Class: Nixenvironment::Xcodebuild
- Inherits:
-
CmdExecutor
- Object
- CmdExecutor
- Nixenvironment::Xcodebuild
- Defined in:
- lib/nixenvironment/xcodebuild.rb
Class Method Summary collapse
-
.build(sdk = nil, config = nil, xcconfig = nil, project = nil, workspace = nil, scheme = nil, env_var_prefix = nil, xc_args = nil) ⇒ Object
other => other args to be passed to xcodebuild.
- .clean_all_targets ⇒ Object
- .config_settings ⇒ Object
- .contains_config?(config) ⇒ Boolean
- .contains_scheme?(scheme) ⇒ Boolean
- .define_workspace_or_project(build_args, workspace = nil, project = nil, scheme = nil, target = nil) ⇒ Object
- .read_config_settings(workspace = nil, project = nil, scheme = nil, sdk = nil, config = nil, xcconfig = nil) ⇒ Object
- .test(sdk = nil, config = nil, workspace = nil, project = nil, scheme = nil, code_coverage_config = nil, timeout = nil, destination = nil) ⇒ Object
Methods inherited from CmdExecutor
execute, last_cmd_exitstatus, last_cmd_success?
Class Method Details
.build(sdk = nil, config = nil, xcconfig = nil, project = nil, workspace = nil, scheme = nil, env_var_prefix = nil, xc_args = nil) ⇒ Object
other => other args to be passed to xcodebuild
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 |
# File 'lib/nixenvironment/xcodebuild.rb', line 29 def self.build(sdk = nil, config = nil, xcconfig = nil, project = nil, workspace = nil, scheme = nil, env_var_prefix = nil, xc_args = nil) build_args = [] build_args << "-sdk '#{sdk}'" if sdk.present? build_args << "-configuration '#{config}'" if config.present? build_args << "-xcconfig '#{xcconfig}'" if xcconfig.present? define_workspace_or_project(build_args, workspace, project, scheme) if env_var_prefix.present? vars_to_define = '' ENV.each do |key, value| if key.start_with?(env_var_prefix) vars_to_define += ' ' + key puts "Environment variable '#{key}' will be defined with value: #{value}" end end build_args << "GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS#{vars_to_define}'" if vars_to_define.present? end build_args << xc_args if xc_args.present? build_args << '| tee xcodebuild.log | xcpretty -c && cat xcodebuild.log && rm xcodebuild.log && exit ${PIPESTATUS[0]}' execute(nil, build_args) end |
.clean_all_targets ⇒ Object
24 25 26 |
# File 'lib/nixenvironment/xcodebuild.rb', line 24 def self.clean_all_targets execute(nil, %w(-alltargets clean)) end |
.config_settings ⇒ Object
179 180 181 |
# File 'lib/nixenvironment/xcodebuild.rb', line 179 def self.config_settings @config_settings end |
.contains_config?(config) ⇒ Boolean
14 15 16 17 |
# File 'lib/nixenvironment/xcodebuild.rb', line 14 def self.contains_config?(config) configurations = @info['Build Configurations'] configurations && configurations.include?(config) end |
.contains_scheme?(scheme) ⇒ Boolean
19 20 21 22 |
# File 'lib/nixenvironment/xcodebuild.rb', line 19 def self.contains_scheme?(scheme) schemes = @info['Schemes'] schemes && schemes.include?(scheme) end |
.define_workspace_or_project(build_args, workspace = nil, project = nil, scheme = nil, target = nil) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/nixenvironment/xcodebuild.rb', line 117 def self.define_workspace_or_project(build_args, workspace = nil, project = nil, scheme = nil, target = nil) if workspace.present? build_args << "-workspace '#{workspace}'" elsif project.present? build_args << "-project '#{project}'" end if scheme.present? build_args << "-scheme '#{scheme}'" end end |
.read_config_settings(workspace = nil, project = nil, scheme = nil, sdk = nil, config = nil, xcconfig = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/nixenvironment/xcodebuild.rb', line 71 def self.read_config_settings(workspace = nil, project = nil, scheme = nil, sdk = nil, config = nil, xcconfig = nil) @config_settings = {} read_info(workspace, project) raise "Scheme #{scheme} doesn't exist!" if scheme.present? && !contains_scheme?(scheme) raise "Configuration #{config} doesn't exist!" if config.present? && !contains_config?(config) raise "Either #{PROJECT_KEY} or #{WORKSPACE_KEY} must be specified!" if project.blank? && workspace.blank? build_args = [] build_args << "-sdk '#{sdk}'" if sdk.present? build_args << "-configuration '#{config}'" if config.present? build_args << "-xcconfig '#{xcconfig}'" if xcconfig.present? define_workspace_or_project(build_args, workspace, project, scheme) build_args << 'clean' build_args << '-showBuildSettings' puts 'Reading config settings ...' puts cmd_output = execute(nil, build_args, true) env_vars_list = cmd_output.split(/\n/).reject(&:empty?) if env_vars_list.present? build_settings_to_strip = Hash[env_vars_list.map { |it| it.split('=', 2) }] build_settings_to_strip.each do |key, value| @config_settings[key.strip] ||= value.strip if key.present? && value.present? end end if workspace.present? @config_settings[WATCHKIT_EXTENSION_PRODUCT_SETTINGS_PATH_KEY] = product_settings_path(workspace, scheme, WATCHKIT_EXTENSION_SUFFIX) @config_settings[WATCHKIT_APP_PRODUCT_SETTINGS_PATH_KEY] = product_settings_path(workspace, scheme, WATCHKIT_APP_SUFFIX) @config_settings[WIDGET_PRODUCT_SETTINGS_PATH_KEY] = product_settings_path(workspace, scheme, WIDGET_SUFFIX) end @config_settings[CONFIGURATION_BUILD_DIR_KEY] = IOS_BUILD_DIRECTORY_NAME @config_settings[BUILT_PRODUCTS_DIR_KEY] = IOS_BUILD_DIRECTORY_NAME @config_settings[DWARF_DSYM_FOLDER_PATH_KEY] = IOS_BUILD_DIRECTORY_NAME plist_path = @config_settings[PRODUCT_SETTINGS_PATH_KEY] info_plist = Plist.from_file(plist_path) @config_settings[RESIGNED_BUNDLE_NAME_KEY] ||= info_plist['CFBundleDisplayName'] end |
.test(sdk = nil, config = nil, workspace = nil, project = nil, scheme = nil, code_coverage_config = nil, timeout = nil, destination = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/nixenvironment/xcodebuild.rb', line 56 def self.test(sdk = nil, config = nil, workspace = nil, project = nil, scheme = nil, code_coverage_config = nil, timeout = nil, destination = nil) build_args = [] build_args << "-sdk '#{sdk}'" if sdk.present? build_args << "-configuration '#{config}'" if config.present? define_workspace_or_project(build_args, workspace, project, scheme) build_args << "-xcconfig '#{code_coverage_config}'" if code_coverage_config.present? build_args << "-destination-timeout '#{timeout}'" if timeout.present? build_args << "-destination '#{destination}'" if destination.present? build_args << "| ocunit2junit" # generates test result xmls execute('test', build_args) end |