xcake 0.6.25 → 0.7.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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/Gemfile.lock +10 -10
  4. data/README.md +4 -0
  5. data/bin/xcake +1 -1
  6. data/docs/Cakefile.md +23 -4
  7. data/docs/Sample/Cakefile +365 -0
  8. data/lib/xcake/context/xcodeproj_context.rb +3 -4
  9. data/lib/xcake/generator/configuration_generator.rb +1 -1
  10. data/lib/xcake/generator/target_file_reference_generator.rb +24 -30
  11. data/lib/xcake/informative.rb +1 -1
  12. data/lib/xcake/path_classifier.rb +66 -0
  13. data/lib/xcake/project/sugar.rb +26 -0
  14. data/lib/xcake/project.rb +0 -1
  15. data/lib/xcake/target/configurable.rb +38 -0
  16. data/lib/xcake/target.rb +0 -39
  17. data/lib/xcake/ui.rb +2 -3
  18. data/lib/xcake/version.rb +1 -1
  19. data/lib/xcake/xcode/project.rb +35 -43
  20. data/lib/xcake/xcodeproj_ext/PBXGroup.rb +41 -0
  21. data/lib/xcake/xcodeproj_ext/PBXNativeTarget.rb +14 -0
  22. data/lib/xcake.rb +6 -2
  23. data/xcake.gemspec +1 -1
  24. metadata +10 -14
  25. data/lib/xcake/file_reference_installer/compile_source_file_reference_installer.rb +0 -15
  26. data/lib/xcake/file_reference_installer/compile_xcdatamodeld_file_reference_installer.rb +0 -22
  27. data/lib/xcake/file_reference_installer/copy_resources_file_reference_installer.rb +0 -25
  28. data/lib/xcake/file_reference_installer/copy_xcassets_file_reference_installer.rb +0 -22
  29. data/lib/xcake/file_reference_installer/header_file_reference_installer.rb +0 -11
  30. data/lib/xcake/file_reference_installer/link_library_file_reference_installer.rb +0 -21
  31. data/lib/xcake/file_reference_installer.rb +0 -83
  32. data/lib/xcake/node.rb +0 -138
  33. /data/{_hound.yml → hound.yml} +0 -0
  34. /data/{_rubocop.yml → rubocop.yml} +0 -0
  35. /data/{_rubocop_general.yml → rubocop_general.yml} +0 -0
@@ -0,0 +1,66 @@
1
+ require 'pathname'
2
+
3
+ module Xcake
4
+ # This class handles classifing the files and how Xcake should handle them.
5
+ #
6
+ class PathClassifier
7
+ EXTENSION_MAPPINGS = {
8
+ PBXFrameworksBuildPhase: %w{.a .dylib .so .framework}.freeze,
9
+ PBXHeadersBuildPhase: %w{.h .hpp}.freeze,
10
+ PBXSourcesBuildPhase: %w{.c .m .mm .cpp .swift .xcdatamodeld}.freeze,
11
+ PBXResourcesBuildPhase: %w{.xcassets}.freeze
12
+ }.freeze
13
+
14
+ # @note This should be overidden
15
+ # by subclasses.
16
+ #
17
+ # @param [String] the path
18
+ #
19
+ # @return [Boolean] true if classifier thinks the path should be included
20
+ # into the project
21
+ #
22
+ def self.should_include_path?(path)
23
+ return false if is_locale_container?(path)
24
+ return false if is_inside_classified_container?(path)
25
+ true
26
+ end
27
+
28
+ def self.classification_for_path(path)
29
+ classification = EXTENSION_MAPPINGS.detect do |_key, ext_group|
30
+ ext_group.any? {|ext| File.extname(path) == ext}
31
+ end
32
+
33
+ return :PBXResourcesBuildPhase if classification.nil?
34
+ classification.first
35
+ end
36
+
37
+ def self.should_create_build_phase_for_classification?(classification)
38
+ classification != :PBXHeadersBuildPhase
39
+ end
40
+
41
+ private_class_method
42
+
43
+ def self.is_locale_container?(path)
44
+ components = path.split('/')
45
+ File.extname(components.last) == '.lproj'
46
+ end
47
+
48
+ def self.is_inside_classified_container?(path)
49
+ components = path.split('/')
50
+
51
+ classified_component_index = components.index do |c|
52
+ is_classified?(c)
53
+ end
54
+
55
+ if !classified_component_index.nil?
56
+ classified_component_index < (components.length - 1)
57
+ else
58
+ false
59
+ end
60
+ end
61
+
62
+ def self.is_classified?(path)
63
+ EXTENSION_MAPPINGS.values.flatten.any? { |ext| File.extname(path) == ext }
64
+ end
65
+ end
66
+ end
@@ -74,6 +74,32 @@ module Xcake
74
74
  end
75
75
  end
76
76
 
77
+ # Defines a extension target.
78
+ #
79
+ # @param [Target] host target
80
+ # host target for which the extension is for.
81
+ #
82
+ # @param [Proc] block
83
+ # an optional block that configures the target through the DSL.
84
+ #
85
+ # @return [Target] the extension target
86
+ # the newly created extension target
87
+ #
88
+ def extension_for(host_target)
89
+ target = target do |t|
90
+ t.type = :app_extension
91
+ t.platform = host_target.platform
92
+ t.deployment_target = host_target.deployment_target
93
+ t.language = host_target.language
94
+ end
95
+
96
+ host_target.target_dependencies << target
97
+
98
+ yield(target) if block_given?
99
+
100
+ target
101
+ end
102
+
77
103
  # Defines targets for watch app.
78
104
  #
79
105
  # @param [Target] watch app's compantion app
data/lib/xcake/project.rb CHANGED
@@ -65,7 +65,6 @@ module Xcake
65
65
  #
66
66
  def target(&block)
67
67
  target = Target.new(project, &block)
68
-
69
68
  targets << target
70
69
  target
71
70
  end
@@ -0,0 +1,38 @@
1
+ module Xcake
2
+ class Target
3
+ def parent_configurable
4
+ @project
5
+ end
6
+
7
+ # TODO: Move this to a constant, maybe Xcodeproj ones should be brought
8
+ # into here?
9
+ #
10
+ # Perhaps these could be made into a Gem itself?
11
+ def default_settings
12
+ {
13
+ 'INFOPLIST_FILE' => "#{name}/Supporting Files/Info.plist"
14
+ }
15
+ end
16
+
17
+ def default_debug_settings
18
+ Xcodeproj::Project::ProjectHelper
19
+ .common_build_settings(:debug,
20
+ platform,
21
+ deployment_target.to_s,
22
+ type,
23
+ language)
24
+ .merge!(default_settings)
25
+ .merge('SWIFT_OPTIMIZATION_LEVEL' => '-Onone')
26
+ end
27
+
28
+ def default_release_settings
29
+ Xcodeproj::Project::ProjectHelper
30
+ .common_build_settings(:release,
31
+ platform,
32
+ deployment_target.to_s,
33
+ type,
34
+ language)
35
+ .merge!(default_settings)
36
+ end
37
+ end
38
+ end
data/lib/xcake/target.rb CHANGED
@@ -224,44 +224,5 @@ module Xcake
224
224
  abort 'Platform not supported!'
225
225
  end
226
226
  end
227
-
228
- # Configurable
229
-
230
- def parent_configurable
231
- @project
232
- end
233
-
234
- # TODO: Move this to a constant, maybe Xcodeproj ones should be brought
235
- # into here?
236
- #
237
- # Perhaps these could be made into a Gem itself?
238
- def default_settings
239
- {
240
- 'INFOPLIST_FILE' => "#{name}/Supporting Files/Info.plist"
241
- }
242
- end
243
-
244
- def default_debug_settings
245
- Xcodeproj::Project::ProjectHelper
246
- .common_build_settings(:debug,
247
- platform,
248
- deployment_target.to_s,
249
- type,
250
- language)
251
- .merge!(default_settings)
252
- .merge({
253
- 'SWIFT_OPTIMIZATION_LEVEL' => '-Onone'
254
- })
255
- end
256
-
257
- def default_release_settings
258
- Xcodeproj::Project::ProjectHelper
259
- .common_build_settings(:release,
260
- platform,
261
- deployment_target.to_s,
262
- type,
263
- language)
264
- .merge!(default_settings)
265
- end
266
227
  end
267
228
  end
data/lib/xcake/ui.rb CHANGED
@@ -6,8 +6,7 @@ require 'cork'
6
6
  module Xcake
7
7
  class UI
8
8
  def self.register_ui_hooks
9
-
10
- board = Cork::Board.new()
9
+ board = Cork::Board.new
11
10
 
12
11
  EventHooks.after_cakefile_init do
13
12
  board.notice 'Open Cakefile to edit and run xcake make to get your xcode project'
@@ -26,7 +25,7 @@ module Xcake
26
25
  end
27
26
 
28
27
  EventHooks.before_resolving_project_structure do
29
- board.puts_indented "- Resolving Project"
28
+ board.puts_indented '- Resolving Project'
30
29
  end
31
30
 
32
31
  EventHooks.before_resolving_target_structure do |target|
data/lib/xcake/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Xcake
2
- VERSION = '0.6.25'.freeze
2
+ VERSION = '0.7.0'.freeze
3
3
  end
@@ -114,66 +114,58 @@ module Xcake
114
114
  new(Xcodeproj::Project::Object::XCBuildConfiguration)
115
115
  end
116
116
 
117
- # Creates a new xcode group from the node
118
- #
119
- # @param [Node] node
120
- # configuration DSL to create target from
121
- #
122
- # @return [Group] new xcode group
123
- #
117
+ # Creates a new xcode file reference from the node
124
118
  #
125
- # TODO: Simplify this method figure out more reliable rules for group
126
- # generation - maybe part of the new file installer in 0.7.
119
+ # @param [Pathname] path
120
+ # => path of the file reference from the source root
127
121
  #
128
- # As well as variant groups and other types of groups.
122
+ # @return [PBXFileReference] new xcode file refrence
129
123
  #
130
- def new_group(node)
124
+ def file_reference_for_path(path)
125
+ group = group_for_file_reference_path(path)
126
+ group_path = Pathname.new group.dirname
131
127
 
132
- parent = node.parent
133
- return main_group unless parent
128
+ file_path = path.cleanpath.relative_path_from group_path
129
+ group.new_reference(file_path.to_s)
130
+ end
134
131
 
135
- if parent.component.include?(".lproj")
132
+ def group_for_file_reference_path(path)
133
+ clean_path = path.cleanpath
134
+ group = variant_group_for_path(path)
135
+ group = group_for_path(path) unless group
136
+ group
137
+ end
136
138
 
137
- group = main_group.find_subpath(parent.parent.path, true) unless group
139
+ private
138
140
 
139
- variant_group = group[node.component]
141
+ def variant_group_for_path(path)
142
+ group_path = path.dirname.cleanpath
143
+ base_name = group_path.basename
140
144
 
141
- unless variant_group
142
- variant_group = group.project.new(PBXVariantGroup)
143
- variant_group.name = node.component
144
- variant_group.set_source_tree(:group)
145
- group.children << variant_group
146
- end
145
+ return nil unless base_name.to_s.include?('.lproj')
146
+ parent_group = group_for_path(group_path)
147
147
 
148
- ensure_parent_path(group, parent.parent)
149
- group = variant_group
150
- else
151
- group = main_group.find_subpath(parent.path, true) unless group
152
- ensure_parent_path(group, parent)
148
+ group = parent_group[path.basename.to_s]
149
+
150
+ unless group
151
+ group = new(PBXVariantGroup)
152
+ group.name = path.basename.to_s
153
+ group.set_source_tree(:group)
154
+ parent_group.children << group
153
155
  end
154
156
 
