spec/unit/software_spec.rb in omnibus-5.0.0 vs spec/unit/software_spec.rb in omnibus-5.1.0
- old
+ new
@@ -7,23 +7,36 @@
name 'project'
install_dir '/opt/project'
end
end
+ let(:source) do
+ {
+ url: 'http://example.com/',
+ md5: 'abcd1234'
+ }
+ end
+
+ let(:rel_path) { 'software' }
+
subject do
+ local_source = source
+ local_rel_path = rel_path
+
described_class.new(project).evaluate do
name 'software'
default_version '1.2.3'
- source url: 'http://example.com/',
- md5: 'abcd1234'
+ source local_source
+ relative_path local_rel_path
end
end
it_behaves_like 'a cleanroom getter', :project
it_behaves_like 'a cleanroom setter', :name, %|name 'libxml2'|
it_behaves_like 'a cleanroom setter', :description, %|description 'The XML magician'|
+ it_behaves_like 'a cleanroom setter', :maintainer, %|maintainer 'Captain Jack <sparrow@chef.io>'|
it_behaves_like 'a cleanroom setter', :dependency, %|dependency 'libxslt'|
it_behaves_like 'a cleanroom setter', :source, %|source url: 'https://source.example.com'|
it_behaves_like 'a cleanroom setter', :default_version, %|default_version '1.2.3'|
it_behaves_like 'a cleanroom setter', :version, %|version '1.2.3'|
it_behaves_like 'a cleanroom setter', :whitelist_file, %|whitelist_file '/opt/whatever'|
@@ -48,64 +61,64 @@
before { stub_ohai(platform: 'ubuntu', version: '12.04') }
it "sets the defaults" do
expect(subject.with_standard_compiler_flags).to eq(
'LDFLAGS' => '-Wl,-rpath,/opt/project/embedded/lib -L/opt/project/embedded/lib',
- 'CFLAGS' => '-I/opt/project/embedded/include',
- 'CXXFLAGS' => '-I/opt/project/embedded/include',
- 'CPPFLAGS' => '-I/opt/project/embedded/include',
+ 'CFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CXXFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CPPFLAGS' => '-I/opt/project/embedded/include -O2',
'LD_RUN_PATH' => '/opt/project/embedded/lib',
'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig'
)
end
it 'overrides LDFLAGS' do
expect(subject.with_standard_compiler_flags('LDFLAGS' => 'foo')).to eq(
'LDFLAGS' => '-Wl,-rpath,/opt/project/embedded/lib -L/opt/project/embedded/lib',
- 'CFLAGS' => '-I/opt/project/embedded/include',
- 'CXXFLAGS' => '-I/opt/project/embedded/include',
- 'CPPFLAGS' => '-I/opt/project/embedded/include',
+ 'CFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CXXFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CPPFLAGS' => '-I/opt/project/embedded/include -O2',
'LD_RUN_PATH' => '/opt/project/embedded/lib',
'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig'
)
end
it 'overrides CFLAGS' do
expect(subject.with_standard_compiler_flags('CFLAGS'=>'foo')).to eq(
'LDFLAGS' => '-Wl,-rpath,/opt/project/embedded/lib -L/opt/project/embedded/lib',
- 'CFLAGS' => '-I/opt/project/embedded/include',
- 'CXXFLAGS' => '-I/opt/project/embedded/include',
- 'CPPFLAGS' => '-I/opt/project/embedded/include',
+ 'CFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CXXFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CPPFLAGS' => '-I/opt/project/embedded/include -O2',
'LD_RUN_PATH' => '/opt/project/embedded/lib',
'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig'
)
end
it 'overrides CXXFLAGS' do
expect(subject.with_standard_compiler_flags('CXXFLAGS'=>'foo')).to eq(
'LDFLAGS' => '-Wl,-rpath,/opt/project/embedded/lib -L/opt/project/embedded/lib',
- 'CFLAGS' => '-I/opt/project/embedded/include',
- 'CXXFLAGS' => '-I/opt/project/embedded/include',
- 'CPPFLAGS' => '-I/opt/project/embedded/include',
+ 'CFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CXXFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CPPFLAGS' => '-I/opt/project/embedded/include -O2',
'LD_RUN_PATH' => '/opt/project/embedded/lib',
'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig'
)
end
it 'overrides CPPFLAGS' do
expect(subject.with_standard_compiler_flags('CPPFLAGS'=>'foo')).to eq(
'LDFLAGS' => '-Wl,-rpath,/opt/project/embedded/lib -L/opt/project/embedded/lib',
- 'CFLAGS' => '-I/opt/project/embedded/include',
- 'CXXFLAGS' => '-I/opt/project/embedded/include',
- 'CPPFLAGS' => '-I/opt/project/embedded/include',
+ 'CFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CXXFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CPPFLAGS' => '-I/opt/project/embedded/include -O2',
'LD_RUN_PATH' => '/opt/project/embedded/lib',
'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig'
)
end
it 'preserves anything else' do
expect(subject.with_standard_compiler_flags('numberwang'=>4)).to eq(
'numberwang' => 4,
'LDFLAGS' => '-Wl,-rpath,/opt/project/embedded/lib -L/opt/project/embedded/lib',
- 'CFLAGS' => '-I/opt/project/embedded/include',
- 'CXXFLAGS' => '-I/opt/project/embedded/include',
- 'CPPFLAGS' => '-I/opt/project/embedded/include',
+ 'CFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CXXFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CPPFLAGS' => '-I/opt/project/embedded/include -O2',
'LD_RUN_PATH' => '/opt/project/embedded/lib',
'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig'
)
end
end
@@ -163,13 +176,13 @@
before { stub_ohai(platform: 'mac_os_x', version: '10.9.2') }
it 'sets the defaults' do
expect(subject.with_standard_compiler_flags).to eq(
'LDFLAGS' => '-L/opt/project/embedded/lib',
- 'CFLAGS' => '-I/opt/project/embedded/include',
- "CXXFLAGS" => "-I/opt/project/embedded/include",
- "CPPFLAGS" => "-I/opt/project/embedded/include",
+ 'CFLAGS' => '-I/opt/project/embedded/include -O2',
+ "CXXFLAGS" => "-I/opt/project/embedded/include -O2",
+ "CPPFLAGS" => "-I/opt/project/embedded/include -O2",
'LD_RUN_PATH' => '/opt/project/embedded/lib',
'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig'
)
end
end
@@ -197,43 +210,106 @@
'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig'
)
end
end
- context 'on freebsd' do
+ context 'on freebsd 9' do
before do
stub_ohai(platform: 'freebsd', version: '9.2')
end
it 'sets the defaults' do
expect(subject.with_standard_compiler_flags).to eq(
- 'CFLAGS' => '-I/opt/project/embedded/include',
- 'CXXFLAGS' => '-I/opt/project/embedded/include',
- 'CPPFLAGS' => '-I/opt/project/embedded/include',
+ 'CFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CXXFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CPPFLAGS' => '-I/opt/project/embedded/include -O2',
'LDFLAGS' => '-L/opt/project/embedded/lib',
'LD_RUN_PATH' => '/opt/project/embedded/lib',
'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig',
)
end
+ end
- context 'on freebsd' do
- before do
- stub_ohai(platform: 'freebsd', version: '10.0')
+ context 'on freebsd 10' do
+ before do
+ stub_ohai(platform: 'freebsd', version: '10.0')
+ end
+
+ it 'Clang as the default compiler' do
+ expect(subject.with_standard_compiler_flags).to eq(
+ 'CC' => 'clang',
+ 'CXX' => 'clang++',
+ 'CFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CXXFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'CPPFLAGS' => '-I/opt/project/embedded/include -O2',
+ 'LDFLAGS' => '-L/opt/project/embedded/lib',
+ 'LD_RUN_PATH' => '/opt/project/embedded/lib',
+ 'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig',
+ )
+ end
+ end
+
+ context 'on Windows' do
+ let(:win_arch_i386) { true }
+
+ before do
+ stub_ohai(platform: 'windows', version: '2012')
+ allow(subject).to receive(:windows_arch_i386?).and_return(win_arch_i386)
+ end
+
+ context 'in 32-bit mode' do
+ it 'sets the default' do
+ expect(subject.with_standard_compiler_flags).to eq(
+ 'CFLAGS' => '-I/opt/project/embedded/include -m32 -O3 -mfpmath=sse -msse2 -march=i686',
+ 'CXXFLAGS' => '-I/opt/project/embedded/include -m32 -O3 -mfpmath=sse -msse2 -march=i686',
+ 'CPPFLAGS' => '-I/opt/project/embedded/include -m32 -O3 -mfpmath=sse -msse2 -march=i686',
+ 'LDFLAGS' => '-L/opt/project/embedded/lib -m32',
+ 'LD_RUN_PATH' => '/opt/project/embedded/lib',
+ 'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig'
+ )
end
- it 'Clang as the default compiler' do
+ it 'sets BFD flags if requested' do
+ expect(subject.with_standard_compiler_flags({}, bfd_flags: true)).to eq(
+ 'CFLAGS' => '-I/opt/project/embedded/include -m32 -O3 -mfpmath=sse -msse2 -march=i686',
+ 'CXXFLAGS' => '-I/opt/project/embedded/include -m32 -O3 -mfpmath=sse -msse2 -march=i686',
+ 'CPPFLAGS' => '-I/opt/project/embedded/include -m32 -O3 -mfpmath=sse -msse2 -march=i686',
+ 'LDFLAGS' => '-L/opt/project/embedded/lib -m32',
+ 'RCFLAGS' => '--target=pe-i386',
+ 'ARFLAGS' => '--target=pe-i386',
+ 'LD_RUN_PATH' => '/opt/project/embedded/lib',
+ 'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig'
+ )
+ end
+ end
+
+ context 'in 64-bit mode' do
+ let(:win_arch_i386) { false }
+
+ it 'sets the default' do
expect(subject.with_standard_compiler_flags).to eq(
- 'CC' => 'clang',
- 'CXX' => 'clang++',
- 'CFLAGS' => '-I/opt/project/embedded/include',
- 'CXXFLAGS' => '-I/opt/project/embedded/include',
- 'CPPFLAGS' => '-I/opt/project/embedded/include',
- 'LDFLAGS' => '-L/opt/project/embedded/lib',
+ 'CFLAGS' => '-I/opt/project/embedded/include -m64 -O3 -mfpmath=sse -msse2 -march=x86-64',
+ 'CXXFLAGS' => '-I/opt/project/embedded/include -m64 -O3 -mfpmath=sse -msse2 -march=x86-64',
+ 'CPPFLAGS' => '-I/opt/project/embedded/include -m64 -O3 -mfpmath=sse -msse2 -march=x86-64',
+ 'LDFLAGS' => '-L/opt/project/embedded/lib -m64',
'LD_RUN_PATH' => '/opt/project/embedded/lib',
- 'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig',
+ 'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig'
)
end
+
+ it 'sets BFD flags if requested' do
+ expect(subject.with_standard_compiler_flags({}, bfd_flags: true)).to eq(
+ 'CFLAGS' => '-I/opt/project/embedded/include -m64 -O3 -mfpmath=sse -msse2 -march=x86-64',
+ 'CXXFLAGS' => '-I/opt/project/embedded/include -m64 -O3 -mfpmath=sse -msse2 -march=x86-64',
+ 'CPPFLAGS' => '-I/opt/project/embedded/include -m64 -O3 -mfpmath=sse -msse2 -march=x86-64',
+ 'LDFLAGS' => '-L/opt/project/embedded/lib -m64',
+ 'RCFLAGS' => '--target=pe-x86-64',
+ 'ARFLAGS' => '--target=pe-x86-64',
+ 'LD_RUN_PATH' => '/opt/project/embedded/lib',
+ 'PKG_CONFIG_PATH' => '/opt/project/embedded/lib/pkgconfig'
+ )
+ end
end
end
end
@@ -271,10 +347,16 @@
'numberwang' => 4,
'PATH' => prepended_path
)
end
+ it 'with_embedded_path ignores option to add msys to path' do
+ expect(subject.with_embedded_path({}, msys: true)).to eq(
+ 'PATH' => prepended_path
+ )
+ end
+
it 'prepends multiple paths to PATH' do
expect(subject.prepend_path('/foo/bar', '/foo/baz')).to eq(
['/foo/bar', separator, '/foo/baz', separator, path].join
)
end
@@ -286,10 +368,14 @@
end
let(:separator) { ';' }
let(:path) { 'c:/Ruby193/bin;c:/Windows/system32;c:/Windows;c:/Windows/System32/Wbem' }
let(:install_dir) { 'c:/opt/project' }
+ let(:prepended_path_msys) do
+ [ "#{install_dir}/bin", separator, "#{install_dir}/embedded/bin", separator,
+ "#{install_dir}/embedded/msys/1.0/bin", separator, path].join
+ end
context '`Path` exists in the environment' do
before do
stub_env('Path', path)
allow(ENV).to receive(:keys).and_return(%w( Path PATH ))
@@ -304,15 +390,23 @@
context '`Path` does not exist in the environment' do
before do
allow(ENV).to receive(:keys).and_return(['PATH'])
end
+
it 'returns a path key of `PATH`' do
expect(subject.with_embedded_path).to eq(
'PATH' => prepended_path
)
end
+
+ it 'with_embedded_path accepts option to add msys to path' do
+ expect(subject.with_embedded_path({}, msys: true)).to eq(
+ 'PATH' => prepended_path_msys
+ )
+ end
+
end
end
end
describe '#ohai' do
@@ -440,9 +534,119 @@
let(:source) { { url: 'http://new.example.com', md5: 'defg5678' } }
before { project.override(:software, source: source) }
it 'returns the correct source' do
expect(subject.source).to eq(source)
+ end
+ end
+ end
+ end
+
+ describe '#fetcher' do
+ before do
+ expect(Omnibus::Fetcher).to receive(:resolve_version).with("1.2.3", source).and_return("1.2.8")
+ end
+
+ context 'when given a source url to an archive' do
+ let(:source) do
+ {
+ url: 'http://example.com/foo.tar.gz',
+ md5: 'abcd1234'
+ }
+ end
+
+ context 'when relative_path is the same as name' do
+ let(:rel_path) { 'software' }
+
+ it 'ignores back-compat and leaves fetch_dir alone' do
+ subject.send(:fetcher)
+ expect(subject.project_dir).to eq(File.expand_path("#{Config.source_dir}/software/software"))
+ end
+
+ it 'sets the fetcher project_dir to fetch_dir' do
+ expect(subject.send(:fetcher).project_dir).to eq(File.expand_path("#{Config.source_dir}/software"))
+ end
+ end
+
+ context 'when relative_path is different from name' do
+ let(:rel_path) { 'foo' }
+
+ it 'ignores back-compat and leaves fetch_dir alone' do
+ subject.send(:fetcher)
+ expect(subject.project_dir).to eq(File.expand_path("#{Config.source_dir}/software/foo"))
+ end
+
+ it 'sets the fetcher project_dir to fetch_dir' do
+ expect(subject.send(:fetcher).project_dir).to eq(File.expand_path("#{Config.source_dir}/software"))
+ end
+ end
+ end
+
+ context 'when given source url is not an archive' do
+ let(:source) do
+ {
+ url: 'http://example.com/foo.txt',
+ md5: 'abcd1234'
+ }
+ end
+
+ context 'when relative_path is the same as name' do
+ let(:rel_path) { 'software' }
+
+ it 'for back-compat, changes fetch_dir' do
+ subject.send(:fetcher)
+ expect(subject.project_dir).to eq(File.expand_path("#{Config.source_dir}/software/software"))
+ end
+
+ it 'sets the fetcher project_dir to project_dir' do
+ expect(subject.send(:fetcher).project_dir).to eq(File.expand_path("#{Config.source_dir}/software/software"))
+ end
+ end
+
+ context 'when relative_path is different from name' do
+ let(:rel_path) { 'foo' }
+
+ it 'ignores back-compat and leaves fetch_dir alone' do
+ subject.send(:fetcher)
+ expect(subject.project_dir).to eq(File.expand_path("#{Config.source_dir}/software/foo"))
+ end
+
+ it 'sets the fetcher project_dir to project_dir' do
+ expect(subject.send(:fetcher).project_dir).to eq(File.expand_path("#{Config.source_dir}/software/foo"))
+ end
+ end
+ end
+
+ context 'when given source is a git repo' do
+ let(:source) do
+ {
+ git: 'http://example.com/my/git/repo',
+ }
+ end
+
+ context 'when relative_path is the same as name' do
+ let(:rel_path) { 'software' }
+
+ it 'for back-compat, changes fetch_dir' do
+ subject.send(:fetcher)
+ expect(subject.project_dir).to eq(File.expand_path("#{Config.source_dir}/software/software"))
+ end
+
+ it 'sets the fetcher project_dir to project_dir' do
+ expect(subject.send(:fetcher).project_dir).to eq(File.expand_path("#{Config.source_dir}/software/software"))
+ end
+ end
+
+ context 'when relative_path is different from name' do
+ let(:rel_path) { 'foo' }
+
+ it 'ignores back-compat and leaves fetch_dir alone' do
+ subject.send(:fetcher)
+ expect(subject.project_dir).to eq(File.expand_path("#{Config.source_dir}/software/foo"))
+ end
+
+ it 'sets the fetcher project_dir to project_dir' do
+ expect(subject.send(:fetcher).project_dir).to eq(File.expand_path("#{Config.source_dir}/software/foo"))
end
end
end
end