Class: Vanagon::Platform::OSX
- Inherits:
-
Vanagon::Platform
- Object
- Vanagon::Platform
- Vanagon::Platform::OSX
- Defined in:
- lib/vanagon/platform/osx.rb
Constant Summary
Constants inherited from Vanagon::Platform
Instance Attribute Summary
Attributes inherited from Vanagon::Platform
#abs_resource_name, #architecture, #aws_ami, #aws_instance_type, #aws_key, #aws_key_name, #aws_region, #aws_shutdown_behavior, #aws_subnet_id, #aws_user_data, #aws_vpc_id, #build_dependencies, #build_hosts, #cflags, #codename, #copy, #cross_compiled, #defaultdir, #dist, #docker_image, #docker_run_args, #environment, #find, #install, #ldflags, #make, #mktemp, #name, #num_cores, #os_name, #os_version, #output_dir, #package_type, #patch, #platform_triple, #provisioning, #rpmbuild, #sed, #servicedir, #servicetype, #settings, #shasum, #shell, #sort, #source_output_dir, #ssh_port, #tar, #target_user, #valid_operators, #vmpooler_template
Instance Method Summary collapse
-
#generate_package(project) ⇒ Array
The specific bits used to generate a osx package for a given project.
-
#generate_packaging_artifacts(workdir, name, binding, project) ⇒ Object
Method to generate the files required to build a osx package for the project.
-
#initialize(name) ⇒ Vanagon::Platform::OSX
constructor
Constructor.
-
#install_build_dependencies(list_build_dependencies) ⇒ String
Because homebrew does not support being run by root we need to have this method to run it in the context of another user.
-
#package_name(project) ⇒ String
Method to derive the package name for the project.
Methods inherited from Vanagon::Platform
#[], #add_build_repository, #add_group, #add_user, #generate_compiled_archive, #is_aix?, #is_cisco_wrlinux?, #is_cross_compiled?, #is_cross_compiled_linux?, #is_deb?, #is_el?, #is_eos?, #is_fedora?, #is_huaweios?, #is_linux?, #is_macos?, #is_osx?, #is_rpm?, #is_sles?, #is_solaris?, #is_unix?, #is_windows?, load_platform, #package_override, #provision_with, #validate_operator, #version_munger
Methods included from HashableAttributes
Methods included from Utilities
#erb_file, #erb_string, #ex, #find_program_on_path, #get_md5sum, #get_sum, #http_request, #local_command, #remote_ssh_command, #retry_with_timeout, #rsync_from, #rsync_to, #ssh_command
Constructor Details
#initialize(name) ⇒ Vanagon::Platform::OSX
Constructor. Sets up some defaults for the osx platform and calls the parent constructor
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/vanagon/platform/osx.rb', line 118 def initialize(name) @name = name @make = "/usr/bin/make" @tar = "tar" @shasum = "/usr/bin/shasum" @pkgbuild = "/usr/bin/pkgbuild" @productbuild = "/usr/bin/productbuild" @hdiutil = "/usr/bin/hdiutil" @patch = "/usr/bin/patch" @num_cores = "/usr/sbin/sysctl -n hw.physicalcpu" @mktemp = "mktemp -d -t 'tmp'" super(name) end |
Instance Method Details
#generate_package(project) ⇒ Array
The specific bits used to generate a osx package for a given project
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vanagon/platform/osx.rb', line 21 def generate_package(project) # rubocop:disable Metrics/AbcSize target_dir = project.repo ? output_dir(project.repo) : output_dir # Here we maintain backward compatibility with older vanagon versions # that did this by default. This shim should get removed at some point # in favor of just letting the makefile deliver the bill-of-materials # to the correct directory. This shouldn't be required at all then. if project.bill_of_materials.nil? bom_install = [ # Move bill-of-materials into a docdir "mkdir -p $(tempdir)/osx/build/root/#{project.name}-#{project.version}/usr/local/share/doc/#{project.name}", "mv $(tempdir)/osx/build/root/#{project.name}-#{project.version}/bill-of-materials $(tempdir)/osx/build/root/#{project.name}-#{project.version}/usr/local/share/doc/#{project.name}/bill-of-materials", ] else bom_install = [] end # Setup build directories ["bash -c 'mkdir -p $(tempdir)/osx/build/{dmg,pkg,scripts,resources,root,payload,plugins}'", "mkdir -p $(tempdir)/osx/build/root/#{project.name}-#{project.version}", "mkdir -p $(tempdir)/osx/build/pkg", # Grab distribution xml, scripts and other external resources "cp #{project.name}-installer.xml $(tempdir)/osx/build/", #copy the uninstaller to the pkg dir, where eventually the installer will go too "cp #{project.name}-uninstaller.tool $(tempdir)/osx/build/pkg/", "cp scripts/* $(tempdir)/osx/build/scripts/", "if [ -d resources/osx/productbuild ] ; then cp -r resources/osx/productbuild/* $(tempdir)/osx/build/; fi", # Unpack the project "gunzip -c #{project.name}-#{project.version}.tar.gz | '#{@tar}' -C '$(tempdir)/osx/build/root/#{project.name}-#{project.version}' --strip-components 1 -xf -", bom_install, # Package the project "(cd $(tempdir)/osx/build/; #{@pkgbuild} --root root/#{project.name}-#{project.version} \ --scripts $(tempdir)/osx/build/scripts \ --identifier #{project.identifier}.#{project.name} \ --version #{project.version} \ --install-location / \ payload/#{project.name}-#{project.version}-#{project.release}.pkg)", # Create a custom installer using the pkg above "(cd $(tempdir)/osx/build/; #{@productbuild} --distribution #{project.name}-installer.xml \ --identifier #{project.identifier}.#{project.name}-installer \ --package-path payload/ \ --resources $(tempdir)/osx/build/resources \ --plugins $(tempdir)/osx/build/plugins \ pkg/#{project.name}-#{project.version}-#{project.release}-installer.pkg)", # Create a dmg and ship it to the output directory "(cd $(tempdir)/osx/build; \ #{@hdiutil} create \ -volname #{project.name}-#{project.version} \ -fs JHFS+ \ -format UDBZ \ -srcfolder pkg \ dmg/#{project.package_name})", "mkdir -p output/#{target_dir}", "cp $(tempdir)/osx/build/dmg/#{project.package_name} ./output/#{target_dir}"].flatten.compact end |
#generate_packaging_artifacts(workdir, name, binding, project) ⇒ Object
Method to generate the files required to build a osx package for the project
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/vanagon/platform/osx.rb', line 86 def generate_packaging_artifacts(workdir, name, binding, project) # rubocop:disable Metrics/AbcSize resources_dir = File.join(workdir, "resources", "osx") FileUtils.mkdir_p(resources_dir) script_dir = File.join(workdir, "scripts") FileUtils.mkdir_p(script_dir) erb_file(File.join(VANAGON_ROOT, "resources/osx/project-installer.xml.erb"), File.join(workdir, "#{name}-installer.xml"), false, { :binding => binding }) ["postinstall", "preinstall"].each do |script_file| erb_file(File.join(VANAGON_ROOT, "resources/osx/#{script_file}.erb"), File.join(script_dir, script_file), false, { :binding => binding }) FileUtils.chmod 0755, File.join(script_dir, script_file) end erb_file(File.join(VANAGON_ROOT, 'resources', 'osx', 'uninstaller.tool.erb'), File.join(workdir, "#{name}-uninstaller.tool"), false, { :binding => binding }) FileUtils.chmod 0755, File.join(workdir, "#{name}-uninstaller.tool") # Probably a better way to do this, but OSX tends to need some extra stuff FileUtils.cp_r("resources/osx/.", resources_dir) if File.exist?("resources/osx/") end |
#install_build_dependencies(list_build_dependencies) ⇒ String
Because homebrew does not support being run by root we need to have this method to run it in the context of another user
9 10 11 12 13 14 15 |
# File 'lib/vanagon/platform/osx.rb', line 9 def install_build_dependencies(list_build_dependencies) <<-HERE.undent mkdir -p /etc/homebrew cd /etc/homebrew su test -c '/usr/local/bin/brew install #{list_build_dependencies.join(' ')}' HERE end |
#package_name(project) ⇒ String
Method to derive the package name for the project
110 111 112 |
# File 'lib/vanagon/platform/osx.rb', line 110 def package_name(project) "#{project.name}-#{project.version}-#{project.release}.#{@os_name}#{@os_version}.dmg" end |