diff --git a/lib/omnibus/packagers/ips.rb b/lib/omnibus/packagers/ips.rb index e8358d85c..6427140ba 100644 --- a/lib/omnibus/packagers/ips.rb +++ b/lib/omnibus/packagers/ips.rb @@ -104,6 +104,15 @@ def transform_file @transform_file ||= File.join(staging_dir, "doc-transform") end + # + # The full path to the symlinks file on disk. + # + # @return [String] + # + def symlinks_file + @symlinks_file ||= File.join(staging_dir, "symlinks_file") + end + # # The full path to the pkg metadata file on disk. # @@ -192,6 +201,25 @@ def write_transform_file ) end + # + # A set of symbolic links to installed commands that + #`pkgmogrify' will apply to the package manifest. Is called only when + # symlinks.erb template exists + # The resource exists locally. For example for project omnibus-toolchain + # resource_path("symlinks.erb") #=> + # {"/path/to/omnibus-toolchain/resources/omnibus-toolchain/ips/symlinks.erb"} + # + # @return [void] + # + def write_symlinks_file + render_template(resource_path("symlinks.erb"), + destination: symlinks_file, + variables: { + projectdir: project.install_dir, + } + ) + end + # # Generate package metadata # @@ -211,6 +239,15 @@ def write_pkg_metadata } ) + # Append the contents of symlinks.erb if it exists + if File.exists?(resource_path("symlinks.erb")) + write_symlinks_file + add_symlinks = File.read(symlinks_file) + File.open(pkg_metadata_file, "a") do |symlink| + symlink.puts add_symlinks + end + end + # Print the full contents of the rendered template file to generate package contents log.debug(log_key) { "Rendered Template:\n" + File.read(pkg_metadata_file) } end diff --git a/spec/unit/packagers/ips_spec.rb b/spec/unit/packagers/ips_spec.rb index 0dd9ab5b9..9cb7775b4 100644 --- a/spec/unit/packagers/ips_spec.rb +++ b/spec/unit/packagers/ips_spec.rb @@ -39,7 +39,7 @@ module Omnibus end end - describe '#publisher_prefix' do + describe "#publisher_prefix" do it "is a DSL method" do expect(subject).to have_exposed_method(:publisher_prefix) end @@ -49,47 +49,47 @@ module Omnibus end end - it '#id is :IPS' do + it "#id is :IPS" do expect(subject.id).to eq(:ips) end - describe '#package_name' do + describe "#package_name" do it "should create correct package name" do expect(subject.package_name).to eq("project-1.2.3+20161003185500.git.37.089ab3f-2.i386.p5p") end end - describe '#fmri_package_name' do + describe "#fmri_package_name" do it "should create correct fmri package name" do expect(subject.fmri_package_name).to eq ("project@1.2.3,5.11-2") end end - describe '#pkg_metadata_file' do + describe "#pkg_metadata_file" do it "is created inside the staging_dir" do expect(subject.pkg_metadata_file).to eq("#{subject.staging_dir}/gen.manifestfile") end end - describe '#pkg_manifest_file' do + describe "#pkg_manifest_file" do it "is created inside the staging_dir" do expect(subject.pkg_manifest_file).to eq("#{subject.staging_dir}/#{subject.safe_base_package_name}.p5m") end end - describe '#repo_dir' do + describe "#repo_dir" do it "is created inside the staging_dir" do expect(subject.repo_dir).to eq("#{subject.staging_dir}/publish/repo") end end - describe '#source_dir' do + describe "#source_dir" do it "is created inside the staging_dir" do expect(subject.source_dir).to eq("#{subject.staging_dir}/proto_install") end end - describe '#safe_base_package_name' do + describe "#safe_base_package_name" do context 'when the project name is "safe"' do it "returns the value without logging a message" do expect(subject.safe_base_package_name).to eq("project") @@ -110,7 +110,7 @@ module Omnibus end end - describe '#safe_architecture' do + describe "#safe_architecture" do context "the architecture is Intel-based" do let(:architecture) { "i86pc" } @@ -144,20 +144,72 @@ module Omnibus transform_file_contents = File.read(transform_file) expect(transform_file_contents).to include(" edit group bin sys>") expect(transform_file_contents).to include(" edit pkg.debug.depend.file ruby env>") - expect(transform_file_contents).to include(" edit pkg.debug.depend.file make env>") - expect(transform_file_contents).to include(" edit pkg.debug.depend.file perl env>") + end + end + + describe "#write_symlinks_file" do + let(:resources_path) { File.join(tmp_path, "resources/path") } + let(:symlinks_file) { File.join(staging_dir, "symlinks_file") } + + before do + FileUtils.mkdir_p(resources_path) + allow(subject).to receive(:resources_path).and_return(resources_path) + File.open(File.join(resources_path, "symlinks.erb"), "w+") do |f| + f.puts("link path=usr/bin/ohai target=<%= projectdir %>/bin/ohai") + f.puts("link path=<%= projectdir %>/bin/gmake target=<%= projectdir %>/embedded/bin/make") + end + end + + it "creates the symlinks file" do + subject.write_symlinks_file + symlinks_file_contents = File.read(symlinks_file) + expect(symlinks_file_contents).to include("link path=usr/bin/ohai target=/opt/project/bin/ohai") + expect(symlinks_file_contents).to include("link path=/opt/project/bin/gmake target=/opt/project/embedded/bin/make") end end describe "#write_pkg_metadata" do + let(:resources_path) { File.join(tmp_path, "resources/path") } + let(:symlinks_file) { File.join(staging_dir, "symlinks_file") } + let(:manifest_file) { File.join(staging_dir, "gen.manifestfile") } + it "should create metadata correctly" do subject.write_pkg_metadata - manifest_file = File.join(staging_dir, "gen.manifestfile") - manifest_file_contents = File.read(manifest_file) expect(File.exist?(manifest_file)).to be(true) + manifest_file_contents = File.read(manifest_file) expect(manifest_file_contents).to include("set name=pkg.fmri value=developer/versioning/project@1.2.3,5.11-2") expect(manifest_file_contents).to include("set name=variant.arch value=i386") end + + context "when symlinks_file exists" do + before do + FileUtils.mkdir_p(resources_path) + allow(subject).to receive(:resources_path).and_return(resources_path) + File.open(File.join(resources_path, "symlinks.erb"), "w+") do |f| + f.puts("link path=usr/bin/ohai target=<%= projectdir %>/bin/ohai") + f.puts("link path=<%= projectdir %>/bin/gmake target=<%= projectdir %>/embedded/bin/make") + end + end + + it "should append symlinks_file to metadata contents" do + subject.write_pkg_metadata + expect(File.exist?(symlinks_file)).to be(true) + expect(File.exist?(manifest_file)).to be(true) + manifest_file_contents = File.read(manifest_file) + expect(manifest_file_contents).to include("link path=usr/bin/ohai target=/opt/project/bin/ohai") + expect(manifest_file_contents).to include("link path=/opt/project/bin/gmake target=/opt/project/embedded/bin/make") + end + end + + context "when symlinks.erb does not exist" do + it "#write_pkg_metadata does not include symlinks" do + subject.write_pkg_metadata + expect(File.exist?(symlinks_file)).to be(false) + manifest_file = File.join(staging_dir, "gen.manifestfile") + manifest_file_contents = File.read(manifest_file) + expect(manifest_file_contents).not_to include("link path=usr/bin/ohai target=/opt/project/bin/ohai") + end + end end describe "#generate_pkg_contents" do