Skip to content

Commit

Permalink
New File Reference Generator. (#95)
Browse files Browse the repository at this point in the history
* Preparing for new system.

* Preparing new system.

* Old system working.

* Fixes wrong groups created.

* Fix multiple variants being created.

* Tweaks to add new method to get dirname.

* Remove node since we don't use it.

* Extra steps.

* Updates Changelog.md.

* Target File Generator Fully Speced.

* Configuration generator tests passing.

* Context tested.

* Implemented basic file reference test.

* Fixes test for main group.

* Tests pass.

* Tests raw file.

* Group.

* Localized test..

* Verify tests.

* Test file reference.

* Preparing for group component tests.:

* File reference path done.

* Group tests.

* Dirname tested.

* All tests passing.

* Fix init.

* Preparing test.

* Initial test.

* Initial test.

* Specs running.

* Initial tests.

* Variant group test.

* All tests passing.

* Enable configs.
  • Loading branch information
jcampbell05 committed Jul 9, 2016
1 parent 1a62956 commit c4ca68b
Show file tree
Hide file tree
Showing 24 changed files with 349 additions and 527 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
Master
======
- Simplified Target File Reference Generator

v0.6.25
=======
- Fixed bug where Xcake would set incorrect path for a group of a Localized file.
Expand Down Expand Up @@ -117,6 +121,7 @@ v0.6.1
v0.6.0
======
- Infers build phases for the apple watch.
- Re-engineered generator infastructure.
- Fixes bug where configurations lacked a name when using shorthand syntax. (Thanks to @colinta).
- Adds support for custom script build phases (Thanks to @colinta).

Expand Down
2 changes: 1 addition & 1 deletion bin/xcake
Expand Up @@ -2,6 +2,6 @@

require 'xcake'

#TODO: Make UI and EventHooks DI-able
# TODO: Make UI and EventHooks DI-able
Xcake::UI.register_ui_hooks
Xcake::Command.run(ARGV)
File renamed without changes.
5 changes: 4 additions & 1 deletion lib/xcake.rb
@@ -1,6 +1,7 @@
require 'xcake/core_ext/array'
require 'xcake/core_ext/object'
require 'xcake/core_ext/string'
require 'xcake/xcodeproj_ext/PBXGroup'
require 'xcake/modern_xcodeproj.rb'

require 'xcake/version'
Expand All @@ -15,6 +16,7 @@
require 'xcake/visitable'
require 'xcake/visitor'
require 'xcake/generator'

require 'xcake/context'
require 'xcake/context/xcodeproj_context'

Expand All @@ -27,10 +29,11 @@
require 'xcake/project/sugar'
require 'xcake/project/hooks'
require 'xcake/file_reference_installer'
require 'xcake/node'
require 'xcake/shell_script_build_phase'

require 'xcake/target'
require 'xcake/target/sugar'
require 'xcake/target/configurable'

require 'xcake/xcode/project'
require 'xcake/xcode/scheme'
Expand Down
7 changes: 3 additions & 4 deletions lib/xcake/context/xcodeproj_context.rb
@@ -1,3 +1,4 @@
require 'pathname'
require 'xcodeproj'

module Xcake
Expand All @@ -16,13 +17,10 @@ def create_object_for(dsl_object)
create_object_for_configuration(dsl_object)
when Node
create_object_for_node(dsl_object)
else
nil
end
end

def create_object_for_project(project)
# TODO: Make setup of project testable
@project = Xcode::Project.new("./#{project.name}.xcodeproj", true)
@project.setup_for_xcake
@project
Expand All @@ -41,7 +39,8 @@ def create_object_for_node(node)
end

def file_reference_for_path(path)
@project.reference_for_path(path) || @project.new_file_reference(path)
pathname = Pathname.new path
@project.file_reference_for_path(pathname)
end
end
end
11 changes: 5 additions & 6 deletions lib/xcake/file_reference_installer.rb
Expand Up @@ -47,7 +47,6 @@ def add_file_reference_to_target(_file_reference, _target)
# @!group Visitable

def visit_node(node)

# Tweak this to respect localizable files
#
# If ".lproj" is in file path
Expand All @@ -62,11 +61,11 @@ def visit_node(node)
#
# TODO: Remove this duplication of the .lproj and node path code.
# Also remove need for the name hack.
if node.parent.component.include?(".lproj")
group_path = Pathname.new node.parent.parent.path
else
group_path = Pathname.new node.parent.path
end
group_path = if node.parent.component.include?('.lproj')
Pathname.new node.parent.parent.path
else
Pathname.new node.parent.path
end

file_path = Pathname.new node.path

Expand Down
2 changes: 1 addition & 1 deletion lib/xcake/generator/configuration_generator.rb
Expand Up @@ -6,7 +6,7 @@ module Xcake
#
class ConfigurationGenerator < Generator
def self.dependencies
[TargetGenerator, ProjectStructureGenerator, TargetFileReferenceGenerator]
[TargetGenerator, ProjectStructureGenerator]
end

def visit_project(project)
Expand Down
49 changes: 13 additions & 36 deletions lib/xcake/generator/target_file_reference_generator.rb
@@ -1,52 +1,29 @@
module Xcake
# This generator processes the files to add to the project from the
# `include_files` and `exclude_files`
#
class TargetFileReferenceGenerator < Generator
attr_accessor :root_node
attr_accessor :dependency_provider

def initialize(context)
@context = context
@root_node = Node.new

@dependency_provider = DependencyProvider.new(FileReferenceInstaller)
end

def self.dependencies
[TargetGenerator]
end

def process_files_for_target(target)
native_target = @context.native_object_for(target)

Dir.glob(target.include_files).each do |file|
@root_node.create_children_with_path(file, native_target)
end if target.include_files

Dir.glob(target.exclude_files).each do |file|
@root_node.remove_children_with_path(file, native_target)
end if target.exclude_files
end

def visit_project(project)
project.targets.each do |target|
process_files_for_target(target)
end

root_node.accept(self)
end
def visit_target(target)
# - References from Configurations
# - References from Build Phases
paths_to_include = Dir.glob(target.include_files)
paths_to_exclude = Dir.glob(target.exclude_files)
paths = paths_to_include - paths_to_exclude

def visit_node(node)
return unless node.path

EventHooks.run_hook :before_adding_file, node

installer_class = @dependency_provider.tsort.detect do |i|
i.can_install_node(node)
paths.each do |path|
@context.file_reference_for_path(path)
end

unless installer_class.nil?
installer = installer_class.new(context)
node.accept(installer)
end
# - Classify Files
# - Build Implicit Build Phases
end
end
end
2 changes: 1 addition & 1 deletion lib/xcake/informative.rb
@@ -1,6 +1,6 @@
require 'claide'

#TODO: Hook into UI Class somehow.
# TODO: Hook into UI Class somehow.
module Xcake
class Informative < StandardError
include CLAide::InformativeError
Expand Down
138 changes: 0 additions & 138 deletions lib/xcake/node.rb

This file was deleted.

39 changes: 0 additions & 39 deletions lib/xcake/target.rb
Expand Up @@ -224,44 +224,5 @@ def default_system_frameworks_for(platform)
abort 'Platform not supported!'
end
end

# Configurable

def parent_configurable
@project
end

# TODO: Move this to a constant, maybe Xcodeproj ones should be brought
# into here?
#
# Perhaps these could be made into a Gem itself?
def default_settings
{
'INFOPLIST_FILE' => "#{name}/Supporting Files/Info.plist"
}
end

def default_debug_settings
Xcodeproj::Project::ProjectHelper
.common_build_settings(:debug,
platform,
deployment_target.to_s,
type,
language)
.merge!(default_settings)
.merge({
'SWIFT_OPTIMIZATION_LEVEL' => '-Onone'
})
end

def default_release_settings
Xcodeproj::Project::ProjectHelper
.common_build_settings(:release,
platform,
deployment_target.to_s,
type,
language)
.merge!(default_settings)
end
end
end

0 comments on commit c4ca68b

Please sign in to comment.