igor-makarov / xcake

:cake: Describe Xcode projects in a human readable format and (re)generate one on demand.
MIT License
634 stars 48 forks source link

Configurable target.shell_script_build_phase input- & output-files and order of build phases #208

Closed PatrickKuijpers closed 4 years ago

PatrickKuijpers commented 4 years ago

When defining the shell_script_build_phase the name and script can be defined as described here. It would be great if the input- and output-files could also be defined.

Additionally I'd like to define the order of a build phase relative to other build phases. For example, moving my newly generated build phase on top of the existing Compile Sources phase.

igor-makarov commented 4 years ago

Actually, it's possible already - the documentation probably hasn't been updated to reflect it. Would you like to make a PR that updates it?

Here's the syntax, in a nutshell -

target.shell_script_build_phase "Build Phase Name", "echo 'Hello World'" do |phase|
    phase.input_paths = []
    phase.input_file_list_paths = []
    phase.output_paths = []
    phase.output_file_list_paths = []
end

As for moving the phase above compilation, you can use #pre_shell_script_build_phase for that.

I would really appreciate the PR if you can spare some time on it.
This project is really useful to a lot of people but I don't have much time to maintain it.

PatrickKuijpers commented 4 years ago

Thanks for the fast answer!

Sure, I'll do. The syntax is new to me though, so how can I combine a multiline SCRIPT with the do |phase| definition behind it?

See example code here:

target.pre_shell_script_build_phase "Generate Apollo GraphQL API", <<-SCRIPT
    SCRIPT_PATH="${PODS_ROOT}/Apollo/scripts"
    cd "${SRCROOT}/${TARGET_NAME}/GraphQL"
    "${SCRIPT_PATH}"/run-bundled-codegen.sh codegen:generate --target=swift --includes=./**/*.graphql --localSchemaFile="schema.json" GraphQLAPI.swift"
SCRIPT do |phase|
    phase.input_paths = ["$(SRCROOT)/$(TARGET_NAME)/**/*.graphql"]
    phase.output_paths = ["$(SRCROOT)/$(TARGET_NAME)/GraphQL/GraphQLAPI.swift"]
end

EDIT: With the code above I get the following error:

.../Cakefile:124: can't find string "SCRIPT" anywhere before EOF (SyntaxError)
.../Cakefile:83: syntax error, unexpected end-of-input
igor-makarov commented 4 years ago

Ruby DOCSTRING syntax is a mystery to me as well 🤷🏻‍♂️

Personally, I'd just factor it into separate lines:

apollo_script = <<-SCRIPT
    SCRIPT_PATH="${PODS_ROOT}/Apollo/scripts"
    cd "${SRCROOT}/${TARGET_NAME}/GraphQL"
    "${SCRIPT_PATH}"/run-bundled-codegen.sh codegen:generate --target=swift --includes=./**/*.graphql --localSchemaFile="schema.json" GraphQLAPI.swift"
SCRIPT
target.pre_shell_script_build_phase "Generate Apollo GraphQL API", apollo_script do |phase|
    phase.input_paths = ["$(SRCROOT)/$(TARGET_NAME)/**/*.graphql"]
    phase.output_paths = ["$(SRCROOT)/$(TARGET_NAME)/GraphQL/GraphQLAPI.swift"]
end
PatrickKuijpers commented 4 years ago

Closed issue and created the PR: https://github.com/igor-makarov/xcake/pull/209

Thanks again for the quick help!