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 Podfile DSL for script_phase #389

Merged
merged 1 commit into from
Aug 25, 2017

Conversation

dnkoutso
Copy link
Contributor

@dnkoutso dnkoutso commented Jun 20, 2017

No description provided.

#
# @return [void]
#
def script_phase(options)
Copy link
Contributor Author

@dnkoutso dnkoutso Jun 20, 2017

Choose a reason for hiding this comment

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

should this be modeled differently? maybe:

def script_phase(name, script, options = nil)

And provide a new class perhaps?

#
def script_phase(options)
raise Informative, 'Script phases can only be added within target definitions.' if current_target_definition.root?
raise Informative, 'Script phases cannot be added to abstract targets.' if current_target_definition.abstract?
Copy link
Member

Choose a reason for hiding this comment

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

hm, I think it might make sense to allow defining script phases for abstract targets, since the build env will be different for the concrete targets that inherit it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't put that much effort into it, I think it could work but for starters it might be OK?

Copy link
Member

Choose a reason for hiding this comment

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

👍

@dnkoutso dnkoutso force-pushed the script_phase_dsl branch 4 times, most recently from e80f96d to ca601f3 Compare June 20, 2017 16:01
@@ -573,6 +581,36 @@ def store_podspec(options = nil)
end
end

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

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.

minor update to use constants for these to make it easier to read and modify in the future.

# @option options [Boolean] :show_env_vars_in_log
# whether this script phase should output the environment variables during execution.
#
# @option options [Symbol] :execution_order
Copy link
Contributor Author

@dnkoutso dnkoutso Jun 20, 2017

Choose a reason for hiding this comment

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

@segiddins @dantoml I am curious on what do you think this API should be...

  1. Should we even handle this case for starters?
  2. If yes, how have you imagined it to work in terms of before or after compile sources, what about other phases like linking or headers? Could the API become execute_before => 'Compile Sources' instead?
  3. Another option could be to just let users specify and index index => 1 and we just insert that where the user asked...no questions and no special logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other way is...not to handle this at all and since this is actually adding a script phase to the users project, let the user drag the script phase and manage it manually instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...and another thing is that consumers can use post_install hooks to re-arrange their script phases....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

talked with some of my team members...seems like manual drag/post_install hook will be a good way to go. Will remove it from here.

Copy link

Choose a reason for hiding this comment

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

Hmmm, I tried this today:

  • Added some script_phases
  • run pod install
  • move phases to correct position
  • run pod install again

The custom positions are lost. CocoaPods should either keep the positions, or provide a way of specifying the positions, I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the custom shell script positions are lost? If confirmed, can you please provide a sample project and file an issue with the project attached?

Copy link

Choose a reason for hiding this comment

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

Jep, that's what I mean. I'll try to create a small sample project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@djbe ah, I think I see what you mean. If you mean you manually readjust a script phase after you've added but then it still gets reordered after another pod install then you will need a post_install hook to arrange it. This is how it landed on master instead.

We can definitely do better but I think I now understand what you mean. Please file this in https://github.com/CocoaPods/CocoaPods so we do not comment on this merged PR further and I can mark it as an enhancement.

@endocrimes
Copy link
Member

This is looking good, definitely a 1.4 feature i think tho, to avoid blocking 1.3 on bugs

@dnkoutso
Copy link
Contributor Author

yeah lets wait for 1.4.0 for this.

@dnkoutso dnkoutso added this to the 1.4 milestone Jul 10, 2017
@dnkoutso dnkoutso force-pushed the script_phase_dsl branch 2 times, most recently from a20fcce to 165c45a Compare July 14, 2017 21:59
@dnkoutso dnkoutso force-pushed the script_phase_dsl branch 3 times, most recently from 50e632b to 6f988d3 Compare August 2, 2017 19:46
@dnkoutso
Copy link
Contributor Author

dnkoutso commented Aug 2, 2017

If you care this is green and still feels good to merge. The bigger splash is about allowing podspecs to include script phases which I am hoping i can introduce in a follow up PR.

In the meantime this allows devs to include script phases within their podfiles for app targets.

def store_script_phase(options)
option_keys = options.keys
unless option_keys.all? { |key| ALL_SCRIPT_PHASE_KEYS.include?(key) }
raise StandardError, 'Unrecognized options for the shell script ' \
Copy link
Member

Choose a reason for hiding this comment

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

might be nice to say which options are unrecognized, and print out the known ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure will update

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@dnkoutso
Copy link
Contributor Author

rebased

@dnkoutso
Copy link
Contributor Author

Any objections of landing this feature? It's useful but not that useful as for podspecs having the ability to declare script phases.

I think we can land this and then just have it exist.

@dnkoutso
Copy link
Contributor Author

rebased. Will merge on ✅

@dnkoutso dnkoutso merged commit bdec7d4 into CocoaPods:master Aug 25, 2017
@dnkoutso
Copy link
Contributor Author

dnkoutso commented Aug 25, 2017

@dantoml please do let me know if you are against this. I'd be happy to revert. Its a minor useful feature that I built in 30 minutes. Its corresponding CocoaPods PR also prepares the ground for managing script phases declared within podspecs.

I am planning on a follow up for podspec DSL.

CocoaPods PR: CocoaPods/CocoaPods#6820

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.

None yet

4 participants