xcodeproj 0.28.2 → 1.0.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 +4 -4
- data/lib/xcodeproj/command/config_dump.rb +2 -1
- data/lib/xcodeproj/config/other_linker_flags_parser.rb +5 -2
- data/lib/xcodeproj/config.rb +14 -5
- data/lib/xcodeproj/constants.rb +62 -27
- data/lib/xcodeproj/differ.rb +7 -7
- data/lib/xcodeproj/gem_version.rb +1 -1
- data/lib/xcodeproj/plist/ffi/core_foundation.rb +441 -0
- data/lib/xcodeproj/plist/ffi/dev_tools_core.rb +188 -0
- data/lib/xcodeproj/plist/ffi.rb +119 -0
- data/lib/xcodeproj/plist/plist_gem.rb +27 -0
- data/lib/xcodeproj/plist.rb +89 -0
- data/lib/xcodeproj/project/object/build_configuration.rb +15 -0
- data/lib/xcodeproj/project/object/build_rule.rb +28 -0
- data/lib/xcodeproj/project/object/group.rb +28 -0
- data/lib/xcodeproj/project/object/helpers/file_references_factory.rb +1 -1
- data/lib/xcodeproj/project/object/native_target.rb +26 -7
- data/lib/xcodeproj/project/object.rb +16 -3
- data/lib/xcodeproj/project/object_attributes.rb +10 -0
- data/lib/xcodeproj/project/object_dictionary.rb +2 -0
- data/lib/xcodeproj/project/object_list.rb +16 -4
- data/lib/xcodeproj/project/project_helper.rb +1 -1
- data/lib/xcodeproj/project/uuid_generator.rb +1 -0
- data/lib/xcodeproj/project.rb +36 -12
- data/lib/xcodeproj/scheme/build_action.rb +5 -2
- data/lib/xcodeproj/scheme/environment_variables.rb +170 -0
- data/lib/xcodeproj/scheme/launch_action.rb +16 -0
- data/lib/xcodeproj/scheme/test_action.rb +18 -0
- data/lib/xcodeproj/scheme.rb +5 -5
- data/lib/xcodeproj/workspace/file_reference.rb +2 -3
- data/lib/xcodeproj/workspace/group_reference.rb +64 -0
- data/lib/xcodeproj/workspace.rb +127 -34
- data/lib/xcodeproj.rb +1 -1
- metadata +29 -17
- data/lib/xcodeproj/plist_helper.rb +0 -758
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
require 'xcodeproj/scheme/xml_element_wrapper'
|
|
2
|
+
|
|
3
|
+
module Xcodeproj
|
|
4
|
+
class XCScheme
|
|
5
|
+
VARIABLES_NODE = 'EnvironmentVariables'
|
|
6
|
+
VARIABLE_NODE = 'EnvironmentVariable'
|
|
7
|
+
|
|
8
|
+
# This class wraps the EnvironmentVariables node of a .xcscheme XML file. This
|
|
9
|
+
# is just a container of EnvironmentVariable objects. It can either appear on a
|
|
10
|
+
# LaunchAction or TestAction scheme group.
|
|
11
|
+
#
|
|
12
|
+
class EnvironmentVariables < XMLElementWrapper
|
|
13
|
+
# @param [nil,REXML::Element,Array<EnvironmentVariable>,Array<Hash{Symbol => String,Bool}>] node_or_variables
|
|
14
|
+
# The 'EnvironmentVariables' XML node, or list of environment variables, that this object represents.
|
|
15
|
+
# - If nil, an empty 'EnvironmentVariables' XML node will be created
|
|
16
|
+
# - If an REXML::Element, it must be named 'EnvironmentVariables'
|
|
17
|
+
# - If an Array of objects or Hashes, they'll each be passed to {#assign_variable}
|
|
18
|
+
#
|
|
19
|
+
def initialize(node_or_variables = nil)
|
|
20
|
+
create_xml_element_with_fallback(node_or_variables, VARIABLES_NODE) do
|
|
21
|
+
@all_variables = []
|
|
22
|
+
node_or_variables.each { |var| assign_variable(var) } unless node_or_variables.nil?
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @return [Array<EnvironmentVariable>]
|
|
27
|
+
# The key value pairs currently set in @xml_element
|
|
28
|
+
#
|
|
29
|
+
def all_variables
|
|
30
|
+
@all_variables ||= @xml_element.get_elements(VARIABLE_NODE).map { |variable| EnvironmentVariable.new(variable) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Adds a given variable to the set of environment variables, or replaces it if that key already exists
|
|
34
|
+
#
|
|
35
|
+
# @param [EnvironmentVariable,Hash{Symbol => String,Bool}] variable
|
|
36
|
+
# The variable to add or update, backed by an EnvironmentVariable node.
|
|
37
|
+
# - If an EnvironmentVariable, the previous reference will still be valid
|
|
38
|
+
# - If a Hash, must conform to {EnvironmentVariable#initialize} requirements
|
|
39
|
+
# @return [Array<EnvironmentVariable>]
|
|
40
|
+
# The new set of environment variables after addition
|
|
41
|
+
#
|
|
42
|
+
def assign_variable(variable)
|
|
43
|
+
env_var = variable.is_a?(EnvironmentVariable) ? variable : EnvironmentVariable.new(variable)
|
|
44
|
+
all_variables.each { |existing_var| remove_variable(existing_var) if existing_var.key == env_var.key }
|
|
45
|
+
@xml_element.add_element(env_var.xml_element)
|
|
46
|
+
@all_variables << env_var
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Removes a specified variable (by string or object) from the set of environment variables
|
|
50
|
+
#
|
|
51
|
+
# @param [EnvironmentVariable,String] variable
|
|
52
|
+
# The variable to remove
|
|
53
|
+
# @return [Array<EnvironmentVariable>]
|
|
54
|
+
# The new set of environment variables after removal
|
|
55
|
+
#
|
|
56
|
+
def remove_variable(variable)
|
|
57
|
+
env_var = variable.is_a?(EnvironmentVariable) ? variable : all_variables.find { |var| var.key == variable }
|
|
58
|
+
raise "Unexpected parameter type: #{env_var.class}" unless env_var.is_a?(EnvironmentVariable)
|
|
59
|
+
@xml_element.delete_element(env_var.xml_element)
|
|
60
|
+
@all_variables -= [env_var]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# @param [String] key
|
|
64
|
+
# The key to lookup
|
|
65
|
+
# @return [EnvironmentVariable] variable
|
|
66
|
+
# Returns the matching environment variable for a specified key
|
|
67
|
+
#
|
|
68
|
+
def [](key)
|
|
69
|
+
all_variables.find { |var| var.key == key }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Assigns a value for a specified key
|
|
73
|
+
#
|
|
74
|
+
# @param [String] key
|
|
75
|
+
# The key to update in the environment variables
|
|
76
|
+
# @param [String] value
|
|
77
|
+
# The value to lookup
|
|
78
|
+
# @return [EnvironmentVariable] variable
|
|
79
|
+
# The newly updated environment variable
|
|
80
|
+
#
|
|
81
|
+
def []=(key, value)
|
|
82
|
+
assign_variable(:key => key, :value => value)
|
|
83
|
+
self[key]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# @return [Array<Hash{Symbol => String,Bool}>]
|
|
87
|
+
# The current environment variables represented as an array
|
|
88
|
+
#
|
|
89
|
+
def to_a
|
|
90
|
+
all_variables.map(&:to_h)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# This class wraps the EnvironmentVariable node of a .xcscheme XML file.
|
|
95
|
+
# Environment variables are accessible via the NSDictionary returned from
|
|
96
|
+
# [[NSProcessInfo processInfo] environment] in your app code.
|
|
97
|
+
#
|
|
98
|
+
class EnvironmentVariable < XMLElementWrapper
|
|
99
|
+
# @param [nil,REXML::Element,Hash{Symbol => String,Bool}] node_or_variable
|
|
100
|
+
# - If nil, it will create a default XML node to use
|
|
101
|
+
# - If a REXML::Element, should be a <EnvironmentVariable> XML node to wrap
|
|
102
|
+
# - If a Hash, must contain keys :key and :value (Strings) and optionally :enabled (Boolean)
|
|
103
|
+
#
|
|
104
|
+
def initialize(node_or_variable)
|
|
105
|
+
create_xml_element_with_fallback(node_or_variable, VARIABLE_NODE) do
|
|
106
|
+
raise "Must pass a Hash with 'key' and 'value'!" unless node_or_variable.is_a?(Hash) &&
|
|
107
|
+
node_or_variable.key?(:key) && node_or_variable.key?(:value)
|
|
108
|
+
|
|
109
|
+
@xml_element.attributes['key'] = node_or_variable[:key]
|
|
110
|
+
@xml_element.attributes['value'] = node_or_variable[:value]
|
|
111
|
+
|
|
112
|
+
@xml_element.attributes['isEnabled'] = if node_or_variable.key?(:enabled)
|
|
113
|
+
bool_to_string(node_or_variable[:enabled])
|
|
114
|
+
else
|
|
115
|
+
bool_to_string(true)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Returns the EnvironmentValue's key
|
|
121
|
+
# @return [String]
|
|
122
|
+
#
|
|
123
|
+
def key
|
|
124
|
+
@xml_element.attributes['key']
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Sets the EnvironmentValue's key
|
|
128
|
+
# @param [String] key
|
|
129
|
+
#
|
|
130
|
+
def key=(key)
|
|
131
|
+
@xml_element.attributes['key'] = key
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Returns the EnvironmentValue's value
|
|
135
|
+
# @return [String]
|
|
136
|
+
#
|
|
137
|
+
def value
|
|
138
|
+
@xml_element.attributes['value']
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Sets the EnvironmentValue's value
|
|
142
|
+
# @param [String] value
|
|
143
|
+
#
|
|
144
|
+
def value=(value)
|
|
145
|
+
@xml_element.attributes['value'] = value
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Returns the EnvironmentValue's enabled state
|
|
149
|
+
# @return [Bool]
|
|
150
|
+
#
|
|
151
|
+
def enabled
|
|
152
|
+
string_to_bool(@xml_element.attributes['isEnabled'])
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Sets the EnvironmentValue's enabled state
|
|
156
|
+
# @param [Bool] enabled
|
|
157
|
+
#
|
|
158
|
+
def enabled=(enabled)
|
|
159
|
+
@xml_element.attributes['isEnabled'] = bool_to_string(enabled)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# @return [Hash{:key => String, :value => String, :enabled => Bool}]
|
|
163
|
+
# The environment variable XML node with attributes converted to a representative Hash
|
|
164
|
+
#
|
|
165
|
+
def to_h
|
|
166
|
+
{ :key => key, :value => value, :enabled => enabled }
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
@@ -62,6 +62,22 @@ module Xcodeproj
|
|
|
62
62
|
@xml_element.add_element(runnable.xml_element) if runnable
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
+
# @return [EnvironmentVariables]
|
|
66
|
+
# Returns the EnvironmentVariables that will be defined at app launch
|
|
67
|
+
#
|
|
68
|
+
def environment_variables
|
|
69
|
+
EnvironmentVariables.new(@xml_element.elements[XCScheme::VARIABLES_NODE])
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# @param [EnvironmentVariables,nil] env_vars
|
|
73
|
+
# Sets the EnvironmentVariables that will be defined at app launch
|
|
74
|
+
#
|
|
75
|
+
def environment_variables=(env_vars)
|
|
76
|
+
@xml_element.delete_element(XCScheme::VARIABLES_NODE)
|
|
77
|
+
@xml_element.add_element(env_vars.xml_element) if env_vars
|
|
78
|
+
env_vars
|
|
79
|
+
end
|
|
80
|
+
|
|
65
81
|
# @todo handle 'AdditionalOptions' tag
|
|
66
82
|
end
|
|
67
83
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'xcodeproj/scheme/abstract_scheme_action'
|
|
2
|
+
require 'xcodeproj/scheme/environment_variables'
|
|
2
3
|
|
|
3
4
|
module Xcodeproj
|
|
4
5
|
class XCScheme
|
|
@@ -84,6 +85,23 @@ module Xcodeproj
|
|
|
84
85
|
@xml_element.add_element(macro_expansion.xml_element)
|
|
85
86
|
end
|
|
86
87
|
|
|
88
|
+
# @return [EnvironmentVariables]
|
|
89
|
+
# Returns the EnvironmentVariables that will be defined at test launch
|
|
90
|
+
#
|
|
91
|
+
def environment_variables
|
|
92
|
+
EnvironmentVariables.new(@xml_element.elements[XCScheme::VARIABLES_NODE])
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# @param [EnvironmentVariables,nil] env_vars
|
|
96
|
+
# Sets the EnvironmentVariables that will be defined at test launch
|
|
97
|
+
# @return [EnvironmentVariables]
|
|
98
|
+
#
|
|
99
|
+
def environment_variables=(env_vars)
|
|
100
|
+
@xml_element.delete_element(XCScheme::VARIABLES_NODE)
|
|
101
|
+
@xml_element.add_element(env_vars.xml_element) if env_vars
|
|
102
|
+
env_vars
|
|
103
|
+
end
|
|
104
|
+
|
|
87
105
|
#-------------------------------------------------------------------------#
|
|
88
106
|
|
|
89
107
|
class TestableReference < XMLElementWrapper
|
data/lib/xcodeproj/scheme.rb
CHANGED
|
@@ -300,11 +300,11 @@ module Xcodeproj
|
|
|
300
300
|
# scheme.save_as('path/to/Project.xcodeproj') #=> true
|
|
301
301
|
#
|
|
302
302
|
def save_as(project_path, name, shared = true)
|
|
303
|
-
if shared
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
303
|
+
scheme_folder_path = if shared
|
|
304
|
+
self.class.shared_data_dir(project_path)
|
|
305
|
+
else
|
|
306
|
+
self.class.user_data_dir(project_path)
|
|
307
|
+
end
|
|
308
308
|
scheme_folder_path.mkpath
|
|
309
309
|
scheme_path = scheme_folder_path + "#{name}.xcscheme"
|
|
310
310
|
File.open(scheme_path, 'w') do |f|
|
|
@@ -76,10 +76,9 @@ module Xcodeproj
|
|
|
76
76
|
when 'absolute'
|
|
77
77
|
File.expand_path(path)
|
|
78
78
|
when 'developer'
|
|
79
|
-
raise
|
|
80
|
-
"#{self}"
|
|
79
|
+
raise "Developer workspace file reference type is not yet supported (#{path})"
|
|
81
80
|
else
|
|
82
|
-
raise "Unsupported workspace file reference type
|
|
81
|
+
raise "Unsupported workspace file reference type `#{type}`"
|
|
83
82
|
end
|
|
84
83
|
end
|
|
85
84
|
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module Xcodeproj
|
|
2
|
+
class Workspace
|
|
3
|
+
# Describes a group reference of a Workspace.
|
|
4
|
+
#
|
|
5
|
+
class GroupReference
|
|
6
|
+
# @return [String] the name of the group
|
|
7
|
+
#
|
|
8
|
+
attr_reader :name
|
|
9
|
+
|
|
10
|
+
# @return [String] the type of reference to the project
|
|
11
|
+
#
|
|
12
|
+
# This can be of the following values:
|
|
13
|
+
# - absolute
|
|
14
|
+
# - group
|
|
15
|
+
# - container (only supported value)
|
|
16
|
+
# - developer
|
|
17
|
+
#
|
|
18
|
+
attr_reader :type
|
|
19
|
+
|
|
20
|
+
# @param [#to_s] name @see name
|
|
21
|
+
# @param [#to_s] type @see type
|
|
22
|
+
#
|
|
23
|
+
def initialize(name, type = 'container')
|
|
24
|
+
@name = name.to_s
|
|
25
|
+
@type = type.to_s
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# @return [Bool] Whether a group reference is equal to another.
|
|
29
|
+
#
|
|
30
|
+
def ==(other)
|
|
31
|
+
name == other.name && type == other.type
|
|
32
|
+
end
|
|
33
|
+
alias_method :eql?, :==
|
|
34
|
+
|
|
35
|
+
# @return [Fixnum] A hash identical for equals objects.
|
|
36
|
+
#
|
|
37
|
+
def hash
|
|
38
|
+
[name, type].hash
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Returns a group reference given XML representation.
|
|
42
|
+
#
|
|
43
|
+
# @param [REXML::Element] xml_node
|
|
44
|
+
# the XML representation.
|
|
45
|
+
#
|
|
46
|
+
# @return [GroupReference] The new group reference instance.
|
|
47
|
+
#
|
|
48
|
+
def self.from_node(xml_node)
|
|
49
|
+
type = xml_node.attribute('location').value.split(':', 2).first
|
|
50
|
+
name = xml_node.attribute('name').value
|
|
51
|
+
new(name, type)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# @return [REXML::Element] the XML representation of the group reference.
|
|
55
|
+
#
|
|
56
|
+
def to_node
|
|
57
|
+
REXML::Element.new('Group').tap do |element|
|
|
58
|
+
element.add_attribute('location', "#{type}:")
|
|
59
|
+
element.add_attribute('name', "#{name}")
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
data/lib/xcodeproj/workspace.rb
CHANGED
|
@@ -1,24 +1,56 @@
|
|
|
1
1
|
require 'fileutils'
|
|
2
2
|
require 'rexml/document'
|
|
3
3
|
require 'xcodeproj/workspace/file_reference'
|
|
4
|
+
require 'xcodeproj/workspace/group_reference'
|
|
4
5
|
|
|
5
6
|
module Xcodeproj
|
|
6
7
|
# Provides support for generating, reading and serializing Xcode Workspace
|
|
7
8
|
# documents.
|
|
8
9
|
#
|
|
9
10
|
class Workspace
|
|
10
|
-
# @return [
|
|
11
|
+
# @return [REXML::Document] the parsed XML model for the workspace contents
|
|
12
|
+
attr_reader :document
|
|
13
|
+
|
|
14
|
+
# @return [Hash<String => String>] a mapping from scheme name to project full path
|
|
15
|
+
# containing the scheme
|
|
16
|
+
attr_reader :schemes
|
|
17
|
+
|
|
11
18
|
# @return [Array<FileReference>] the paths of the projects contained in the
|
|
12
19
|
# workspace.
|
|
13
20
|
#
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
def file_references
|
|
22
|
+
return [] unless @document
|
|
23
|
+
@document.get_elements('/Workspace//FileRef').map do |node|
|
|
24
|
+
FileReference.from_node(node)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# @return [Array<GroupReference>] the groups contained in the workspace
|
|
29
|
+
#
|
|
30
|
+
def group_references
|
|
31
|
+
return [] unless @document
|
|
32
|
+
@document.get_elements('/Workspace//Group').map do |node|
|
|
33
|
+
GroupReference.from_node(node)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
16
36
|
|
|
17
|
-
# @param
|
|
37
|
+
# @param [REXML::Document] document @see document
|
|
38
|
+
# @param [Array<FileReference>] file_references additional projects to add
|
|
39
|
+
#
|
|
40
|
+
# @note The document parameter is passed to the << operator if it is not a
|
|
41
|
+
# valid REXML::Document. It is optional, but may also be passed as nil
|
|
18
42
|
#
|
|
19
|
-
def initialize(*file_references)
|
|
20
|
-
@file_references = file_references.flatten
|
|
43
|
+
def initialize(document, *file_references)
|
|
21
44
|
@schemes = {}
|
|
45
|
+
if document.nil?
|
|
46
|
+
@document = REXML::Document.new(root_xml(''))
|
|
47
|
+
elsif document.is_a?(REXML::Document)
|
|
48
|
+
@document = document
|
|
49
|
+
else
|
|
50
|
+
@document = REXML::Document.new(root_xml(''))
|
|
51
|
+
self << document
|
|
52
|
+
end
|
|
53
|
+
file_references.each { |ref| self << ref }
|
|
22
54
|
end
|
|
23
55
|
|
|
24
56
|
#-------------------------------------------------------------------------#
|
|
@@ -31,9 +63,10 @@ module Xcodeproj
|
|
|
31
63
|
# @return [Workspace] the generated workspace.
|
|
32
64
|
#
|
|
33
65
|
def self.new_from_xcworkspace(path)
|
|
34
|
-
from_s(File.read(File.join(path, 'contents.xcworkspacedata')),
|
|
66
|
+
from_s(File.read(File.join(path, 'contents.xcworkspacedata')),
|
|
67
|
+
File.expand_path(File.dirname(path)))
|
|
35
68
|
rescue Errno::ENOENT
|
|
36
|
-
new
|
|
69
|
+
new(nil)
|
|
37
70
|
end
|
|
38
71
|
|
|
39
72
|
#-------------------------------------------------------------------------#
|
|
@@ -48,28 +81,53 @@ module Xcodeproj
|
|
|
48
81
|
#
|
|
49
82
|
def self.from_s(xml, workspace_path = '')
|
|
50
83
|
document = REXML::Document.new(xml)
|
|
51
|
-
|
|
52
|
-
FileReference.from_node(node)
|
|
53
|
-
end
|
|
54
|
-
instance = new(file_references)
|
|
84
|
+
instance = new(document)
|
|
55
85
|
instance.load_schemes(workspace_path)
|
|
56
86
|
instance
|
|
57
87
|
end
|
|
58
88
|
|
|
59
|
-
#-------------------------------------------------------------------------#
|
|
60
|
-
|
|
61
89
|
# Adds a new path to the list of the of projects contained in the
|
|
62
90
|
# workspace.
|
|
91
|
+
# @param [String, Xcodeproj::Workspace::FileReference] path_or_reference
|
|
92
|
+
# A string or Xcode::Workspace::FileReference containing a path to an Xcode project
|
|
63
93
|
#
|
|
64
|
-
# @
|
|
65
|
-
# The path of the project to add.
|
|
94
|
+
# @raise [ArgumentError] Raised if the input is neither a String nor a FileReference
|
|
66
95
|
#
|
|
67
96
|
# @return [void]
|
|
68
97
|
#
|
|
69
|
-
def <<(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
98
|
+
def <<(path_or_reference)
|
|
99
|
+
return unless @document && @document.respond_to?(:root)
|
|
100
|
+
case
|
|
101
|
+
when path_or_reference.is_a?(String)
|
|
102
|
+
project_file_reference = Xcodeproj::Workspace::FileReference.new(path_or_reference)
|
|
103
|
+
when path_or_reference.is_a?(Xcodeproj::Workspace::FileReference)
|
|
104
|
+
project_file_reference = path_or_reference
|
|
105
|
+
projpath = nil
|
|
106
|
+
else
|
|
107
|
+
raise ArgumentError, 'Input to the << operator must be a file path or FileReference'
|
|
108
|
+
end
|
|
109
|
+
@document.root.add_element(project_file_reference.to_node)
|
|
110
|
+
load_schemes_from_project File.expand_path(projpath || project_file_reference.path)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
#-------------------------------------------------------------------------#
|
|
114
|
+
|
|
115
|
+
# Adds a new group container to the workspace
|
|
116
|
+
# workspace.
|
|
117
|
+
#
|
|
118
|
+
# @param [String] name The name of the group
|
|
119
|
+
#
|
|
120
|
+
# @yield [Xcodeproj::Workspace::GroupReference, REXML::Element]
|
|
121
|
+
# Yields the GroupReference and underlying XML element for mutation
|
|
122
|
+
#
|
|
123
|
+
# @return [Xcodeproj::Workspace::GroupReference] The added group reference
|
|
124
|
+
#
|
|
125
|
+
def add_group(name)
|
|
126
|
+
return nil unless @document
|
|
127
|
+
group = Xcodeproj::Workspace::GroupReference.new(name)
|
|
128
|
+
elem = @document.root.add_element(group.to_node)
|
|
129
|
+
yield group, elem if block_given?
|
|
130
|
+
group
|
|
73
131
|
end
|
|
74
132
|
|
|
75
133
|
# Checks if the workspace contains the project with the given file
|
|
@@ -81,14 +139,32 @@ module Xcodeproj
|
|
|
81
139
|
# @return [Boolean] whether the project is contained in the workspace.
|
|
82
140
|
#
|
|
83
141
|
def include?(file_reference)
|
|
84
|
-
|
|
142
|
+
file_references.include?(file_reference)
|
|
85
143
|
end
|
|
86
144
|
|
|
87
145
|
# @return [String] the XML representation of the workspace.
|
|
88
146
|
#
|
|
89
147
|
def to_s
|
|
90
|
-
contents =
|
|
91
|
-
|
|
148
|
+
contents = ''
|
|
149
|
+
stack = []
|
|
150
|
+
@document.root.each_recursive do |elem|
|
|
151
|
+
until stack.empty?
|
|
152
|
+
last = stack.last
|
|
153
|
+
break if last == elem.parent
|
|
154
|
+
contents += xcworkspace_element_end_xml(stack.length, last)
|
|
155
|
+
stack.pop
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
stack << elem
|
|
159
|
+
contents += xcworkspace_element_start_xml(stack.length, elem)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
until stack.empty?
|
|
163
|
+
contents += xcworkspace_element_end_xml(stack.length, stack.last)
|
|
164
|
+
stack.pop
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
root_xml(contents)
|
|
92
168
|
end
|
|
93
169
|
|
|
94
170
|
# Saves the workspace at the given `xcworkspace` path.
|
|
@@ -115,7 +191,7 @@ module Xcodeproj
|
|
|
115
191
|
# @return [void]
|
|
116
192
|
#
|
|
117
193
|
def load_schemes(workspace_dir_path)
|
|
118
|
-
|
|
194
|
+
file_references.each do |file_reference|
|
|
119
195
|
project_full_path = file_reference.absolute_path(workspace_dir_path)
|
|
120
196
|
load_schemes_from_project(project_full_path)
|
|
121
197
|
end
|
|
@@ -146,21 +222,38 @@ module Xcodeproj
|
|
|
146
222
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
147
223
|
<Workspace
|
|
148
224
|
version = "1.0">
|
|
149
|
-
|
|
225
|
+
#{contents.rstrip}
|
|
150
226
|
</Workspace>
|
|
151
|
-
|
|
227
|
+
DOC
|
|
152
228
|
end
|
|
153
229
|
|
|
154
|
-
# @return [String] The XML representation of a file reference.
|
|
155
230
|
#
|
|
156
|
-
# @param [
|
|
231
|
+
# @param [Integer] depth The depth of the element in the tree
|
|
232
|
+
# @param [REXML::Document::Element] elem The XML element to format.
|
|
157
233
|
#
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
234
|
+
# @return [String] The Xcode-specific XML formatting of an element start
|
|
235
|
+
#
|
|
236
|
+
def xcworkspace_element_start_xml(depth, elem)
|
|
237
|
+
attributes = case elem.name
|
|
238
|
+
when 'Group'
|
|
239
|
+
%w(location name)
|
|
240
|
+
when 'FileRef'
|
|
241
|
+
%w(location)
|
|
242
|
+
end
|
|
243
|
+
contents = "<#{elem.name}"
|
|
244
|
+
indent = ' ' * depth
|
|
245
|
+
attributes.each { |name| contents += "\n #{name} = \"#{elem.attribute(name)}\"" }
|
|
246
|
+
contents.split("\n").map { |line| "#{indent}#{line}" }.join("\n") + ">\n"
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
#
|
|
250
|
+
# @param [Integer] depth The depth of the element in the tree
|
|
251
|
+
# @param [REXML::Document::Element] elem The XML element to format.
|
|
252
|
+
#
|
|
253
|
+
# @return [String] The Xcode-specific XML formatting of an element end
|
|
254
|
+
#
|
|
255
|
+
def xcworkspace_element_end_xml(depth, elem)
|
|
256
|
+
"#{' ' * depth}</#{elem.name}>\n"
|
|
164
257
|
end
|
|
165
258
|
|
|
166
259
|
#-------------------------------------------------------------------------#
|
data/lib/xcodeproj.rb
CHANGED
|
@@ -20,7 +20,7 @@ module Xcodeproj
|
|
|
20
20
|
autoload :Constants, 'xcodeproj/constants'
|
|
21
21
|
autoload :Differ, 'xcodeproj/differ'
|
|
22
22
|
autoload :Helper, 'xcodeproj/helper'
|
|
23
|
-
autoload :
|
|
23
|
+
autoload :Plist, 'xcodeproj/plist'
|
|
24
24
|
autoload :Project, 'xcodeproj/project'
|
|
25
25
|
autoload :Workspace, 'xcodeproj/workspace'
|
|
26
26
|
autoload :XCScheme, 'xcodeproj/scheme'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: xcodeproj
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eloy Duran
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -42,16 +42,22 @@ dependencies:
|
|
|
42
42
|
name: claide
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- -
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 1.0.0
|
|
48
|
+
- - <
|
|
46
49
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0
|
|
50
|
+
version: '2.0'
|
|
48
51
|
type: :runtime
|
|
49
52
|
prerelease: false
|
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
54
|
requirements:
|
|
52
|
-
- -
|
|
55
|
+
- - '>='
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: 1.0.0
|
|
58
|
+
- - <
|
|
53
59
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 0
|
|
60
|
+
version: '2.0'
|
|
55
61
|
description: Xcodeproj lets you create and modify Xcode projects from Ruby. Script
|
|
56
62
|
boring management tasks or build Xcode-friendly libraries. Also includes support
|
|
57
63
|
for Xcode workspaces (.xcworkspace) and configuration files (.xcconfig).
|
|
@@ -61,22 +67,30 @@ executables:
|
|
|
61
67
|
extensions: []
|
|
62
68
|
extra_rdoc_files: []
|
|
63
69
|
files:
|
|
64
|
-
- README.md
|
|
65
70
|
- LICENSE
|
|
71
|
+
- README.md
|
|
72
|
+
- bin/xcodeproj
|
|
73
|
+
- lib/xcodeproj.rb
|
|
74
|
+
- lib/xcodeproj/command.rb
|
|
66
75
|
- lib/xcodeproj/command/config_dump.rb
|
|
67
76
|
- lib/xcodeproj/command/project_diff.rb
|
|
68
77
|
- lib/xcodeproj/command/show.rb
|
|
69
78
|
- lib/xcodeproj/command/sort.rb
|
|
70
79
|
- lib/xcodeproj/command/target_diff.rb
|
|
71
|
-
- lib/xcodeproj/command.rb
|
|
72
|
-
- lib/xcodeproj/config/other_linker_flags_parser.rb
|
|
73
80
|
- lib/xcodeproj/config.rb
|
|
81
|
+
- lib/xcodeproj/config/other_linker_flags_parser.rb
|
|
74
82
|
- lib/xcodeproj/constants.rb
|
|
75
83
|
- lib/xcodeproj/differ.rb
|
|
76
84
|
- lib/xcodeproj/gem_version.rb
|
|
77
85
|
- lib/xcodeproj/helper.rb
|
|
78
|
-
- lib/xcodeproj/
|
|
86
|
+
- lib/xcodeproj/plist.rb
|
|
87
|
+
- lib/xcodeproj/plist/ffi.rb
|
|
88
|
+
- lib/xcodeproj/plist/ffi/core_foundation.rb
|
|
89
|
+
- lib/xcodeproj/plist/ffi/dev_tools_core.rb
|
|
90
|
+
- lib/xcodeproj/plist/plist_gem.rb
|
|
91
|
+
- lib/xcodeproj/project.rb
|
|
79
92
|
- lib/xcodeproj/project/case_converter.rb
|
|
93
|
+
- lib/xcodeproj/project/object.rb
|
|
80
94
|
- lib/xcodeproj/project/object/build_configuration.rb
|
|
81
95
|
- lib/xcodeproj/project/object/build_file.rb
|
|
82
96
|
- lib/xcodeproj/project/object/build_phase.rb
|
|
@@ -91,31 +105,29 @@ files:
|
|
|
91
105
|
- lib/xcodeproj/project/object/reference_proxy.rb
|
|
92
106
|
- lib/xcodeproj/project/object/root_object.rb
|
|
93
107
|
- lib/xcodeproj/project/object/target_dependency.rb
|
|
94
|
-
- lib/xcodeproj/project/object.rb
|
|
95
108
|
- lib/xcodeproj/project/object_attributes.rb
|
|
96
109
|
- lib/xcodeproj/project/object_dictionary.rb
|
|
97
110
|
- lib/xcodeproj/project/object_list.rb
|
|
98
111
|
- lib/xcodeproj/project/project_helper.rb
|
|
99
112
|
- lib/xcodeproj/project/uuid_generator.rb
|
|
100
|
-
- lib/xcodeproj/
|
|
113
|
+
- lib/xcodeproj/scheme.rb
|
|
101
114
|
- lib/xcodeproj/scheme/abstract_scheme_action.rb
|
|
102
115
|
- lib/xcodeproj/scheme/analyze_action.rb
|
|
103
116
|
- lib/xcodeproj/scheme/archive_action.rb
|
|
104
117
|
- lib/xcodeproj/scheme/build_action.rb
|
|
105
118
|
- lib/xcodeproj/scheme/buildable_product_runnable.rb
|
|
106
119
|
- lib/xcodeproj/scheme/buildable_reference.rb
|
|
120
|
+
- lib/xcodeproj/scheme/environment_variables.rb
|
|
107
121
|
- lib/xcodeproj/scheme/launch_action.rb
|
|
108
122
|
- lib/xcodeproj/scheme/macro_expansion.rb
|
|
109
123
|
- lib/xcodeproj/scheme/profile_action.rb
|
|
110
124
|
- lib/xcodeproj/scheme/test_action.rb
|
|
111
125
|
- lib/xcodeproj/scheme/xml_element_wrapper.rb
|
|
112
|
-
- lib/xcodeproj/scheme.rb
|
|
113
126
|
- lib/xcodeproj/user_interface.rb
|
|
114
|
-
- lib/xcodeproj/workspace/file_reference.rb
|
|
115
127
|
- lib/xcodeproj/workspace.rb
|
|
128
|
+
- lib/xcodeproj/workspace/file_reference.rb
|
|
129
|
+
- lib/xcodeproj/workspace/group_reference.rb
|
|
116
130
|
- lib/xcodeproj/xcodebuild_helper.rb
|
|
117
|
-
- lib/xcodeproj.rb
|
|
118
|
-
- bin/xcodeproj
|
|
119
131
|
homepage: https://github.com/cocoapods/xcodeproj
|
|
120
132
|
licenses:
|
|
121
133
|
- MIT
|
|
@@ -136,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
136
148
|
version: '0'
|
|
137
149
|
requirements: []
|
|
138
150
|
rubyforge_project:
|
|
139
|
-
rubygems_version: 2.
|
|
151
|
+
rubygems_version: 2.6.3
|
|
140
152
|
signing_key:
|
|
141
153
|
specification_version: 3
|
|
142
154
|
summary: Create and modify Xcode projects from Ruby.
|