branch_io_cli 0.9.9 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9193658d454dcab2a74341807a6594a25baaa647ec46eac3e44043ee632a696
4
- data.tar.gz: afb073e2385911619802a78066f281f9b36fef02d5613cba141ccaf8498dcd11
3
+ metadata.gz: d57e3295339b988ee4f835a92154eb15e45ae1df5655930902ebc5c43f1a33e0
4
+ data.tar.gz: 6b9b929afa148c9aa389116ac73e8d0eb8143ea5fed06285e389819371496c24
5
5
  SHA512:
6
- metadata.gz: cfb723a5edc92d5eaae87c3b2673cc1c41cc38aaf694dd19cec96e26a53fd3cb275559de3e442fbcd58c18cf1a5768b790a47643875b21f868b4e4bd21eac74a
7
- data.tar.gz: d134244741fe80706d32662edfb08d9212c80428b70aada33d90b2954b77ebe5ad6e88e080809b9d2e3685ce47758a37d03f15cb088dfded0e83aac849fda5ec
6
+ metadata.gz: 0f8a5e5132646571ed123b8546b8ceee45e998d0cc06356854d133c93cf544313302100f6058f22ecafa5a859f1459fd0c89b983745d3fadd865c2f95d7b0ee4
7
+ data.tar.gz: b37bd6a57304fb87f0ff721e30d1d7281bf52f1b0cfd6872b23b6cbd46494a4b5345b1f3925dfe6fc322f4365606b053aacb28aaad9b1875e5eae93d889dfe01
data/README.md CHANGED
@@ -121,6 +121,8 @@ that the relevant commands are available in your `PATH`.
121
121
  |--app-link-subdomain myapp|Branch app.link subdomain, e.g. myapp for myapp.app.link|
122
122
  |-D, --domains example.com,www.example.com|Comma-separated list of custom domain(s) or non-Branch domain(s)|
