From 511fad1ab6962cfa757283c2598f0d89bf48646b Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Thu, 1 Aug 2013 18:06:58 +0200 Subject: [PATCH 1/2] [Specification::DSL] Add prepare_command & deprecate hooks --- lib/cocoapods-core/specification/dsl.rb | 33 +++++++++++++++++++ lib/cocoapods-core/specification/linter.rb | 13 ++++++++ .../specification/root_attribute_accessors.rb | 4 +++ spec/specification/dsl_spec.rb | 4 +++ spec/specification/linter_spec.rb | 21 ++++++++++-- .../root_attribute_accessors_spec.rb | 5 +++ 6 files changed, 77 insertions(+), 3 deletions(-) diff --git a/lib/cocoapods-core/specification/dsl.rb b/lib/cocoapods-core/specification/dsl.rb index a6c218f87..71a6cfcfc 100644 --- a/lib/cocoapods-core/specification/dsl.rb +++ b/lib/cocoapods-core/specification/dsl.rb @@ -300,6 +300,33 @@ module DSL :container => Array, } + #------------------# + + # @!method prepare_command=(command) + # + # A command that will be executed after the Pod is downloaded. This + # command can be used to create or modify any file which be picked up + # by the other attributes of the specification. + # + # This command is executed before the Pod is cleaned and before the + # Pods project is created. + # + # @example + # + # spec.prepare_command = 'ruby build_files.rb' + # + # @example + # + # spec.prepare_command = <<-CMD + # sed -i 's/MyNameSpacedHeader/Header/g' ./**/*.h + # sed -i 's/MyNameOtherSpacedHeader/OtherHeader/g' ./**/*.h + # CMD + # + # @param [String] command + # the name of the pod. + # + root_attribute :prepare_command + #-----------------------------------------------------------------------# # @!group Platform @@ -985,6 +1012,9 @@ def dependency(*args) # end # def pre_install(&block) + CoreUI.warn "The pre install hook of the specification DSL has been " \ + "deprecated, use the `resource_bundles` or the `prepare_command` " \ + "attributes." @pre_install_callback = block end @@ -1012,6 +1042,9 @@ def pre_install(&block) # end # def post_install(&block) + CoreUI.warn "The post install hook of the specification DSL has been " \ + "deprecated, use the `resource_bundles` or the `prepare_command` " \ + "attributes." @post_install_callback = block end diff --git a/lib/cocoapods-core/specification/linter.rb b/lib/cocoapods-core/specification/linter.rb index f578185aa..9e9f39796 100644 --- a/lib/cocoapods-core/specification/linter.rb +++ b/lib/cocoapods-core/specification/linter.rb @@ -146,6 +146,7 @@ def perform_all_specs_ananlysis validate_file_patterns check_tmp_arc_not_nil check_if_spec_is_empty + check_install_hooks @consumer = nil end end @@ -301,6 +302,18 @@ def check_if_spec_is_empty end end + # Check the hooks + # + def check_install_hooks + warning "The pre install hook of the specification DSL has been " \ + "deprecated, use the `resource_bundles` or the `prepare_command` " \ + "attributes." unless consumer.spec.pre_install_callback.nil? + + warning "The post install hook of the specification DSL has been " \ + "deprecated, use the `resource_bundles` or the `prepare_command` " \ + "attributes." unless consumer.spec.post_install_callback.nil? + end + #-----------------------------------------------------------------------# # !@group Result Helpers diff --git a/lib/cocoapods-core/specification/root_attribute_accessors.rb b/lib/cocoapods-core/specification/root_attribute_accessors.rb index a42003b94..5201eb78e 100644 --- a/lib/cocoapods-core/specification/root_attribute_accessors.rb +++ b/lib/cocoapods-core/specification/root_attribute_accessors.rb @@ -118,6 +118,10 @@ def screenshots [*value] end + def prepare_command + attributes_hash["prepare_command"] + end + #-----------------------------------------------------------------------# private diff --git a/spec/specification/dsl_spec.rb b/spec/specification/dsl_spec.rb index c1675dabd..ecc5eff52 100644 --- a/spec/specification/dsl_spec.rb +++ b/spec/specification/dsl_spec.rb @@ -57,6 +57,10 @@ module Pod @spec.attributes_hash["description"].should == 'text' end + it "allows to specify a prepare command" do + @spec.prepare_command = "ruby build_files.rb" + @spec.attributes_hash["prepare_command"].should == "ruby build_files.rb" + end end #-----------------------------------------------------------------------------# diff --git a/spec/specification/linter_spec.rb b/spec/specification/linter_spec.rb index bc4265cd6..bdcb13433 100644 --- a/spec/specification/linter_spec.rb +++ b/spec/specification/linter_spec.rb @@ -303,13 +303,28 @@ def message_should_include(*values) message.should.include('spec is empty') end - it "requires that the require_arc value is specified until the switch to a true default" do - consumer = Specification::Consumer - consumer.any_instance.stubs(:requires_arc).returns(nil) + xit "requires that the require_arc value is specified until the switch to a true default" do + # TODO the default value is invalidating this test + consumer = @spec.consumer(:ios) + @spec.requires_arc = nil @linter.lint message = @linter.results.first.message message.should.include('`requires_arc` should be specified') end + + it "checks if the pre install hook has been defined" do + @spec.pre_install do; end + @linter.lint + message = @linter.results.first.message + message.should.match /pre install hook.*deprecated/ + end + + it "checks if the post install hook has been defined" do + @spec.post_install do; end + @linter.lint + message = @linter.results.first.message + message.should.match /post install hook.*deprecated/ + end end end diff --git a/spec/specification/root_attribute_accessors_spec.rb b/spec/specification/root_attribute_accessors_spec.rb index 36847ec7a..c9aae9fbf 100644 --- a/spec/specification/root_attribute_accessors_spec.rb +++ b/spec/specification/root_attribute_accessors_spec.rb @@ -117,5 +117,10 @@ module Pod @spec.screenshots.should == ['www.example.com/img1.png'] end + it "returns the prepare_command" do + @spec.prepare_command = 'ruby prepare_script.rb' + @spec.prepare_command.should == 'ruby prepare_script.rb' + end + end end From 2558ca127435e10a60349c503218e8a1e4eb494c Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Fri, 2 Aug 2013 10:13:21 +0200 Subject: [PATCH 2/2] [Specification::DSL] Improve prepare_command docs --- lib/cocoapods-core/specification/dsl.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cocoapods-core/specification/dsl.rb b/lib/cocoapods-core/specification/dsl.rb index 71a6cfcfc..fb04e4165 100644 --- a/lib/cocoapods-core/specification/dsl.rb +++ b/lib/cocoapods-core/specification/dsl.rb @@ -304,9 +304,9 @@ module DSL # @!method prepare_command=(command) # - # A command that will be executed after the Pod is downloaded. This - # command can be used to create or modify any file which be picked up - # by the other attributes of the specification. + # A bash script that will be executed after the Pod is downloaded. This + # command can be used to create, delete and modify any file downloaded + # and will be ran before other attributes from the specification. # # This command is executed before the Pod is cleaned and before the # Pods project is created. @@ -323,7 +323,7 @@ module DSL # CMD # # @param [String] command - # the name of the pod. + # the prepare command of the pod. # root_attribute :prepare_command