155
157
  group
156
158
  end
157
159
 
158
- # Creates a new xcode file reference from the node
159
- #
160
- # @param [String] path
161
- # => path of the file reference from the source root
162
- #
163
- # @return [PBXFileReference] new xcode file refrence
164
- #
165
- def new_file_reference(path)
166
- path_object = Pathname.new(path)
167
- group = main_group.find_subpath(path_object.dirname.to_s, true)
168
- group[path_object.basename.to_s] ||
169
- group.new_reference(path_object.to_s)
170
- end
160
+ def group_for_path(path)
161
+ group_path = path.dirname.cleanpath
171
162
 
172
- def ensure_parent_path(group, node)
173
- group.path = node.component
174
- ensure_parent_path(group.parent, node.parent) unless node.parent.nil?
163
+ return main_group unless group_path.to_s != '.'
164
+ main_group.child_for_path(group_path.to_s)
175
165
  end
176
166
 
167
+ public
168
+
177
169
  # Finds a unit test target for a xcode target
178
170
  #
179
171
  # @param [Target] target
@@ -0,0 +1,41 @@
1
+ require 'Xcodeproj'
2
+
3
+ module Xcodeproj
4
+ class Project
5
+ module Object
6
+ class PBXGroup
7
+ def child_for_path(path)
8
+ path = path.split('/').keep_if do |c|
9
+ c != '.'
10
+ end unless path.is_a?(Array)
11
+
12
+ child_name = path.shift
13
+ child = children.find { |c| c.display_name == child_name }
14
+
15
+ if child.nil?
16
+ child = new_group(child_name)
17
+ child.path = child_name
18
+ end
19
+
20
+ if path.empty?
21
+ child
22
+ else
23
+ child.child_for_path(path)
24
+ end
25
+ end
26
+
27
+ def dirname
28
+ return "." if parent.is_a? Xcake::Xcode::Project
29
+ return "." if parent.is_a? PBXProject
30
+ return parent.dirname.to_s if is_a? PBXVariantGroup
31
+
32
+ if display_name
33
+ "#{parent.dirname.to_s}/#{display_name}"
34
+ else
35
+ parent.dirname.to_s
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ require 'xcodeproj'
2
+
3
+ module Xcodeproj
4
+ class Project
5
+ module Object
6
+ class PBXNativeTarget
7
+ #TODO: BDD
8
+ def build_phase_by_class(phase_class)
9
+ find_or_create_build_phase_by_class(phase_class)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/xcake.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'xcake/core_ext/array'
2
2
  require 'xcake/core_ext/object'
3
3
  require 'xcake/core_ext/string'
4
+ require 'xcake/xcodeproj_ext/PBXGroup'
5
+ require 'xcake/xcodeproj_ext/PBXNativeTarget'
4
6
  require 'xcake/modern_xcodeproj.rb'
5
7
 
6
8
  require 'xcake/version'
@@ -15,6 +17,7 @@ require 'xcake/plugin'
15
17
  require 'xcake/visitable'
16
18
  require 'xcake/visitor'
17
19
  require 'xcake/generator'
20
+
18
21
  require 'xcake/context'
19
22
  require 'xcake/context/xcodeproj_context'
20
23
 
@@ -26,11 +29,12 @@ require 'xcake/configurable'
26
29
  require 'xcake/project'
27
30
  require 'xcake/project/sugar'
28
31
  require 'xcake/project/hooks'
29
- require 'xcake/file_reference_installer'
30
- require 'xcake/node'
32
+ require 'xcake/path_classifier'
31
33
  require 'xcake/shell_script_build_phase'
34
+
32
35
  require 'xcake/target'
33
36
  require 'xcake/target/sugar'
37
+ require 'xcake/target/configurable'
34
38
 
35
39
  require 'xcake/xcode/project'
36
40
  require 'xcake/xcode/scheme'
data/xcake.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.executables = %w( xcake )
19
+ spec.executables = %w(xcake)
20
20
  spec.require_paths = ['lib']
21
21
 
22
22
  spec.required_ruby_version = '>= 2.0.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.25
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Campbell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-07 00:00:00.000000000 Z
11
+ date: 2016-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -210,15 +210,13 @@ files:
210
210
  - LICENSE.txt
211
211
  - README.md
212
212
  - Rakefile
213
- - _hound.yml
214
- - _rubocop.yml
215
- - _rubocop_general.yml
216
213
  - bin/console
217
214
  - bin/setup
218
215
  - bin/xcake
219
216
  - docs/Cakefile.md
220
217
  - docs/Getting Started.md
221
218
  - docs/Hooks.md
219
+ - docs/Sample/Cakefile
222
220
  - docs/Xcode Project Support.md
223
221
  - fastlane-plugin-xcake/Gemfile
224
222
  - fastlane-plugin-xcake/LICENSE
@@ -229,6 +227,7 @@ files:
229
227
  - fastlane-plugin-xcake/lib/fastlane/plugin/xcake/actions/xcake_action.rb
230
228
  - fastlane-plugin-xcake/lib/fastlane/plugin/xcake/version.rb
231
229
  - fastlane-plugin-xcake/spec/spec_helper.rb
230
+ - hound.yml
232
231
  - lib/xcake.rb
233
232
  - lib/xcake/command.rb
234
233
  - lib/xcake/command/init.rb
@@ -245,13 +244,6 @@ files:
245
244
  - lib/xcake/dependency.rb
246
245
  - lib/xcake/dependency_provider.rb
247
246
  - lib/xcake/event_hooks.rb
248
- - lib/xcake/file_reference_installer.rb
249
- - lib/xcake/file_reference_installer/compile_source_file_reference_installer.rb
250
- - lib/xcake/file_reference_installer/compile_xcdatamodeld_file_reference_installer.rb
251
- - lib/xcake/file_reference_installer/copy_resources_file_reference_installer.rb
252
- - lib/xcake/file_reference_installer/copy_xcassets_file_reference_installer.rb
253
- - lib/xcake/file_reference_installer/header_file_reference_installer.rb
254
- - lib/xcake/file_reference_installer/link_library_file_reference_installer.rb
255
247
  - lib/xcake/generator.rb
256
248
  - lib/xcake/generator/configuration_generator.rb
257
249
  - lib/xcake/generator/project_generator.rb
@@ -267,7 +259,7 @@ files:
267
259
  - lib/xcake/generator/target_library_generator.rb
268
260
  - lib/xcake/informative.rb
269
261
  - lib/xcake/modern_xcodeproj.rb
270
- - lib/xcake/node.rb
262
+ - lib/xcake/path_classifier.rb
271
263
  - lib/xcake/plugin.rb
272
264
  - lib/xcake/project.rb
273
265
  - lib/xcake/project/hooks.rb
@@ -275,6 +267,7 @@ files:
275
267
  - lib/xcake/resources/Cakefile
276
268
  - lib/xcake/shell_script_build_phase.rb
277
269
  - lib/xcake/target.rb
270
+ - lib/xcake/target/configurable.rb
278
271
  - lib/xcake/target/sugar.rb
279
272
  - lib/xcake/ui.rb
280
273
  - lib/xcake/version.rb
@@ -283,6 +276,10 @@ files:
283
276
  - lib/xcake/xcode/project.rb
284
277
  - lib/xcake/xcode/scheme.rb
285
278
  - lib/xcake/xcode/scheme_list.rb
279
+ - lib/xcake/xcodeproj_ext/PBXGroup.rb
280
+ - lib/xcake/xcodeproj_ext/PBXNativeTarget.rb
281
+ - rubocop.yml
282
+ - rubocop_general.yml
286
283
  - xcake.gemspec
287
284
  homepage: https://github.com/jcampbell05/xcake/
288
285
  licenses:
@@ -309,4 +306,3 @@ signing_key:
309
306
  specification_version: 4
310
307
  summary: DSL for Xcode Projects.
311
308
  test_files: []