123
123
  |-U, --uri-scheme myurischeme[://]|Custom URI scheme used in the Branch Dashboard for this app|
124
+ |-s, --setting [BRANCH_KEY_SETTING]|Use a custom build setting for the Branch key (default: Use Info.plist)|
125
+ |--test-configurations|List of configurations that use the test key with a custom build setting (default: Debug configurations)|
124
126
  |--xcodeproj MyProject.xcodeproj|Path to an Xcode project to update|
125
127
  |--target MyAppTarget|Name of a target to modify in the Xcode project|
126
128
  |--podfile /path/to/Podfile|Path to the Podfile for the project|
@@ -132,7 +134,7 @@ that the relevant commands are available in your `PATH`.
132
134
  |--[no-]force|Update project even if Universal Link validation fails (default: no)|
133
135
  |--[no-]add-sdk|Add the Branch framework to the project (default: yes)|
134
136
  |--[no-]patch-source|Add Branch SDK calls to the AppDelegate (default: yes)|
135
- |--[no-]commit|Commit the results to Git (default: no)|
137
+ |--[no-]commit [message]|Commit the results to Git (default: no)|
136
138
 
137
139
  All parameters are optional. A live key or test key, or both is required, as well as at least one domain.
138
140
  Specify --live-key, --test-key or both and --app-link-subdomain, --domains or both. If these are not
@@ -236,7 +238,7 @@ report with additional diagnostic information suitable for opening a support tic
236
238
  |--[no-]pod-repo-update|Update the local podspec repo before installing (default: yes)|
237
239
  |--podfile /path/to/Podfile|Path to the Podfile for the project|
238
240
  |--cartfile /path/to/Cartfile|Path to the Cartfile for the project|
239
- |--out ./report.txt|Path to use for the generated report (default: ./report.txt)|
241
+ |-o, --out ./report.txt|Path to use for the generated report (default: ./report.txt)|
240
242
 
241
243
  ## Examples
242
244
 
@@ -12,7 +12,8 @@ _branch_io_complete()
12
12
  global_opts="-h --help -t --trace -v --version"
13
13
 
14
14
  setup_opts="$global_opts -L --live-key -T --test-key -D --domains --app-link-subdomain -U --uri-scheme"
15
- setup_opts="$setup_opts --xcodeproj --target --frameworks --podfile --cartfile --carthage-command"
15
+ setup_opts="$setup_opts --xcodeproj --target --frameworks --podfile --cartfile --carthage-command --setting -s"
16
+ setup_opts="$setup_opts --test-configurations --no-test-configurations"
16
17
  # Don't autocomplete the default values here, e.g. --no-force, --pod-repo-update.
17
18
  setup_opts="$setup_opts --no-add-sdk --no-validate --force --no-pod-repo-update --commit --no-patch-source"
18
19
 
@@ -5,7 +5,8 @@ _branch_io_complete() {
5
5
  word="$1"
6
6
  opts="-h --help -t --trace -v --version"
7
7
  opts="$opts -L --live-key -T --test-key -D --domains --app-link-subdomain -U --uri-scheme"
8
- opts="$opts --xcodeproj --target --frameworks --podfile --cartfile --carthage-command"
8
+ opts="$opts --xcodeproj --target --frameworks --podfile --cartfile --carthage-command --setting -s"
9
+ opts="$opts --test-configurations --no-test-configurations"
9
10
  # Don't autocomplete the default values here, e.g. --no-force, --pod-repo-update.
10
11
  opts="$opts --no-add-sdk --no-validate --force --no-pod-repo-update --commit --no-patch-source"
11
12
 
@@ -77,6 +77,8 @@ EOF
77
77
  c.option "--app-link-subdomain myapp", String, "Branch app.link subdomain, e.g. myapp for myapp.app.link"
78
78
  c.option "-D", "--domains example.com,www.example.com", Array, "Comma-separated list of custom domain(s) or non-Branch domain(s)"
79
79
  c.option "-U", "--uri-scheme myurischeme[://]", String, "Custom URI scheme used in the Branch Dashboard for this app"
80
+ c.option "-s", "--setting [BRANCH_KEY_SETTING]", String, "Use a custom build setting for the Branch key (default: Use Info.plist)"
81
+ c.option "--[no-]test-configurations [config1,config2]", Array, "List of configurations that use the test key with a custom build setting (default: Debug configurations)"
80
82
 
81
83
  c.option "--xcodeproj MyProject.xcodeproj", String, "Path to an Xcode project to update"
82
84
  c.option "--target MyAppTarget", String, "Name of a target to modify in the Xcode project"
@@ -90,7 +92,7 @@ EOF
90
92
  c.option "--[no-]force", "Update project even if Universal Link validation fails (default: no)"
91
93
  c.option "--[no-]add-sdk", "Add the Branch framework to the project (default: yes)"
92
94
  c.option "--[no-]patch-source", "Add Branch SDK calls to the AppDelegate (default: yes)"
93
- c.option "--[no-]commit", "Commit the results to Git (default: no)"
95
+ c.option "--[no-]commit [message]", String, "Commit the results to Git (default: no)"
94
96
 
95
97
  c.example "Test without validation (can use dummy keys and domains)", "branch_io setup -L key_live_xxxx -D myapp.app.link --no-validate"
96
98
  c.example "Use both live and test keys", "branch_io setup -L key_live_xxxx -T key_test_yyyy -D myapp.app.link"
@@ -169,7 +171,7 @@ EOF
169
171
  c.option "--[no-]clean", "Clean before attempting to build (default: yes)"
170
172
  c.option "-H", "--[no-]header-only", "Write a report header to standard output and exit"
171
173
  c.option "--[no-]pod-repo-update", "Update the local podspec repo before installing (default: yes)"
172
- c.option "--out ./report.txt", String, "Report output path (default: ./report.txt)"
174
+ c.option "-o", "--out ./report.txt", String, "Report output path (default: ./report.txt)"
173
175
 
174
176
  c.action do |args, options|
175
177
  options.default(
@@ -7,7 +7,11 @@ module BranchIOCLI
7
7
  say "\n"
8
8
 
9
9
  say "Loading settings from Xcode"
10
- if xcode_settings.valid?
10
+ # In case running in a non-CLI context (e.g., Rake or Fastlane) be sure
11
+ # to reset Xcode settings each time, since project, target and
12
+ # configurations will change.
13
+ Configuration::XcodeSettings.reset
14
+ if Configuration::XcodeSettings.all_valid?
11
15
  say "Done ✅"
12
16
  else
13
17
  say "Failed to load settings from Xcode. Some information may be missing.\n"
@@ -15,63 +19,66 @@ module BranchIOCLI
15
19
 
16
20
  if config.header_only
17
21
  say report_helper.report_header
18
- exit 0
22
+ return
19
23
  end
20
24
 
21
- File.open config.report_path, "w" do |report|
22
- report.write "Branch.io Xcode build report v #{VERSION} #{DateTime.now}\n\n"
23
- report.write "#{config.report_configuration}\n"
24
- report.write "#{report_helper.report_header}\n"
25
+ if config.report_path == "stdout"
26
+ write_report STDOUT
27
+ else
28
+ File.open(config.report_path, "w") { |f| write_report f }
29
+ say "Report generated in #{config.report_path}"
30
+ end
31
+ end
32
+
33
+ def write_report(report)
34
+ report.write "Branch.io Xcode build report v #{VERSION} #{DateTime.now}\n\n"
35
+ report.write "#{config.report_configuration}\n"
36
+ report.write "#{report_helper.report_header}\n"
25
37
 
26
- report_helper.pod_install_if_required report
38
+ report_helper.pod_install_if_required report
27
39
 
28
- # run xcodebuild -list
29
- report.log_command "#{report_helper.base_xcodebuild_cmd} -list"
40
+ # run xcodebuild -list
41
+ report.log_command "#{report_helper.base_xcodebuild_cmd} -list"
30
42
 
31
- # If using a workspace, -list all the projects as well
32
- if config.workspace_path
33
- config.workspace.file_references.map(&:path).each do |project_path|
34
- path = File.join File.dirname(config.workspace_path), project_path
35
- report.log_command "xcodebuild -list -project #{Shellwords.escape path}"
36
- end
43
+ # If using a workspace, -list all the projects as well
44
+ if config.workspace_path
45
+ config.workspace.file_references.map(&:path).each do |project_path|
46
+ path = File.join File.dirname(config.workspace_path), project_path
47
+ report.log_command "xcodebuild -list -project #{Shellwords.escape path}"
37
48
  end
49
+ end
38
50
 
39
- base_cmd = report_helper.base_xcodebuild_cmd
40
- # Add more options for the rest of the commands
41
- base_cmd += " -scheme #{Shellwords.escape config.scheme}"
42
- base_cmd += " -configuration #{Shellwords.escape config.configuration}"
43
- base_cmd += " -sdk #{Shellwords.escape config.sdk}"
51
+ # xcodebuild -showBuildSettings
52
+ config.configurations.each do |configuration|
53
+ Configuration::XcodeSettings[configuration].log_xcodebuild_showbuildsettings report
54
+ end
44
55
 
45
- # xcodebuild -showBuildSettings
46
- xcode_settings.log_xcodebuild_showbuildsettings report
56
+ base_cmd = report_helper.base_xcodebuild_cmd
57
+ # Add more options for the rest of the commands
58
+ base_cmd += " -scheme #{Shellwords.escape config.scheme}"
59
+ base_cmd += " -configuration #{Shellwords.escape(config.configuration || config.configurations_from_scheme.first)}"
60
+ base_cmd += " -sdk #{Shellwords.escape config.sdk}"
47
61
 
48
- if config.clean
49
- say "Cleaning"
50
- if report.log_command("#{base_cmd} clean").success?
51
- say "Done ✅"
52
- else
53
- say "Clean failed."
54
- end
55
- end
56
-
57
- say "Building"
58
- if report.log_command("#{base_cmd} -verbose").success?
62
+ if config.clean
63
+ say "Cleaning"
64
+ if report.log_command("#{base_cmd} clean").success?
59
65
  say "Done ✅"
60
66
  else
61
- say "Build failed."
67
+ say "Clean failed."
62
68
  end
63
69
  end
64
70
 
65
- say "Report generated in #{config.report_path}"
71
+ say "Building"
72
+ if report.log_command("#{base_cmd} -verbose").success?
73
+ say "Done ✅"
74
+ else
75
+ say "Build failed."
76
+ end
66
77
  end
67
78
 
68
79
  def report_helper
69
80
  Helper::ReportHelper
70
81
  end
71
-
72
- def xcode_settings
73
- Configuration::XcodeSettings.settings
74
- end
75
82
  end
76
83
  end
77
84
  end
@@ -30,18 +30,18 @@ module BranchIOCLI
30
30
  say "Universal Link configuration passed validation. ✅"
31
31
  end
32
32
 
33
- if @keys.count > 1 && helper.has_multiple_info_plists? &&
34
- !File.exist?(File.join(File.dirname(config.podfile_path), 'Pods'))
35
- # Work around a potential crash for now. The PBXBuildConfiguration#debug?
36
- # method may raise in this case.
33
+ if config.podfile_path && File.exist?(config.podfile_path) && config.pod_install_required?
37
34
  helper.verify_cocoapods
38
35
  say "Installing pods to resolve current build settings"
39
- # We haven't modified anything yet. Don't use --repo-update at this stage.
40
- # This is unlikely to fail.
41
- sh "pod install"
36
+ Dir.chdir(File.dirname(config.podfile_path)) do
37
+ # We haven't modified anything yet. Don't use --repo-update at this stage.
38
+ # This is unlikely to fail.
39
+ sh "pod install"
40
+ end
42
41
  end
43
42
 
44
- # the following calls can all raise IOError
43
+ helper.add_custom_build_setting if config.setting
44
+
45
45
  helper.add_keys_to_info_plist @keys
46
46
  helper.add_branch_universal_link_domains_to_info_plist @domains if is_app_target
47
47
  helper.ensure_uri_scheme_in_info_plist if is_app_target # does nothing if already present
@@ -76,7 +76,10 @@ module BranchIOCLI
76
76
 
77
77
  changes = helper.changes.to_a.map { |c| Pathname.new(File.expand_path(c)).relative_path_from(Pathname.pwd).to_s }
78
78
 
79
- sh "git commit -qm '[branch_io_cli] Branch SDK integration' #{changes.join(' ')}"
79
+ commit_message = options.commit if options.commit.kind_of?(String)
80
+ commit_message ||= "[branch_io_cli] Branch SDK integration #{config.relative_path(config.xcodeproj_path)} (#{config.target.name})"
81
+
82
+ sh "git commit -qm #{Shellwords.escape commit_message} #{changes.join(' ')}"
80
83
  end
81
84
  # rubocop: enable Metrics/PerceivedComplexity
82
85
 
@@ -268,11 +268,11 @@ EOF
268
268
  setting == "YES"
269
269
  end
270
270
 
271
- def bridging_header_path
271
+ def bridging_header_path(configuration = "Release")
272
272
  return @bridging_header_path if @bridging_header_path
273
273
 
274
274
  return nil unless target
275
- path = helper.expanded_build_setting target, "SWIFT_OBJC_BRIDGING_HEADER", "Release"
275
+ path = helper.expanded_build_setting target, "SWIFT_OBJC_BRIDGING_HEADER", configuration
276
276
  return nil unless path
277
277
 
278
278
  @bridging_header_path = File.expand_path path, File.dirname(xcodeproj_path)
@@ -292,7 +292,11 @@ EOF
292
292
 
293
293
  source_files = target.source_build_phase.files.map { |f| f.file_ref.real_path.to_s }
294
294
  source_files << bridging_header_path if bridging_header_path
295
- @branch_imports = source_files.compact.map { |f| { f => branch_imports_from_file(f) } }.inject({}, :merge)
295
+ @branch_imports = source_files.compact.map do |f|
296
+ imports = branch_imports_from_file f
297
+ next {} if imports.empty?
298
+ { f => imports }
299
+ end.inject({}, :merge)
296
300
  @branch_imports
297
301
  end
298
302
 
@@ -51,10 +51,6 @@ module BranchIOCLI
51
51
  attr_reader :report_path
52
52
  attr_reader :sdk
53
53
 
54
- def xcode_settings
55
- XcodeSettings.settings
56
- end
57
-
58
54
  def validate_options
59
55
  @clean = options.clean
60
56
  @header_only = options.header_only
@@ -105,7 +101,7 @@ EOF
105
101
  <%= color('Xcode project:', BOLD) %> #{xcodeproj_path || '(none)'}
106
102
  <%= color('Scheme:', BOLD) %> #{scheme || '(none)'}
107
103
  <%= color('Target:', BOLD) %> #{target || '(none)'}
108
- <%= color('Configuration:', BOLD) %> #{configuration}
104
+ <%= color('Configuration:', BOLD) %> #{configuration || '(none)'}
109
105
  <%= color('SDK:', BOLD) %> #{sdk}
110
106
  <%= color('Podfile:', BOLD) %> #{relative_path(podfile_path) || '(none)'}
111
107
  <%= color('Cartfile:', BOLD) %> #{relative_path(cartfile_path) || '(none)'}
@@ -265,11 +261,13 @@ EOF
265
261
  end
266
262
 
267
263
  def validate_configuration(options)
264
+ return unless options.configuration
265
+
268
266
  all_configs = xcodeproj.build_configurations.map(&:name)
269
267
 
270
- if options.configuration && all_configs.include?(options.configuration)
268
+ if all_configs.include?(options.configuration)
271
269
  @configuration = options.configuration
272
- elsif options.configuration
270
+ else
273
271
  say "Configuration #{options.configuration} not found."
274
272
  @configuration = choose do |menu|
275
273
  menu.header = "Configurations from project"
@@ -277,14 +275,15 @@ EOF
277
275
  menu.prompt = "Please choose one of the above. "
278
276
  end
279
277
  end
278
+ end
280
279
 
281
- return if @configuration
282
-
283
- @configuration = "Debug" # Usual default for the launch action
284
-
285
- return unless xcscheme
280
+ def configurations
281
+ configuration ? [configuration] : configurations_from_scheme
282
+ end
286
283
 
287
- @configuration = xcscheme.launch_action.build_configuration
284
+ def configurations_from_scheme
285
+ return ["Debug", "Release"] unless xcscheme
286
+ %i[test launch profile archive analyze].map { |pfx| xcscheme.send("#{pfx}_action").build_configuration }.uniq
288
287
  end
289
288
 
290
289
  def branch_version
@@ -335,17 +334,18 @@ EOF
335
334
  "#{version} [Cartfile.resolved]"
336
335
  end
337
336
 
338
- def version_from_branch_framework
337
+ def version_from_branch_framework(configuration = configurations.first)
339
338
  framework = target.frameworks_build_phase.files.find { |f| f.file_ref.path =~ /Branch.framework$/ }
340
339
  return nil unless framework
341
340
 
342
341
  if framework.file_ref.isa == "PBXFileReference"
343
- project_path = relative_path(config.xcodeproj_path)
342
+ project_path = relative_path(xcodeproj_path)
344
343
  framework_path = framework.file_ref.real_path
345
- elsif framework.file_ref.isa == "PBXReferenceProxy" && xcode_settings
344
+ elsif framework.file_ref.isa == "PBXReferenceProxy" && XcodeSettings[configuration].valid?
346
345
  project_path = relative_path framework.file_ref.remote_ref.proxied_object.project.path
347
- framework_path = File.expand_path framework.file_ref.path, xcode_settings[framework.file_ref.source_tree]
346
+ framework_path = File.expand_path framework.file_ref.path, XcodeSettings[configuration][framework.file_ref.source_tree]
348
347
  end
348
+ return nil unless framework_path
349
349
  info_plist_path = File.join framework_path.to_s, "Info.plist"
350
350
  return nil unless File.exist? info_plist_path
351
351
 
@@ -377,6 +377,19 @@ EOF
377
377
  version = matches[1]
378
378
  "#{version} [BNCConfig.m:#{relative_path project.path}]"
379
379
  end
380
+
381
+ def branch_key_setting_from_info_plist(config = configuration || "Release")
382
+ return @branch_key_setting_from_info_plist if @branch_key_setting_from_info_plist
383
+
384
+ infoplist_path = helper.expanded_build_setting target, "INFOPLIST_FILE", config
385
+ infoplist_path = File.expand_path infoplist_path, File.dirname(xcodeproj_path)
386
+ info_plist = File.open(infoplist_path) { |f| Plist.parse_xml f }
387
+ branch_key = info_plist["branch_key"]
388
+ regexp = /^\$\((\w+)\)$|^\$\{(\w+)\}$/
389
+ return nil unless branch_key.kind_of?(String) && (matches = regexp.match branch_key)
390
+ @branch_key_setting_from_info_plist = matches[1] || matches[2]
391
+ @branch_key_setting_from_info_plist
392
+ end
380
393
  end
381
394
  end
382
395
  end
@@ -20,6 +20,8 @@ module BranchIOCLI
20
20
  attr_reader :force
21
21
  attr_reader :patch_source
22
22
  attr_reader :commit
23
+ attr_reader :setting
24
+ attr_reader :test_configurations
23
25
 
24
26
  def validate_options
25
27
  @validate = options.validate
@@ -39,6 +41,8 @@ module BranchIOCLI
39
41
  validate_keys_from_setup_options options
40
42
  validate_all_domains options, !target.extension_target_type?
41
43
  validate_uri_scheme options
44
+ validate_setting options
45
+ validate_test_configurations options
42
46
 
43
47
  # If neither --podfile nor --cartfile is present, arbitrarily look for a Podfile
44
48
  # first.
@@ -63,6 +67,20 @@ module BranchIOCLI
63
67
  <%= color('Test key:', BOLD) %> #{keys[:test] || '(none)'}
64
68
  <%= color('Domains:', BOLD) %> #{all_domains}
65
69
  <%= color('URI scheme:', BOLD) %> #{uri_scheme || '(none)'}
70
+ EOF
71
+
72
+ if setting
73
+ message += <<-EOF
74
+ <%= color('Branch key setting:', BOLD) %> #{setting}
75
+ EOF
76
+ if test_configurations
77
+ message += <<-EOF
78
+ <%= color('Test configurations:', BOLD) %> #{test_configurations}
79
+ EOF
80
+ end
81
+ end
82
+
83
+ message += <<-EOF
66
84
  <%= color('Podfile:', BOLD) %> #{relative_path(podfile_path) || '(none)'}
67
85
  <%= color('Cartfile:', BOLD) %> #{relative_path(cartfile_path) || '(none)'}
68
86
  <%= color('Carthage command:', BOLD) %> #{carthage_command || '(none)'}
@@ -241,6 +259,40 @@ module BranchIOCLI
241
259
  @carthage_command = options.carthage_command
242
260
  end
243
261
  end
262
+
263
+ def validate_setting(options)
264
+ setting = options.setting
265
+ return if setting.nil?
266
+
267
+ @setting = "BRANCH_KEY" and return if setting == true
268
+
269
+ loop do
270
+ if setting =~ /^[A-Z0-9_]+$/
271
+ @setting = setting
272
+ return
273
+ end
274
+ setting = ask "Invalid build setting. Please enter an all-caps identifier (may include digits and underscores): "
275
+ end
276
+ end
277
+
278
+ def validate_test_configurations(options)
279
+ return if options.test_configurations.nil?
280
+ unless options.setting
281
+ say "--test-configurations ignored without --setting"
282
+ return
283
+ end
284
+
285
+ all_configurations = target.build_configurations.map(&:name)
286
+ test_configs = options.test_configurations == false ? [] : options.test_configurations
287
+ loop do
288
+ invalid_configurations = test_configs.reject { |c| all_configurations.include? c }
289
+ @test_configurations = test_configs and return if invalid_configurations.empty?
290
+
291
+ say "The following test configurations are invalid: #{invalid_configurations}."
292
+ say "Available configurations: #{all_configurations}"
293
+ test_configs = ask "Please enter a comma-separated list of configurations to use the Branch test key: ", Array
294
+ end
295
+ end
244
296
  end
245
297
  end
246
298
  end
@@ -5,14 +5,30 @@ module BranchIOCLI
5
5
  module Configuration
6
6
  class XcodeSettings
7
7
  class << self
8
- def settings
9
- return @settings if @settings
10
- @settings = self.new
11
- @settings
8
+ def all_valid?
9
+ Configuration.current.configurations.map { |c| settings(c) }.all?(&:valid?)
10
+ end
11
+
12
+ def [](configuration)
13
+ settings configuration
14
+ end
15
+
16
+ def settings(configuration = Configuration.current.configurations.first)
17
+ return @settings[configuration] if @settings && @settings[configuration]
18
+ @settings ||= {}
19
+
20
+ @settings[configuration] = self.new configuration
21
+ end
22
+
23
+ def reset
24
+ @settings = {}
12
25
  end
13
26
  end
14
27
 
15
- def initialize
28
+ attr_reader :configuration
29
+
30
+ def initialize(configuration)
31
+ @configuration = configuration
16
32
  load_settings_from_xcode
17
33
  end
18
34
 
@@ -30,11 +46,11 @@ module BranchIOCLI
30
46
 
31
47
  def xcodebuild_cmd
32
48
  cmd = "xcodebuild"
33
- cmd = "#{cmd} -project #{Shellwords.escape config.xcodeproj_path}"
49
+ cmd += " -showBuildSettings"
50
+ cmd += " -project #{Shellwords.escape config.xcodeproj_path}"
34
51
  cmd += " -target #{Shellwords.escape config.target.name}"
35
- cmd += " -configuration #{Shellwords.escape config.configuration}"
36
52
  cmd += " -sdk #{Shellwords.escape config.sdk}"
37
- cmd += " -showBuildSettings"
53
+ cmd += " -configuration #{Shellwords.escape configuration}"
38
54
  cmd
39
55
  end
40
56
 
@@ -53,7 +69,12 @@ module BranchIOCLI
53
69
  end
54
70
 
55
71
  def log_xcodebuild_showbuildsettings(report = STDOUT)
56
- report.write "$ #{xcodebuild_cmd}\n\n"
72
+ if report == STDOUT
73
+ say "<%= color('$ #{xcodebuild_cmd}', [MAGENTA, BOLD]) %>\n\n"
74
+ else
75
+ report.write "$ #{xcodebuild_cmd}\n\n"
76
+ end
77
+
57
78
  report.write @xcodebuild_showbuildsettings_output
58
79
  if valid?
59
80
  report.write "Success.\n\n"
@@ -32,13 +32,31 @@ module BranchIOCLI
32
32
  end.uniq.count > 1
33
33
  end
34
34
 
35
+ def uses_test_key?(build_configuration)
36
+ return build_configuration.debug? unless config.setting && config.test_configurations
37
+ config.test_configurations.include? build_configuration.name
38
+ end
39
+
40
+ def add_custom_build_setting
41
+ return unless config.setting
42
+
43
+ config.target.build_configurations.each do |c|
44
+ key = uses_test_key?(c) ? config.keys[:test] : config.keys[:live]
45
+ # Reuse the same key if both not present
46
+ key ||= uses_test_key?(c) ? config.keys[:live] : config.keys[:test]
47
+ c.build_settings[config.setting] = key
48
+ end
49
+ end
50
+
35
51
  def add_keys_to_info_plist(keys)
36
52
  if has_multiple_info_plists?
37
53
  config.xcodeproj.build_configurations.each do |c|
38
54
  update_info_plist_setting c.name do |info_plist|
39
- if keys.count > 1
55
+ if keys.count > 1 && !config.setting
40
56
  # Use test key in debug configs and live key in release configs
41
57
  info_plist["branch_key"] = c.debug? ? keys[:test] : keys[:live]
58
+ elsif config.setting
59
+ info_plist["branch_key"] = "$(#{config.setting})"
42
60
  else
43
61
  info_plist["branch_key"] = keys[:live] ? keys[:live] : keys[:test]
44
62
  end
@@ -47,8 +65,10 @@ module BranchIOCLI
47
65
  else
48
66
  update_info_plist_setting RELEASE_CONFIGURATION do |info_plist|
49
67
  # add/overwrite Branch key(s)
50
- if keys.count > 1
68
+ if keys.count > 1 && !config.setting
51
69
  info_plist["branch_key"] = keys
70
+ elsif config.setting
71
+ info_plist["branch_key"] = "$(#{config.setting})"
52
72
  elsif keys[:live]
53
73
  info_plist["branch_key"] = keys[:live]
54
74
  else
@@ -23,7 +23,7 @@ module BranchIOCLI
23
23
  end
24
24
 
25
25
  def use_conditional_test_key?
26
- config.keys.count > 1 && !helper.has_multiple_info_plists?
26
+ config.keys.count > 1 && config.setting.nil? && !helper.has_multiple_info_plists?
27
27
  end
28
28
 
29
29
  def swift_file_includes_branch?(path)
@@ -38,6 +38,13 @@ module BranchIOCLI
38
38
  cmd
39
39
  end
40
40
 
41
+ def report_scheme
42
+ report = "\nScheme #{config.scheme}:\n"
43
+ report += " Configurations:\n"
44
+ report += " #{config.configurations_from_scheme.join("\n ")}\n"
45
+ report
46
+ end
47
+
41
48
  # rubocop: disable Metrics/PerceivedComplexity
42
49
  def report_header
43
50
  header = "cocoapods-core: #{Pod::CORE_VERSION}\n"
@@ -45,10 +52,14 @@ module BranchIOCLI
45
52
  header += `xcodebuild -version`
46
53
  header += "SDK: #{xcode_settings['SDK_NAME']}\n" if xcode_settings
47
54
 
48
- bundle_identifier = helper.expanded_build_setting config.target, "PRODUCT_BUNDLE_IDENTIFIER", config.configuration
49
- dev_team = helper.expanded_build_setting config.target, "DEVELOPMENT_TEAM", config.configuration
50
- infoplist_path = helper.expanded_build_setting config.target, "INFOPLIST_FILE", config.configuration
51
- entitlements_path = helper.expanded_build_setting config.target, "CODE_SIGN_ENTITLEMENTS", config.configuration
55
+ header += report_scheme
56
+
57
+ configuration = config.configuration || config.configurations_from_scheme.first
58
+ configurations = config.configuration ? [config.configuration] : config.configurations_from_scheme
59
+
60
+ bundle_identifier = helper.expanded_build_setting config.target, "PRODUCT_BUNDLE_IDENTIFIER", configuration
61
+ dev_team = helper.expanded_build_setting config.target, "DEVELOPMENT_TEAM", configuration
62
+ entitlements_path = helper.expanded_build_setting config.target, "CODE_SIGN_ENTITLEMENTS", configuration
52
63
 
53
64
  header += "\nTarget #{config.target.name}:\n"
54
65
  header += " Bundle identifier: #{bundle_identifier || '(none)'}\n"
@@ -57,7 +68,12 @@ module BranchIOCLI
57
68
  header += " Modules #{config.modules_enabled? ? '' : 'not '}enabled\n"
58
69
  header += " Swift #{config.swift_version}\n" if config.swift_version
59
70
  header += " Bridging header: #{config.relative_path(config.bridging_header_path)}\n" if config.bridging_header_path
60
- header += " Info.plist: #{config.relative_path(infoplist_path) || '(none)'}\n"
71
+
72
+ header += " Info.plist\n"
73
+ configurations.each do |c|
74
+ header += " #{c}: #{helper.expanded_build_setting config.target, 'INFOPLIST_FILE', c}\n"
75
+ end
76
+
61
77
  header += " Entitlements file: #{config.relative_path(entitlements_path) || '(none)'}\n"
62
78
 
63
79
  if config.podfile_path
@@ -121,53 +137,66 @@ module BranchIOCLI
121
137
  header += "\nBranch SDK not found.\n"
122
138
  end
123
139
 
124
- header += "\n#{branch_report}"
140
+ header += "\n#{report_branch}"
125
141
 
126
142
  header
127
143
  end
128
144
  # rubocop: enable Metrics/PerceivedComplexity
129
145
 
130
146
  # String containing information relevant to Branch setup
131
- def branch_report
132
- infoplist_path = helper.expanded_build_setting config.target, "INFOPLIST_FILE", config.configuration
133
- infoplist_path = File.expand_path infoplist_path, File.dirname(config.xcodeproj_path)
134
-
147
+ def report_branch
135
148
  report = "Branch configuration:\n"
136
149
 
137
- begin
138
- info_plist = File.open(infoplist_path) { |f| Plist.parse_xml f }
139
- branch_key = info_plist["branch_key"]
140
- report += " Branch key(s) (Info.plist):\n"
141
- if branch_key.kind_of? Hash
142
- branch_key.each_key do |key|
143
- resolved_key = helper.expand_build_settings branch_key[key], config.target, config.configuration
144
- report += " #{key.capitalize}: #{resolved_key}\n"
150
+ configurations = config.configuration ? [config.configuration] : config.configurations_from_scheme
151
+
152
+ configurations.each do |configuration|
153
+ report += " #{configuration}:\n"
154
+ infoplist_path = helper.expanded_build_setting config.target, "INFOPLIST_FILE", configuration
155
+ infoplist_path = File.expand_path infoplist_path, File.dirname(config.xcodeproj_path)
156
+
157
+ begin
158
+ info_plist = File.open(infoplist_path) { |f| Plist.parse_xml f }
159
+ branch_key = info_plist["branch_key"]
160
+ if config.branch_key_setting_from_info_plist(configuration)
161
+ annotation = "[#{File.basename infoplist_path}:$(#{config.branch_key_setting_from_info_plist})]"
162
+ else
163
+ annotation = "(#{File.basename infoplist_path})"
145
164
  end
146
- elsif branch_key
147
- resolved_key = helper.expand_build_settings branch_key, config.target, config.configuration
148
- report += " #{resolved_key}\n"
149
- else
150
- report += " (none found)\n"
151
- end
152
165
 
153
- branch_universal_link_domains = info_plist["branch_universal_link_domains"]
154
- if branch_universal_link_domains
155
- if branch_universal_link_domains.kind_of? Array
156
- report += " branch_universal_link_domains (Info.plist):\n"
157
- branch_universal_link_domains.each do |domain|
158
- report += " #{domain}\n"
166
+ report += " Branch key(s) #{annotation}:\n"
167
+ if branch_key.kind_of? Hash
168
+ branch_key.each_key do |key|
169
+ resolved_key = helper.expand_build_settings branch_key[key], config.target, configuration
170
+ report += " #{key.capitalize}: #{resolved_key}\n"
159
171
  end
172
+ elsif branch_key
173
+ resolved_key = helper.expand_build_settings branch_key, config.target, configuration
174
+ report += " #{resolved_key}\n"
160
175
  else
161
- report += " branch_universal_link_domains (Info.plist): #{branch_universal_link_domains}\n"
176
+ report += " (none found)\n"
162
177
  end
178
+
179
+ branch_universal_link_domains = info_plist["branch_universal_link_domains"]
180
+ if branch_universal_link_domains
181
+ if branch_universal_link_domains.kind_of? Array
182
+ report += " branch_universal_link_domains (Info.plist):\n"
183
+ branch_universal_link_domains.each do |domain|
184
+ report += " #{domain}\n"
185
+ end
186
+ else
187
+ report += " branch_universal_link_domains (Info.plist): #{branch_universal_link_domains}\n"
188
+ end
189
+ end
190
+ rescue StandardError => e
191
+ report += " (Failed to open Info.plist: #{e.message})\n"
163
192
  end
164
- rescue StandardError => e
165
- report += " (Failed to open Info.plist: #{e.message})\n"
166
193
  end
167
194
 
168
195
  unless config.target.extension_target_type?
169
196
  begin
170
- domains = helper.domains_from_project config.configuration
197
+ # This isn't likely to vary by configuration, so just report for one, either
198
+ # whatever was passed or Release.
199
+ domains = helper.domains_from_project config.configuration || config.configurations_from_scheme.first
171
200
  report += " Universal Link domains (entitlements):\n"
172
201
  domains.each do |domain|
173
202
  report += " #{domain}\n"
@@ -0,0 +1,88 @@
1
+ require "rake"
2
+ require "rake/tasklib"
3
+ require "branch_io_cli"
4
+ require "highline/import"
5
+
6
+ module BranchIOCLI
7
+ class RakeTask < Rake::TaskLib
8
+ ReportOptions = Struct.new(
9
+ :cartfile,
10
+ :clean,
11
+ :configuration,
12
+ :header_only,
13
+ :out,
14
+ :pod_repo_update,
15
+ :podfile,
16
+ :scheme,
17
+ :sdk,
18
+ :target,
19
+ :xcodeproj,
20
+ :workspace
21
+ )
22
+
23
+ attr_reader :defaults
24
+
25
+ def initialize(defaults = {}, &b)
26
+ @defaults = defaults
27
+ @defaults[:report] ||= {}
28
+
29
+ namespace :branch do
30
+ report_task
31
+ end
32
+ end
33
+
34
+ def report_task
35
+ desc "Generate a brief Branch report"
36
+ task :report, %i{paths options} do |task, args|
37
+ paths = args[:paths]
38
+ paths = [paths] unless paths.respond_to?(:each)
39
+
40
+ paths.each do |path|
41
+ Dir.chdir(path) do |p|
42
+ Command::ReportCommand.new(report_options(args[:options])).run!
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ # rubocop: disable Metrics/PerceivedComplexity
49
+ def report_options(options)
50
+ options ||= {}
51
+ defs = defaults[:report]
52
+
53
+ if options[:clean].nil? && defs[:clean].nil?
54
+ clean = true
55
+ else
56
+ clean = options[:clean] || defs[:clean]
57
+ end
58
+
59
+ if options[:pod_repo_update].nil? && defs[:pod_repo_update].nil?
60
+ repo_update = true
61
+ else
62
+ repo_update = options[:pod_repo_update] || defs[:pod_repo_update]
63
+ end
64
+
65
+ if options[:header_only].nil? && defs[:header_only].nil?
66
+ header_only = false
67
+ else
68
+ header_only = options[:header_only] || defs[:header_only]
69
+ end
70
+
71
+ ReportOptions.new(
72
+ options[:cartfile] || defs[:cartfile],
73
+ clean,
74
+ options[:configuration] || defs[:configuration],
75
+ header_only,
76
+ options[:out] || defs[:out] || "./report.txt",
77
+ repo_update,
78
+ options[:podfile] || defs[:podfile],
79
+ options[:scheme] || defs[:scheme],
80
+ options[:sdk] || defs[:sdk] || "iphonesimulator",
81
+ options[:target] || defs[:target],
82
+ options[:xcodeproj] || defs[:xcodeproj],
83
+ options[:workspace] || defs[:workspace]
84
+ )
85
+ end
86
+ # rubocop: enable Metrics/PerceivedComplexity
87
+ end
88
+ end
@@ -1,3 +1,3 @@
1
1
  module BranchIOCLI
2
- VERSION = "0.9.9"
2
+ VERSION = "0.10.0"
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.9
4
+ version: 0.10.0
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-15 00:00:00.000000000 Z
12
+ date: 2017-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: CFPropertyList
@@ -310,6 +310,7 @@ files:
310
310
  - lib/branch_io_cli/helper/methods.rb
311
311
  - lib/branch_io_cli/helper/patch_helper.rb
312
312
  - lib/branch_io_cli/helper/report_helper.rb
313
+ - lib/branch_io_cli/rake_task.rb
313
314
  - lib/branch_io_cli/version.rb
314
315
  homepage: http://github.com/BranchMetrics/branch_io_cli
315
316
  licenses: