Skip to content

Commit

Permalink
Fork update (#1)
Browse files Browse the repository at this point in the history
* fix bundler-gate build error

* fix bundler-gate build error

* add shell script input/output paths (igor-makarov#195)

* bump version

* Disable Xcodeproj diffing in integration tests as it doesn't work (igor-makarov#199)

This PR fixes nightly builds failing on Xcodeproj egde version, as it changes some base constants to new version.

As I can't actually account for that, I had to disable Xcodeproj diffing.

* Travis grooming (igor-makarov#200)

* don't build on ruby 2.0.0 + add linux

* disable xcodebuild integration test on Linux

* add LINT task

* pin rubocop version

* Add `before_save` hook (igor-makarov#201)

* add `before_save` hook

* add test for `before_hook`

* bump version to 0.9.2

* bump rake dependency to silence security warning (igor-makarov#202)

* fix inherit configuration logic (igor-makarov#212)

* bump version to 0.9.3

* Update documentation on build phases (igor-makarov#209)

* Update documentation on build phases

* Improve description and example code per review

Co-authored-by: Igor Makarov <igormaka@gmail.com>
Co-authored-by: Patrick <patrickuijpers@gmail.com>
  • Loading branch information
3 people authored Jul 1, 2020
1 parent 2e7116b commit fde0dbf
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 22 deletions.
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
os:
os:
- osx
- linux
language: ruby
install: true

env:
- |
Expand All @@ -11,9 +13,18 @@ gemfile:
- gemfiles/Gemfile.xcodeproj-edge
rvm:
- 2.5.0
- ruby-2.0.0-p648
- 2.6.0
- 2.7.0

matrix:
include:
- rvm: 2.7.0
os: linux
env: XCAKE_CI_TASKS=LINT

before_script:
- gem install bundler -v "~> 1.17"
- bundle install --jobs=3
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-darwin-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter

Expand Down
23 changes: 20 additions & 3 deletions docs/Cakefile.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,32 @@ end

##### Shell Script Build Phase

You can create a Shell Script buld phase to run a script when building.
You can create a Shell Script build phase to run a script when building.
The following creates a simple script printing `Hello World`:

```ruby
target.shell_script_build_phase "Build Phase Name", <<-SCRIPT
echo "Hello World"
target.shell_script_build_phase "Build Phase Name", "echo 'Hello World'"
end
```

You can optionally define input- and output (file list) paths, combinbed with a multi-line script, like this:

```ruby
myScript = <<-SCRIPT
echo "This is a multi-line script"
echo "Hello World"
SCRIPT
target.shell_script_build_phase "Build Phase Name", myScript do |phase|
phase.input_paths = ["$(SRCROOT)/$(TARGET_NAME)/**/*.txt"]
phase.output_paths = ["$(SRCROOT)/$(TARGET_NAME)/OutputFiles/MyFile.txt"]
phase.input_file_list_paths = ["$(SRCROOT)/$(TARGET_NAME)/**/*.xcfilelist"]
phase.output_file_list_paths = ["$(SRCROOT)/$(TARGET_NAME)/OutputFiles/MyFileList.xcfilelist"]
end
```

Note: to move the build phase before all other build phases (right before the `Compile Sources` phase), use `target.pre_shell_script_build_phase` instead.


## Configurations

Xcake allows you define a hierarchy of build configuations like you would in Xcode
Expand Down
10 changes: 10 additions & 0 deletions lib/xcake/dsl/build_phase/shell_script_build_phase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@ class ShellScriptBuildPhase < BuildPhase
# String coataining the contents of the script to run
attr_accessor :script

# input/output paths
attr_accessor :input_paths
attr_accessor :output_paths
attr_accessor :input_file_list_paths
attr_accessor :output_file_list_paths

def build_phase_type
Xcodeproj::Project::Object::PBXShellScriptBuildPhase
end

def configure_native_build_phase(native_build_phase, _context)
native_build_phase.name = name
native_build_phase.shell_script = script.strip_heredoc
native_build_phase.input_paths = input_paths || []
native_build_phase.output_paths = output_paths || []
native_build_phase.input_file_list_paths = input_file_list_paths || []
native_build_phase.output_file_list_paths = output_file_list_paths || []
end

def to_s
Expand Down
2 changes: 1 addition & 1 deletion lib/xcake/dsl/configuration/sugar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Configuration
#
# @example Using Supported Devices
#
# Target.new do |t|
# Target.new(project) do |t|
# t.all_configurations.each do |c|
# c.supported_devices = :ipad_only
# end
Expand Down
2 changes: 1 addition & 1 deletion lib/xcake/dsl/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def initialize(name = 'Project')
# the newly created target
#
def target(&block)
target = Target.new(&block)
target = Target.new(self, &block)
targets << target
target
end
Expand Down
4 changes: 4 additions & 0 deletions lib/xcake/dsl/project/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class Project
include Hooks
include Hooks::InstanceHooks

# Defines hook which is ran before project is saved.
#
define_hooks :before_save

# Defines hook which is ran after project is saved.
#
define_hooks :after_save
Expand Down
8 changes: 6 additions & 2 deletions lib/xcake/dsl/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,19 @@ class Target
#
attr_accessor :schemes

# @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 do |t|
# Target.new(project) do |t|
# t.name "test"
# end
#
def initialize
def initialize(project)
@pinned_build_phases = []
@build_phases = []
@build_rules = []
Expand All @@ -200,6 +203,7 @@ def initialize
@system_libraries = []
@target_dependencies = []
@schemes = []
@project = project

yield(self) if block_given?
end
Expand Down
1 change: 1 addition & 0 deletions lib/xcake/generator/project_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def self.dependencies

def leave_project(project)
native_project = @context.native_object_for(project)
project.run_hook :before_save, native_project
native_project.save
project.run_hook :after_save

Expand Down
2 changes: 1 addition & 1 deletion lib/xcake/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Xcake
VERSION = '0.9.0'.freeze
VERSION = '0.9.3'.freeze
end
33 changes: 33 additions & 0 deletions spec/dsl/build_phase/shell_script_build_phase_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ module Xcake

allow(@native_build_phase).to receive(:name=)
allow(@native_build_phase).to receive(:shell_script=)

@paths = %w(path1 path2 path3 path4 path5).shuffle

allow(@native_build_phase).to receive(:input_paths=)
allow(@native_build_phase).to receive(:output_paths=)
allow(@native_build_phase).to receive(:input_file_list_paths=)
allow(@native_build_phase).to receive(:output_file_list_paths=)
end

it 'should use correct build phase type' do
Expand All @@ -30,5 +37,31 @@ module Xcake
expect(@native_build_phase).to receive(:shell_script=).with(@script.strip_heredoc)
@phase.configure_native_build_phase(@native_build_phase, nil)
end

context 'Input/Ouput paths' do
it 'should set input paths' do
@phase.input_paths = @paths
expect(@native_build_phase).to receive(:input_paths=).with(@paths)
@phase.configure_native_build_phase(@native_build_phase, nil)
end

it 'should set output paths' do
@phase.output_paths = @paths
expect(@native_build_phase).to receive(:output_paths=).with(@paths)
@phase.configure_native_build_phase(@native_build_phase, nil)
end

it 'should set input file list paths' do
@phase.input_file_list_paths = @paths
expect(@native_build_phase).to receive(:input_file_list_paths=).with(@paths)
@phase.configure_native_build_phase(@native_build_phase, nil)
end

it 'should set output file list paths' do
@phase.output_file_list_paths = @paths
expect(@native_build_phase).to receive(:output_file_list_paths=).with(@paths)
@phase.configure_native_build_phase(@native_build_phase, nil)
end
end
end
end
3 changes: 2 additions & 1 deletion spec/dsl/target/sugar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
module Xcake
describe Target do
before :each do
@target = Target.new
@project = Project.new
@target = Target.new(@project)
@build_phase_name = 'Hello World'
end

Expand Down
9 changes: 8 additions & 1 deletion spec/dsl/target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
module Xcake
describe Target do
before :each do
@target = Target.new
@project = Project.new
@target = Target.new(@project)
@target.name = 'Test'
end

Expand Down Expand Up @@ -116,6 +117,12 @@ module Xcake
expect(@target.default_release_settings).to eq(settings)
end

it 'should inherit settings' do
@project.debug_configuration :Test
expect(@target.all_configurations.count).to eq(1)
expect(@target.all_configurations.first.name).to eq('Test')
end

it 'should initialize schemes' do
expect(@target.schemes).not_to be(nil)
end
Expand Down
5 changes: 5 additions & 0 deletions spec/generator/project_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ module Xcake
@generator.leave_project(@dsl_project)
end

it 'should run the before save hook' do
expect(@dsl_project).to receive(:run_hook).with(:before_save, @project)
@generator.leave_project(@dsl_project)
end

it 'should run the after save hook' do
expect(@dsl_project).to receive(:run_hook).with(:after_save)
@generator.leave_project(@dsl_project)
Expand Down
19 changes: 11 additions & 8 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'spec_helper'
require 'yaml'
require 'simplecov'
require 'os'

SimpleCov.command_name 'test:integration'

Expand Down Expand Up @@ -59,17 +60,19 @@ def self.list_files(directory)
Dir.chdir(fixture) do
Xcake.make_helper
expect(Dir['temp/*.xcodeproj']).to eq(%w(temp/Project.xcodeproj))
expected_proj = Xcodeproj::Project.open('output/Project.xcodeproj')
expect(Xcodeproj::Project.open('temp/Project.xcodeproj')).to eq_project(expected_proj)
end
end
it 'Should build fixture with xcodebuild with no errors' do
Dir.chdir(fixture) do
Xcake.make_helper
Dir.chdir('temp') do
expect('xcodebuild clean build -sdk iphonesimulator &> xcode_output.txt').to succeed

# this cannot be tested on any OS other than macOS
if OS.mac?
it 'Should build fixture with xcodebuild with no errors' do
Dir.chdir(fixture) do
Xcake.make_helper
Dir.chdir('temp') do
expect('xcodebuild clean build -sdk iphonesimulator &> xcode_output.txt').to succeed
end
expect(Xcake.list_files('temp')).to include(*Xcake.list_files('output'))
end
expect(Xcake.list_files('temp')).to include(*Xcake.list_files('output'))
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions xcake.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
# Lock `activesupport` (transitive dependency via `xcodeproj`) to keep supporting system ruby
spec.add_dependency 'activesupport', '< 5'

spec.add_development_dependency 'bundler', '~> 1.10'
spec.add_development_dependency 'bundler', '>= 1.10'
spec.add_development_dependency 'os', '~> 1.0'
spec.add_development_dependency 'pry', '~> 0.10'
spec.add_development_dependency 'pry-rescue'
spec.add_development_dependency 'pry-stack_explorer'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rake', '~> 12.0'
spec.add_development_dependency 'rb-readline', '~> 0.5.4'
spec.add_development_dependency 'rspec', '~> 3.4.0'
spec.add_development_dependency 'rubocop', '~> 0.64.0'
spec.add_development_dependency 'rubocop-git', '~> 0.1.1'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down

0 comments on commit fde0dbf

Please sign in to comment.