312
- has_rdoc:
@@ -1,15 +0,0 @@
1
- module Xcake
2
- # This build phase generator detects source
3
- # files and adds them to the compile build phase.
4
- #
5
- class CompileSourceFileReferenceInstaller < FileReferenceInstaller
6
- def self.can_install_node(node)
7
- !File.directory?(node.path) &&
8
- %w(.c .m .mm .cpp .swift).include?(File.extname(node.path))
9
- end
10
-
11
- def add_file_reference_to_target(file_reference, target)
12
- target.source_build_phase.add_file_reference(file_reference, true)
13
- end
14
- end
15
- end
@@ -1,22 +0,0 @@
1
- module Xcake
2
- # This build phase generator detects XCDataModeld bundles
3
- # and adds them to the compile source phase.
4
- #
5
- class CompileXCDataModeldFileReferenceInstaller < CompileSourceFileReferenceInstaller
6
- def self.dependencies
7
- []
8
- end
9
-
10
- def self.can_install_node(node)
11
- File.directory?(node.path) &&
12
- ['.xcdatamodeld'].include?(File.extname(node.path))
13
- end
14
-
15
- def visit_node(node)
16
- super
17
-
18
- # Ignore all files inside of the XCDataModel
19
- node.children = []
20
- end
21
- end
22
- end
@@ -1,25 +0,0 @@
1
- module Xcake
2
- # This build phase generator detects
3
- # files and adds them to the copy resources phase.
4
- #
5
- # Note: This installer is always the last to be executed.
6
- class CopyResourcesFileReferenceInstaller < FileReferenceInstaller
7
- def self.dependencies
8
- FileReferenceInstaller.descendants.select do |i|
9
- i != self
10
- end
11
- end
12
-
13
- def self.can_install_node(node)
14
- extension = File.extname(node.path)
15
- (!File.directory?(node.path) ||
16
- (File.directory?(node.path) &&
17
- !['.xcassets', '.xcdatamodeld', '.lproj'].include?(extension) &&
18
- node.children.count == 0))
19
- end
20
-
21
- def add_file_reference_to_target(file_reference, target)
22
- target.resources_build_phase.add_file_reference(file_reference, true)
23
- end
24
- end
25
- end
@@ -1,22 +0,0 @@
1
- module Xcake
2
- # This build phase generator detects XCAsset bundles
3
- # and adds them to the copy resources phase.
4
- #
5
- class CopyXCAssetsFileReferenceInstaller < CopyResourcesFileReferenceInstaller
6
- def self.dependencies
7
- []
8
- end
9
-
10
- def self.can_install_node(node)
11
- File.directory?(node.path) &&
12
- ['.xcassets'].include?(File.extname(node.path))
13
- end
14
-
15
- def visit_node(node)
16
- super
17
-
18
- # Ignore all files inside of the XCAssets
19
- node.children = []
20
- end
21
- end
22
- end
@@ -1,11 +0,0 @@
1
- module Xcake
2
- class HeaderFileReferenceInstaller < FileReferenceInstaller
3
- # This build phase generator detects header files
4
- # and ignores them.
5
- #
6
- def self.can_install_node(node)
7
- !File.directory?(node.path) &&
8
- %w(.h .hpp).include?(File.extname(node.path))
9
- end
10
- end
11
- end
@@ -1,21 +0,0 @@
1
- module Xcake
2
- # This build phase generator detects library
3
- # files and adds them to the frameworks build phase.
4
- #
5
- class LinkLibraryFileReferenceInstaller < FileReferenceInstaller
6
- def self.can_install_node(node)
7
- %w(.a .dylib .so .framework).include?(File.extname(node.path))
8
- end
9
-
10
- def add_file_reference_to_target(file_reference, target)
11
- target.frameworks_build_phases.add_file_reference(file_reference, true)
12
- end
13
-
14
- def visit_node(node)
15
- super
16
-
17
- # Ignore all files inside of libraries
18
- node.children = []
19
- end
20
- end
21
- end