class Xcake::Target
This class is used to describe a target for a Xcode
project; This forms part of the DSL and is usually stored in files named ‘Cakefile`.
Attributes
@return [Array<BuildPhase>] the list
of build phases for the project.
@return [Array<BuildRule>] the list
of build rules for the project.
@return [String] the minimum deployment version
for the target's platform.
@return [Array or String] files to exclude for the target.
Supports regular expressions
@example
spec.exclude_files = ["Classes/**/unused.{h,m}"]
@return [Array or String] files to include for the target.
Supports regular expressions, Defaults to: ["./<Target Name>/*\*/\*.*"]
@note Xcake
defaults to including files in the folder with the same name as
the targt
@example
spec.include_files = "Classes/**/*.{h,m}"
@return [String] the language for the target.
Can be `:objc`, `:swift`.
@return [Array<Target>] targets to link to, use this
when you want to use a library or framework target in another target
@return [String] the name of the target.
@return [Array<BuildPhase>] the list
of build phases to place first for the project.
@return [String] the platform for the target.
Can be `:ios`, `:osx`, `:tvos`, `:watchos`.
@return [Array<Scheme>] schemes for the target
@return [Array<String>] system frameworks to include for the target
Defaults to: - ["Foundation", "UIKit"] for iOS - ["Cocoa"] for OSX
@example
spec.system_frameworks = ["Foundation"]
@return [Array<String>] system libraries to include for the target
@example
spec.system_libraries = ["z", "sqlite3"]
@return [Array<Target>] targets to use as dependencies
@return [String] the type of the target.
Can be `:application`, `:dynamic_library`, `framework` or `:static_library`.
Public Class Methods
@param [Project] project
the project the target belongs to.
@param [Proc] block
an optional block that configures the target through the DSL.
@example Creating a Target
.
Target.new(project) do |t| t.name "test" end
# File lib/xcake/dsl/target.rb, line 197 def initialize(project) @pinned_build_phases = [] @build_phases = [] @build_rules = [] @exclude_files = [] @linked_targets = [] @system_libraries = [] @target_dependencies = [] @schemes = [] @project = project yield(self) if block_given? end
Public Instance Methods
Creates a new build rule for the target
@param [String] name
the name to use for the build rule
@param [Proc] block
an optional block that configures the build rule through the DSL.
@return [BuildRule] the new xcode build rule
# File lib/xcake/dsl/target/sugar.rb, line 86 def build_rule(name, file_type, output_files, output_files_compiler_flags, script, &block) rule = BuildRule.new(&block) rule.name = name rule.file_type = file_type rule.output_files = output_files rule.output_files_compiler_flags = output_files_compiler_flags rule.script = script build_rules << rule rule end
Creates a new Copy Files build phase for the target
@param [String] name
the name to use for the build phase
@param [Proc] block
an optional block that configures the build phase through the DSL.
@return [CopyFilesBuildPhase] the new xcode build phase
# File lib/xcake/dsl/target/sugar.rb, line 16 def copy_files_build_phase(name, &block) phase = CopyFilesBuildPhase.new(&block) phase.name = name build_phases << phase phase end
# File lib/xcake/dsl/target/configurable.rb, line 13 def default_debug_settings Xcake::Constants .common_build_settings(:debug, platform, deployment_target.to_s, type, language) .merge!(default_settings) .merge('SWIFT_OPTIMIZATION_LEVEL' => '-Onone') end
# File lib/xcake/dsl/target/configurable.rb, line 24 def default_release_settings Xcake::Constants .common_build_settings(:release, platform, deployment_target.to_s, type, language) .merge!(default_settings) end
# File lib/xcake/dsl/target/configurable.rb, line 7 def default_settings { 'INFOPLIST_FILE' => "#{name}/Supporting Files/Info.plist" } end
Creates a new Copy Headers build phase for the target
@param [Proc] block
an optional block that configures the build phase through the DSL.
@return [HeadersBuildPhase] the new xcode build phase
# File lib/xcake/dsl/target/sugar.rb, line 31 def headers_build_phase(&block) phase = HeadersBuildPhase.new(&block) build_phases << phase phase end
@!group getters
# File lib/xcake/dsl/target.rb, line 229 def include_files # Import files in folder with same name as target by default @include_files ||= ["./#{@name}/**/*.*"] end
# File lib/xcake/dsl/target.rb, line 239 def info_plist_paths all_configurations.map { |config| config.settings['INFOPLIST_FILE'] }.uniq end
# File lib/xcake/dsl/target/configurable.rb, line 3 def parent_configurable @project end
Creates a new Shell Script build phase for the target before all of the other build phases
@param [String] name
the name to use for the build phase
@param [Proc] block
an optional block that configures the build phase through the DSL.
@return [ShellScriptBuildPhase] the new xcode build phase
# File lib/xcake/dsl/target/sugar.rb, line 48 def pre_shell_script_build_phase(name, script, &block) phase = ShellScriptBuildPhase.new(&block) phase.name = name phase.script = script pinned_build_phases << phase phase end
Creates a new scheme for the target
@param [String] name
the name of the new scheme
@return [Scheme] the scheme
the newly created scheme
# File lib/xcake/dsl/target.rb, line 221 def scheme(name, &block) scheme = Scheme.new(name, &block) schemes << scheme scheme end
Creates a new Shell Script build phase for the target
@param [String] name
the name to use for the build phase
@param [Proc] block
an optional block that configures the build phase through the DSL.
@return [ShellScriptBuildPhase] the new xcode build phase
# File lib/xcake/dsl/target/sugar.rb, line 67 def shell_script_build_phase(name, script, &block) phase = ShellScriptBuildPhase.new(&block) phase.name = name phase.script = script build_phases << phase phase end
# File lib/xcake/dsl/target.rb, line 234 def system_frameworks # Use default frameworks by default @system_frameworks ||= default_system_frameworks_for(platform) end
@!group Conversion
# File lib/xcake/dsl/target.rb, line 245 def to_s "Target<#{name}>" end
Protected Instance Methods
Returns an array of default system frameworks to use for a given platform.
@param [Symbol] platform
platform the frameworks are for.
@return [Array<String>] system frameworks to use
# File lib/xcake/dsl/target.rb, line 260 def default_system_frameworks_for(platform) case platform when :ios %w(Foundation UIKit) when :osx %w(Cocoa) when :tvos %w(Foundation UIKit) when :watchos %w(Foundation UIKit WatchKit) else abort 'Platform not supported!' end end