lib/motion/project/project.rb in motion-sparkle-sandbox-2.0.0 vs lib/motion/project/project.rb in motion-sparkle-sandbox-2.0.1

- old
+ new

@@ -1,67 +1,57 @@ -module Motion::Project +# frozen_string_literal: true - class Config - variable :sparkle +require 'open3' - def sparkle(&block) - @sparkle ||= Motion::Project::Sparkle.new(self) - if block - @sparkle.instance_eval &block +module Motion + module Project + class Config + variable :sparkle + + def sparkle(&block) + @sparkle ||= Motion::Project::Sparkle.new(self) + @sparkle.instance_eval(&block) if block + @sparkle end - @sparkle end - end - class App - class << self - def build_with_sparkle(platform, opts = {}) - if App.config.sparkle.setup_ok? - App.info "Sparkle", "Setup OK" - else - exit 1 + class App + class << self + def build_with_sparkle(platform, opts = {}) + App.fail 'Sparkle not setup correctly' unless App.config.sparkle.setup_ok? + + App.info 'Sparkle', 'Setup OK' + + build_without_sparkle(platform, opts) end - build_without_sparkle(platform, opts) - end - alias_method "build_without_sparkle", "build" - alias_method "build", "build_with_sparkle" + alias_method 'build_without_sparkle', 'build' + alias_method 'build', 'build_with_sparkle' + end end - end - class Builder - # if we're using the sandboxed version of Sparkle, then we need to copy the - # xpc services to the proper folder and sign them. This has to be done - # before we sign the app itself - #------------------------------------------------------------------------------ - def codesign_with_sparkle(config, platform) - if App.config.embedded_frameworks.any? {|item| item.to_s.include?('Sparkle.framework')} - bundle_path = App.config.app_bundle('MacOSX') + class Builder + # The XPC services are already residing in the Sparkle package. But we need + # to re-sign the entire package to ensure all executables have the hardened + # runtime and correct certificate. + #------------------------------------------------------------------------------ + def codesign_with_sparkle(config, platform) + if App.config.embedded_frameworks.any? { |item| item.to_s.include?('Sparkle.framework') } + bundle_path = App.config.app_bundle('MacOSX') + sparkle_path = File.join(bundle_path, 'Frameworks', 'Sparkle.framework') - if File.directory?(App.config.sparkle.sparkle_xpc_path) - App.info 'Sparkle', 'Removing unnecessary executables...' - sparkle_path = File.join(bundle_path, "Frameworks/Sparkle.framework") - ['Resources/Autoupdate', 'Resources/Updater.app'].each do |item| - bundle = File.join(sparkle_path, item) - FileUtils.rm_r(bundle) if File.exist?(bundle) - end + `/usr/bin/codesign -f -s "#{config.codesign_certificate}" -o runtime "#{sparkle_path}/Versions/B/Autoupdate"` + `/usr/bin/codesign -f -s "#{config.codesign_certificate}" -o runtime "#{sparkle_path}/Versions/B/Updater.app"` + `/usr/bin/codesign -f -s "#{config.codesign_certificate}" -o runtime "#{sparkle_path}/Versions/B/XPCServices/org.sparkle-project.InstallerLauncher.xpc"` + `/usr/bin/codesign -f -s "#{config.codesign_certificate}" -o runtime --entitlements "./vendor/Pods/Sparkle/Entitlements/org.sparkle-project.Downloader.entitlements" "#{sparkle_path}/Versions/B/XPCServices/org.sparkle-project.Downloader.xpc"` # rubocop:disable Layout/LineLength - xpc_path = File.join(bundle_path, "XPCServices") - App.info 'Sparkle', "Copying XPCServices to #{xpc_path}" - - FileUtils.mkdir_p(xpc_path) - `cp -R #{App.config.sparkle.sparkle_xpc_path}/*.xpc "#{xpc_path}"` - - Dir.glob("#{xpc_path}/*.xpc").each do |path| - App.info 'Codesign', path - results = `#{App.config.sparkle.sparkle_vendor_path}/codesign_embedded_executable "#{App.config.codesign_certificate}" "#{File.expand_path(path)}" 2>&1` - end + `/usr/bin/codesign -f -s "#{config.codesign_certificate}" -o runtime "#{sparkle_path}"` end + + codesign_without_sparkle(config, platform) end - codesign_without_sparkle(config, platform) + alias_method 'codesign_without_sparkle', 'codesign' + alias_method 'codesign', 'codesign_with_sparkle' end - - alias_method "codesign_without_sparkle", "codesign" - alias_method "codesign", "codesign_with_sparkle" end end