bin/nixenvironment in nixenvironment-0.0.58 vs bin/nixenvironment in nixenvironment-0.0.59

- old
+ new

@@ -4,14 +4,15 @@ require 'nixenvironment' require 'commander/import' require 'yaml' require 'fileutils' require 'shellwords' +require 'tmpdir' +require 'active_support/core_ext/object/blank' include Nixenvironment -# :name is optional, otherwise uses the basename of this executable program :name, 'nixenvironment' program :version, VERSION program :description, 'NIX projects build and deploy utility' global_option ('--project_to_build VALUE') { |value| $project_to_build = value } @@ -648,10 +649,64 @@ unless build_success restore_info_plist abort('Build error!') end + if @config_settings['SDK'].include?('macos') + build_env_vars = load_build_env_vars + built_products_dir = build_env_vars['BUILT_PRODUCTS_DIR'] + executable_name = build_env_vars['EXECUTABLE_NAME'] + target_name = build_env_vars['TARGET_NAME'] + configuration = build_env_vars['CONFIGURATION'] + app_product = build_env_vars['APP_PRODUCT'] + + new_ipa_name = "#{executable_name}-#{target_name}-#{configuration}" + new_ipa_path = "#{built_products_dir}/#{new_ipa_name}.zip" + p("IPA_PRODUCT = #{new_ipa_path}") + + root_working_dir = Dir.pwd + tmp_dir = Dir.mktmpdir + + begin + dest_app_dir = File.join(tmp_dir, new_ipa_name) + dest_app_product = File.join(dest_app_dir, File.basename(app_product)) + + p("--> Create '#{dest_app_dir}' ...") + Dir.mkdir(dest_app_dir) + + p("--> Copy '#{app_product}' into '#{dest_app_product}' ...") + FileUtils.cp_r(app_product, dest_app_product) + + if Dir.exist?(new_ipa_path) + p("--> Remove old '#{new_ipa_path}' ...") + FileUtils.rm_rf(new_ipa_path) + end + + p("--> Zip '#{tmp_dir}' into '#{new_ipa_path}' ...") + Dir.chdir(tmp_dir) + + zip_success = system("/usr/bin/zip --symlinks --verbose --recurse-paths \"#{new_ipa_path}\" .") + raise unless zip_success + rescue + abort('Make zip failed!') + ensure + Dir.chdir(root_working_dir) + FileUtils.remove_entry(tmp_dir) + end + + system(" + IPA_BUNDLE_ID=\"`/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' \"#{app_product}/Contents/Info.plist\"`\" + + echo \"\n +IPA_PRODUCT=#{new_ipa_path.shellescape} +IPA_BUNDLE_ID=\"${IPA_BUNDLE_ID}\" +NAME_FOR_DEPLOYMENT=\"#{configuration}\" + \" >> _last_build_vars.sh") + + return + end + if config == 'Release' p('IconTagger: configuration is Release. Skipping ...') else case icon_tagger when 'full' @@ -768,10 +823,32 @@ --plist=\"#{plist_path}\"\ --sourceIconsPath=\"#{icons_dir}\"\ --destinationIconsPath=#{app_product}") end +def load_build_env_vars + load_build_env_vars = File.join(BUILD_SCRIPTS_PATH, 'LoadBuildEnvVars.sh') + cmd_output = %x[ source \"#{load_build_env_vars}\" ].strip! + build_env_vars = {} + + vars_list = cmd_output.split(/\n/).reject(&:empty?) + if vars_list and vars_list.length > 0 + vars_to_strip = Hash[vars_list.map { |it| it.split('=', 2) }] + vars_to_strip.each do |key, value| + if key and value + stripped_key = key.strip + stripped_value = value.strip + + p("#{stripped_key} : #{stripped_value}") + build_env_vars[stripped_key] = stripped_value + end + end + end + + build_env_vars +end + def backup_info_plist p('Backuping Info.plist ...') @info_plist_backup_name = @unescaped_product_settings_path + '.backup' FileUtils.cp(@unescaped_product_settings_path, @info_plist_backup_name) @@ -901,22 +978,57 @@ p('Widget Info.plist was restored.') end end def deploy(deliver_deploy) - deploy = File.join(BUILD_SCRIPTS_PATH, 'DeployIPA.sh') + deploy_host = @config_settings['DEPLOY_HOST'].blank? ? ENV['DEPLOY_HOST'] : @config_settings['DEPLOY_HOST'] + deploy_username = @config_settings['DEPLOY_USERNAME'].blank? ? ENV['DEPLOY_USERNAME'] : @config_settings['DEPLOY_USERNAME'] + deploy_password = @config_settings['DEPLOY_PASSWORD'].blank? ? ENV['DEPLOY_PASSWORD'] : @config_settings['DEPLOY_PASSWORD'] + deploy_itunesconnect_username = @config_settings['DEPLOY_ITUNESCONNECT_USERNAME'].blank? ? ENV['DEPLOY_ITUNESCONNECT_USERNAME'] : @config_settings['DEPLOY_ITUNESCONNECT_USERNAME'] - deploy_host = @config_settings['DEPLOY_HOST'].nil? || @config_settings['DEPLOY_HOST'].empty? ? ENV['DEPLOY_HOST'] : @config_settings['DEPLOY_HOST'] - deploy_path = @config_settings['DEPLOY_PATH'].nil? || @config_settings['DEPLOY_PATH'].empty? ? ENV['DEPLOY_PATH'] : @config_settings['DEPLOY_PATH'] - deploy_username = @config_settings['DEPLOY_USERNAME'].nil? || @config_settings['DEPLOY_USERNAME'].empty? ? ENV['DEPLOY_USERNAME'] : @config_settings['DEPLOY_USERNAME'] - deploy_password = @config_settings['DEPLOY_PASSWORD'].nil? || @config_settings['DEPLOY_PASSWORD'].empty? ? ENV['DEPLOY_PASSWORD'] : @config_settings['DEPLOY_PASSWORD'] - deploy_itunesconnect_username = @config_settings['DEPLOY_ITUNESCONNECT_USERNAME'].nil? || @config_settings['DEPLOY_ITUNESCONNECT_USERNAME'].empty? ? ENV['DEPLOY_ITUNESCONNECT_USERNAME'] : @config_settings['DEPLOY_ITUNESCONNECT_USERNAME'] - deploy_itunesconnect_username ||= 'unknown' deliver_deploy = deliver_deploy ? 1 : 0 - deploy_success = system("#{deploy} #{deploy_host} #{deploy_path} #{deploy_username} #{deploy_password} #{deploy_itunesconnect_username} #{deliver_deploy}") + deploy_success = false + + sdk_name = %x[ source _last_build_vars.sh && echo ${SDK_NAME} ].strip! + + if sdk_name.include?('macos') + build_env_vars = load_build_env_vars + ipa_bundle_id = build_env_vars['IPA_BUNDLE_ID'] + current_app_version = build_env_vars['CURRENT_APP_VERSION'] + current_build_version = build_env_vars['CURRENT_BUILD_VERSION'] + name_for_deployment = build_env_vars['NAME_FOR_DEPLOYMENT'] + executable_name = build_env_vars['EXECUTABLE_NAME'] + ipa_product = build_env_vars['IPA_PRODUCT'] + app_dsym = build_env_vars['APP_DSYM'] + built_products_dir = build_env_vars['BUILT_PRODUCTS_DIR'] + + local_path_to_app = File.join(Dir.tmpdir, ipa_bundle_id) + local_path_to_build = File.join(local_path_to_app, "v.#{current_app_version}_#{current_build_version}") + FileUtils.rm_rf(local_path_to_build) # cleanup in case of previous releases + FileUtils.mkdir_p(local_path_to_build) + + configuration_full_path = File.join(local_path_to_build, name_for_deployment) + FileUtils.mkdir(configuration_full_path) + FileUtils.cp(ipa_product, File.join(configuration_full_path, "#{executable_name}.zip")) + + if File.exist?(app_dsym) + Dir.chdir(built_products_dir) + destination = File.join(configuration_full_path, "#{executable_name}.app.dSYM.zip") + system("zip -r \"#{destination}\" \"#{executable_name}.app.dSYM\"") + end + + deploy_path = @config_settings['DEPLOY_PATH'].blank? ? 'Projects/macOSProjects' : @config_settings['DEPLOY_PATH'] + deploy = File.join(BUILD_SCRIPTS_PATH, 'Deploy.sh') + deploy_success = system("#{deploy} #{deploy_host} #{deploy_path} #{deploy_username} #{deploy_password} #{local_path_to_app}") + else + deploy_path = @config_settings['DEPLOY_PATH'].blank? ? ENV['DEPLOY_PATH'] : @config_settings['DEPLOY_PATH'] + deploy = File.join(BUILD_SCRIPTS_PATH, 'DeployIPA.sh') + deploy_success = system("#{deploy} #{deploy_host} #{deploy_path} #{deploy_username} #{deploy_password} #{deploy_itunesconnect_username} #{deliver_deploy}") + end + abort('Deploy error!') unless deploy_success end def unity_deploy(unity_platform) root_working_dir = nil @@ -1009,6 +1121,6 @@ def clean_working_copy(all) clean_all = all ? 'all' : nil clean_working_copy = File.join(BUILD_SCRIPTS_PATH, 'CleanWorkingCopy.sh') clean_success = system("#{clean_working_copy} #{clean_all}") abort('Clean working copy error!') unless clean_success -end +end \ No newline at end of file