-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup_schemes.rb
More file actions
75 lines (59 loc) · 2.82 KB
/
setup_schemes.rb
File metadata and controls
75 lines (59 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'xcodeproj'
# Set up various properties
project_path = 'BBTestAppBundleIdentifiers.xcodeproj'
xcconfig_path = 'EnterpriseStaging.xcconfig'
target_name = 'BBTestAppBundleIdentifiers'
configuration_to_clone = 'Enterprise'
configuration_name = xcconfig_path.sub('.xcconfig', '')
# Open the xcode project
project = Xcodeproj::Project.open(project_path)
# Add the .xcconfig file to the xcode project
xcconfig_file = project.new_file(xcconfig_path)
# Basically we are going to clone an existing build configuration, then
# override the xcconfig
# Loop over the project-level build configurations
project.build_configurations.each do |build_configuration|
if build_configuration.name === configuration_to_clone
# This is the project-level build configuration we want to clone
# Make a new build configuration
generated_configuration = project.add_build_configuration(configuration_name, :release)
# Use the new .xcconfig
generated_configuration.base_configuration_reference = xcconfig_file
# Copy over the build settings from the original build configuration
generated_configuration.build_settings = build_configuration.build_settings
end
end
# Now we also need to make sure the new build configuration has settings
# for each target, so loop over the targets
project.targets.each do |target|
# Find the build configuration on the target we are trying to copy
target.build_configurations.each do |build_configuration|
if build_configuration.name === configuration_to_clone
# This is the target-level build configuration that we need to clone
# So, make a new build configuration
generated_target_configuration = project.new(Xcodeproj::Project::Object::XCBuildConfiguration)
# Set the name
generated_target_configuration.name = configuration_name
# Copy over the target-level build settings
generated_target_configuration.build_settings = build_configuration.build_settings
# Now add the new build configuration
target.build_configuration_list.build_configurations << generated_target_configuration
end
end
end
# Loop over the targets, and find the one we want our scheme to actually build
target_for_scheme = nil
project.targets.each do |target|
if target.name == target_name
target_for_scheme = target
end
end
# Generate a new scheme, set various properties then save it
scheme = Xcodeproj::XCScheme.new
scheme.add_build_target(target_for_scheme)
scheme.set_launch_target(target_for_scheme)
scheme.launch_action.build_configuration = configuration_name
scheme.archive_action.build_configuration = configuration_name
scheme.save_as(project.path(), configuration_name, true)
# Save the main project (to persist the build configuration changes)
project.save