branch_io_cli 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96b0f856a2de3dbd4c63841fd112a8477cdb4694eee1201fd862ee653304160b
4
- data.tar.gz: abb2546fdb310dea4075e5bc018885974a6e4fd97236c3bc2870a90b61aeab91
3
+ metadata.gz: dd6157b41fc586526be77da254770b5d85163ec3288927bc61c0c57a56c33bc8
4
+ data.tar.gz: 79f2102c3254a3eabd933d9cd5b36a9504a86ec1a348fed55c02fbbbf1463dfe
5
5
  SHA512:
6
- metadata.gz: 9b1a6513a50d3dc45ac060759de51964d51dd51752517b6d7ccb8d77e00922c580cdb76c3384a489766ee57ce59642ee722354f4d298bdee4292f0e04ec8c42b
7
- data.tar.gz: fdd5c4d1d8c5c08ce0b2601ed4b413644b5ad7097a32628276733d06fed649de5e6ab8baa95fb236430b5112bb4acd17328b80d480ba4cd4db9f3cd8086357e8
6
+ metadata.gz: d5b48cdb7b011c4a21a54f80455f0f6780d857d21592d368429079d32921b638b347e38e5eb7bc91eabacae731b033acffb6cc527652789c1dfd6025506ffab5
7
+ data.tar.gz: a7014ab71338528a7c40f11636ea9c31db09fca6a29ae8f3d8235427cd88512d660d5b30c2d2aa7a920ce6f59a03315bf6d87ae93aebd4b4e2335029560e29a1
data/README.md CHANGED
@@ -229,10 +229,10 @@ report with additional diagnostic information suitable for opening a support tic
229
229
  |--xcodeproj MyProject.xcodeproj|Path to an Xcode project|
230
230
  |--target MyAppTarget|Name of a target to modify in the Xcode project|
231
231
  |--scheme MyAppScheme|Name of a scheme to build|
232
- |--configuration Debug/Release/CustomConfig|Name of a build configuration (default: Release)|
232
+ |--configuration Debug/Release/CustomConfig|Name of a build configuration (default: Scheme-dependent)|
233
233
  |--sdk iphonesimulator|Name of an SDK to use with xcodebuild (default: iphonesimulator)|
234
234
  |--[no-]clean|Clean before building (default: yes)|
235
- |--[no-]header-only|Show a diagnostic header and exit without cleaning or building (default: no)|
235
+ |-H, --[no-]header-only|Show a diagnostic header and exit without cleaning or building (default: no)|
236
236
  |--[no-]pod-repo-update|Update the local podspec repo before installing (default: yes)|
237
237
  |--podfile /path/to/Podfile|Path to the Podfile for the project|
238
238
  |--cartfile /path/to/Cartfile|Path to the Cartfile for the project|
@@ -18,7 +18,7 @@ _branch_io_complete()
18
18
 
19
19
  validate_opts="$global_opts -D --domains --xcodeproj --target"
20
20
 
21
- report_opts="$global_opts --xcodeproj --workspace --header-only --no-clean --scheme --target --configuration --sdk --out"
21
+ report_opts="$global_opts --xcodeproj --workspace -H --header-only --no-clean --scheme --target --configuration --sdk --out"
22
22
  report_opts="$report_opts --podfile --cartfile --no-pod-repo-update"
23
23
 
24
24
  if [[ ${cur} == -* ]] ; then
@@ -162,12 +162,12 @@ EOF
162
162
  c.option "--workspace MyProject.xcworkspace", String, "Path to an Xcode workspace"
163
163
  c.option "--scheme MyProjectScheme", String, "A scheme from the project or workspace to build"
164
164
  c.option "--target MyProjectTarget", String, "A target to build"
165
- c.option "--configuration Debug|Release|CustomConfigName", String, "The build configuration to use (default: Release)"
165
+ c.option "--configuration Debug|Release|CustomConfigName", String, "The build configuration to use (default: Scheme-dependent)"
166
166
  c.option "--sdk iphonesimulator", String, "Passed as -sdk to xcodebuild (default: iphonesimulator)"
167
167
  c.option "--podfile /path/to/Podfile", String, "Path to the Podfile for the project"
168
168
  c.option "--cartfile /path/to/Cartfile", String, "Path to the Cartfile for the project"
169
169
  c.option "--[no-]clean", "Clean before attempting to build (default: yes)"
170
- c.option "--[no-]header-only", "Write a report header to standard output and exit"
170
+ c.option "-H", "--[no-]header-only", "Write a report header to standard output and exit"
171
171
  c.option "--[no-]pod-repo-update", "Update the local podspec repo before installing (default: yes)"
172
172
  c.option "--out ./report.txt", String, "Report output path (default: ./report.txt)"
173
173
 
@@ -175,7 +175,6 @@ EOF
175
175
  options.default(
176
176
  clean: true,
177
177
  header_only: false,
178
- configuration: "Release",
179
178
  sdk: "iphonesimulator",
180
179
  out: "./report.txt",
181
180
  pod_repo_update: true
@@ -1,6 +1,8 @@
1
1
  require "cocoapods-core"
2
2
  require "branch_io_cli/helper/methods"
3
+ require "open3"
3
4
  require "plist"
5
+ require "xcodeproj"
4
6
 
5
7
  module BranchIOCLI
6
8
  module Command
@@ -13,6 +15,10 @@ module BranchIOCLI
13
15
  def run!
14
16
  say "\n"
15
17
 
18
+ unless load_settings_from_xcode
19
+ say "Failed to load settings from Xcode. Some information may be missing.\n"
20
+ end
21
+
16
22
  if config.header_only
17
23
  say report_header
18
24
  exit 0
@@ -61,15 +67,18 @@ EOF
61
67
  end
62
68
 
63
69
  base_cmd = base_xcodebuild_cmd
64
- # Add -scheme option for the rest of the commands if using a workspace
65
- base_cmd = "#{base_cmd} -scheme #{config.scheme}" if config.workspace_path
66
-
67
- # xcodebuild -showBuildSettings
68
- report.log_command "#{base_cmd} -showBuildSettings"
69
-
70
70
  # Add more options for the rest of the commands
71
+ base_cmd = "#{base_cmd} -scheme #{config.scheme}"
71
72
  base_cmd = "#{base_cmd} -configuration #{config.configuration} -sdk #{config.sdk}"
72
- base_cmd = "#{base_cmd} -target #{config.target}" unless config.workspace_path
73
+
74
+ # xcodebuild -showBuildSettings
75
+ report.write "$ #{base_cmd} -showBuildSettings\n\n"
76
+ report.write @xcodebuild_showbuildsettings_output
77
+ if @xcodebuild_showbuildsettings_status.success?
78
+ report.write "Success.\n\n"
79
+ else
80
+ report.write "#{@xcodebuild_showbuildsettings_status}.\n\n"
81
+ end
73
82
 
74
83
  if config.clean
75
84
  say "Cleaning"
@@ -146,7 +155,11 @@ EOF
146
155
  def version_from_branch_framework
147
156
  framework = config.target.frameworks_build_phase.files.find { |f| f.file_ref.path =~ /Branch.framework$/ }
148
157
  return nil unless framework
149
- framework_path = framework.file_ref.real_path
158
+ if framework.file_ref.isa == "PBXFileReference"
159
+ framework_path = framework.file_ref.real_path
160
+ elsif framework.file_ref.isa == "PBXReferenceProxy" && @xcode_settings
161
+ framework_path = File.expand_path framework.file_ref.path, @xcode_settings[framework.file_ref.source_tree]
162
+ end
150
163
  info_plist_path = File.join framework_path.to_s, "Info.plist"
151
164
  return nil unless File.exist? info_plist_path
152
165
 
@@ -158,9 +171,18 @@ EOF
158
171
  version ? "#{version} [Branch.framework/Info.plist]" : nil
159
172
  end
160
173
 
161
- def version_from_bnc_config_m
174
+ def version_from_bnc_config_m(project = @config.xcodeproj)
162
175
  # Look for BNCConfig.m in embedded source
163
- bnc_config_m_ref = config.xcodeproj.files.find { |f| f.path =~ /BNCConfig\.m$/ }
176
+ bnc_config_m_ref = project.files.find { |f| f.path =~ /BNCConfig\.m$/ }
177
+ unless bnc_config_m_ref
178
+ subprojects = project.files.select { |f| f.path =~ /\.xcodeproj$/ }
179
+ subprojects.each do |subproject|
180
+ p = Xcodeproj::Project.open subproject.real_path
181
+ version = version_from_bnc_config_m p
182
+ return version if version
183
+ end
184
+ end
185
+
164
186
  return nil unless bnc_config_m_ref
165
187
  bnc_config_m = File.read bnc_config_m_ref.real_path
166
188
  matches = /BNC_SDK_VERSION\s+=\s+@"(\d+\.\d+\.\d+)"/m.match bnc_config_m
@@ -216,6 +238,7 @@ EOF
216
238
  header = "cocoapods-core: #{Pod::CORE_VERSION}\n"
217
239
 
218
240
  header += `xcodebuild -version`
241
+ header += "SDK: #{@xcode_settings['SDK_NAME']}\n" if @xcode_settings
219
242
 
220
243
  bundle_identifier = helper.expanded_build_setting config.target, "PRODUCT_BUNDLE_IDENTIFIER", config.configuration
221
244
  dev_team = helper.expanded_build_setting config.target, "DEVELOPMENT_TEAM", config.configuration
@@ -348,6 +371,23 @@ EOF
348
371
 
349
372
  report
350
373
  end
374
+
375
+ def load_settings_from_xcode
376
+ cmd = "#{base_xcodebuild_cmd} -scheme #{config.scheme}"
377
+ cmd += " -configuration #{config.configuration} -sdk #{config.sdk} -showBuildSettings"
378
+ @xcodebuild_showbuildsettings_output = ""
379
+ @xcode_settings = {}
380
+ Open3.popen2e(cmd) do |stdin, output, thread|
381
+ while (line = output.gets)
382
+ @xcodebuild_showbuildsettings_output += line
383
+ line.strip!
384
+ next unless (matches = /^(.+)\s+=\s+(.+)$/.match line)
385
+ @xcode_settings[matches[1]] = matches[2]
386
+ end
387
+ @xcodebuild_showbuildsettings_status = thread.value
388
+ return @xcodebuild_showbuildsettings_status.success?
389
+ end
390
+ end
351
391
  end
352
392
  end
353
393
  end
@@ -13,14 +13,14 @@ module BranchIOCLI
13
13
  @header_only = options.header_only
14
14
  @scheme = options.scheme
15
15
  @target = options.target
16
- @configuration = options.configuration
17
16
  @report_path = options.out
18
17
  @sdk = options.sdk
19
18
  @pod_repo_update = options.pod_repo_update
20
19
 
21
20
  validate_xcodeproj_and_workspace options
22
- validate_target options
23
21
  validate_scheme options
22
+ validate_target options
23
+ validate_configuration options
24
24
 
25
25
  # If neither --podfile nor --cartfile is present, arbitrarily look for a Podfile
26
26
  # first.
@@ -132,24 +132,32 @@ EOF
132
132
 
133
133
  def validate_scheme(options)
134
134
  schemes = all_schemes
135
- # TODO: Prompt if --scheme specified but not found.
135
+
136
136
  if options.scheme && schemes.include?(options.scheme)
137
137
  @scheme = options.scheme
138
138
  elsif schemes.count == 1
139
139
  @scheme = schemes.first
140
+ say "Scheme #{options.scheme} not found. Using #{@scheme}." if options.scheme
140
141
  elsif !schemes.empty?
141
- # By default, take a scheme with the same name as the target name.
142
- return if (@scheme = schemes.find { |s| s == target.name })
142
+ # By default, take a scheme with the same name as the project name.
143
+ return if !options.scheme && (@scheme = schemes.find { |s| s == File.basename(xcodeproj_path, '.xcodeproj') })
143
144
 
144
- say "Please specify one of the following for the --scheme argument:"
145
- schemes.each do |scheme|
146
- say " #{scheme}"
145
+ @scheme = choose do |menu|
146
+ menu.header = "Schemes from project"
147
+ schemes.each { |s| menu.choice s }
148
+ menu.prompt = "Please choose one of the schemes above. "
147
149
  end
148
- exit 1
149
150
  else
150
151
  say "No scheme defined in project."
151
152
  exit(-1)
152
153
  end
154
+
155
+ return if options.target || xcscheme.nil?
156
+
157
+ # Find the target used when running the scheme if the user didn't specify one.
158
+ # This will be picked up in #validate_target
159
+ entry = xcscheme.build_action.entries.select(&:build_for_running?).first
160
+ options.target = entry.buildable_references.first.target_name
153
161
  end
154
162
 
155
163
  def all_schemes
@@ -159,6 +167,61 @@ EOF
159
167
  Xcodeproj::Project.schemes xcodeproj_path
160
168
  end
161
169
  end
170
+
171
+ def xcscheme
172
+ return @xcscheme if @xcscheme_checked
173
+ # This may not exist. If it comes back nil once, don't keep checking.
174
+ @xcscheme_checked = true
175
+ @xcscheme = scheme_with_name @scheme
176
+ @xcscheme
177
+ end
178
+
179
+ def scheme_with_name(scheme_name)
180
+ if workspace_path
181
+ project_path = workspace.schemes[@scheme]
182
+ else
183
+ project_path = xcodeproj_path
184
+ end
185
+
186
+ # Look for a shared scheme.
187
+ xcshareddata_path = File.join project_path, "xcshareddata", "xcschemes", "#{@scheme}.xcscheme"
188
+ scheme_path = xcshareddata_path if File.exist?(xcshareddata_path)
189
+
190
+ unless scheme_path
191
+ # Look for a local scheme
192
+ user = @xcode_settings["USER"] if @xcode_settings
193
+ user ||= ENV["USER"] || ENV["LOGNAME"]
194
+ xcuserdata_path = File.join project_path, "xcuserdata", "#{user}.xcuserdatad", "xcschemes", "#{@scheme}.xcscheme"
195
+ scheme_path = xcuserdata_path if File.exist?(xcuserdata_path)
196
+ end
197
+
198
+ return nil unless scheme_path
199
+
200
+ Xcodeproj::XCScheme.new(scheme_path)
201
+ end
202
+
203
+ def validate_configuration(options)
204
+ all_configs = xcodeproj.build_configurations.map(&:name)
205
+
206
+ if options.configuration && all_configs.include?(options.configuration)
207
+ @configuration = options.configuration
208
+ elsif options.configuration
209
+ say "Configuration #{options.configuration} not found."
210
+ @configuration = choose do |menu|
211
+ menu.header = "Configurations from project"
212
+ all_configs.each { |c| menu.choice c }
213
+ menu.prompt = "Please choose one of the above. "
214
+ end
215
+ end
216
+
217
+ return if @configuration
218
+
219
+ @configuration = "Debug" # Usual default for the launch action
220
+
221
+ return unless xcscheme
222
+
223
+ @configuration = xcscheme.launch_action.build_configuration
224
+ end
162
225
  end
163
226
  end
164
227
  end
@@ -375,18 +375,22 @@ module BranchIOCLI
375
375
  setting_value = target.resolved_build_setting(setting_name)[configuration]
376
376
  return if setting_value.nil?
377
377
 
378
+ expand_build_settings setting_value, target, configuration
379
+ end
380
+
381
+ def expand_build_settings(string, target, configuration)
378
382
  search_position = 0
379
- while (matches = /\$\(([^(){}]*)\)|\$\{([^(){}]*)\}/.match(setting_value, search_position))
383
+ while (matches = /\$\(([^(){}]*)\)|\$\{([^(){}]*)\}/.match(string, search_position))
380
384
  macro_name = matches[1] || matches[2]
381
- search_position = setting_value.index(macro_name) - 2
385
+ search_position = string.index(macro_name) - 2
382
386
 
383
387
  expanded_macro = macro_name == "SRCROOT" ? "." : expanded_build_setting(target, macro_name, configuration)
384
388
  search_position += macro_name.length + 3 and next if expanded_macro.nil?
385
389
 
386
- setting_value.gsub!(/\$\(#{macro_name}\)|\$\{#{macro_name}\}/, expanded_macro)
390
+ string.gsub!(/\$\(#{macro_name}\)|\$\{#{macro_name}\}/, expanded_macro)
387
391
  search_position += expanded_macro.length
388
392
  end
389
- setting_value
393
+ string
390
394
  end
391
395
 
392
396
  def add_cocoapods(options)
@@ -1,3 +1,3 @@
1
1
  module BranchIOCLI
2
- VERSION = "0.9.4"
2
+ VERSION = "0.9.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: branch_io_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Branch
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-11-09 00:00:00.000000000 Z
12
+ date: 2017-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: CFPropertyList