Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add podspec script_phases DSL #413

Merged
merged 1 commit into from
Oct 4, 2017

Conversation

dnkoutso
Copy link
Contributor

No description provided.

@dnkoutso
Copy link
Contributor Author

First run and green.

@@ -585,12 +585,6 @@ def store_podspec(options = nil)

#--------------------------------------#

SCRIPT_PHASE_REQUIRED_KEYS = [:name, :script].freeze
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thosed moved to specification.rb, no logical changes here.

# @return [Array<Hash{String=>String}>] the normalized script phases array.
#
def _prepare_script_phases(value)
if value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return unless value

Copy link
Contributor Author

@dnkoutso dnkoutso Sep 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was cargo culting from the other methods :)


SCRIPT_PHASE_OPTIONAL_KEYS = [:shell_path, :input_files, :output_files, :show_env_vars_in_log].freeze

ALL_SCRIPT_PHASE_KEYS = (SCRIPT_PHASE_REQUIRED_KEYS + SCRIPT_PHASE_OPTIONAL_KEYS).freeze
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec linter should validate this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeap working on that as we speak.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests added

@dnkoutso dnkoutso force-pushed the script_phase_podspec_dsl branch 4 times, most recently from 6906c4b to 4287d59 Compare September 29, 2017 00:40
@dnkoutso
Copy link
Contributor Author

This needs a bit more time which I will spend some tomorrow and the next few days to flesh out.

I basically want the container of the attribute to be an array of hashes as I want to preserve the order.

Will update with a comment once its ready again.

@@ -324,7 +329,11 @@ def merge_values(attr, existing_value, new_value)
#
def prepare_value(attr, value)
if attr.container == Array
value = [*value].compact
value = if value.is_a?(Hash)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@segiddins this is the primary fix that helps me accomplish this. Basically I want to the container to be an "Array" for this attribute since I want to preserve the order in which the script phases are added.

However, without this change the Hash becomes an array and then I lose the ability to recreate the hashes from the arrays.

This is the first attribute that requires an array of hashes so this is probably why I hit this.

@dnkoutso dnkoutso force-pushed the script_phase_podspec_dsl branch 3 times, most recently from 60abf96 to 88b1346 Compare September 29, 2017 20:23
@dnkoutso
Copy link
Contributor Author

Alright, this is now ready again. I decided to format the DSL the same way it is in the Podfile DSL.

In other words, users are required to specify :name key for their script instead of us trying to normalize it. Its a bit more symmetric and we can improve again in the future if needed.

@@ -376,11 +382,6 @@ def local?
#
# @overload supported_on_platform?(symbolic_name, deployment_target)
#
# @param [Symbol] symbolic_name
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused params, deleted the doc

@dnkoutso dnkoutso force-pushed the script_phase_podspec_dsl branch 3 times, most recently from 30e9ac4 to 3b55e1e Compare September 29, 2017 20:37
# Converts the keys of the given hash to a string.
#
# @param [Object] value
# the value that needs to be stripped from the Symbols.
#
# @return [Hash] the hash with the strings instead of the keys.
#
def convert_keys_to_string(value)
def self.convert_keys_to_string(value)
Copy link
Contributor Author

@dnkoutso dnkoutso Sep 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for symmetry, decided to make this a class method as well as it maintains no state.

@dnkoutso dnkoutso force-pushed the script_phase_podspec_dsl branch 3 times, most recently from 86edeaa to b3d7c0b Compare September 29, 2017 21:04
@dnkoutso
Copy link
Contributor Author

dnkoutso commented Sep 29, 2017

Alright this is set! I verified that passing wrong type to script phases fails at the linter level as well.

Also JSON looks like:

{
  "name": "CannonPodder",
  "version": "1.0.0",
  "summary": "Small library that can be used to test CocoaPod stuff (new features, CI, building etc.)",
  "homepage": "https://www.cannonpodder.com",
  "license": {
    "type": "Proprietary",
    "text": "© 2017 Something, Inc."
  },
  "authors": {
    "Someone": "someone@something.com"
  },
  "source": {
    "git": "somewhere/in/git.git",
    "tag": "1.0.0"
  },
  "platforms": {
    "ios": "9.0",
    "osx": "10.10"
  },
  "source_files": "Sources/**/*.{h,m}",
  "private_header_files": "Sources/Internal/**/*.h",
  "script_phases": [
    {
      "name": "Hello World",
      "script": "echo \"Hello World\""
    },
    {
      "name": "Hello Ruby World",
      "script": "puts \"Hello World\"",
      "shell_path": "/usr/bin/ruby"
    }
  ],
  "resource_bundles": {
    "CannonPodderResources": [
      "Resources/**/*"
    ]
  },
  "testspecs": [
    {
      "name": "Tests",
      "test_type": "unit",
      "source_files": "Tests/**/*.{h,m}",
      "resource_bundles": {
        "CannonPodderResourcesTests": [
          "Tests/Resources/**/*"
        ]
      }
    }
  ]
}

@dnkoutso
Copy link
Contributor Author

dnkoutso commented Oct 3, 2017

@paulb777 I believe you can now review and approve stuff :) Want to take a stab at this?

@dnkoutso dnkoutso added this to the 1.4 milestone Oct 3, 2017
Copy link
Member

@paulb777 paulb777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Looking forward to using script_phases.

@dnkoutso
Copy link
Contributor Author

dnkoutso commented Oct 4, 2017

Thank you! I got one more PR after this that extends script phase DSL to add execution_placement so that script phases can be executed before compilation etc.

@dnkoutso dnkoutso merged commit 3f98bce into CocoaPods:master Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants