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

Allow specifying run script and copy files phase ordering #402

Merged
merged 8 commits into from Nov 8, 2018

Conversation

brentleyjones
Copy link
Collaborator

@brentleyjones brentleyjones commented Sep 14, 2018

Fixes #400.

  • Allows specifying run scripts to run immediately after the Compile Sources phase (which should be used instead of postbuildScripts 99% of the time).
  • Allows specifying copy files phases to be run before the Compile Sources phase
    • Adjusts modulemap and static library heady copy files phases to be run pre Compile Sources
    • Adjusts the Carthage copy-frameworks to be run sooner

@@ -194,7 +195,8 @@ class SourceGenerator {
guard targetType == .staticLibrary else { return nil }
return .copyFiles(TargetSource.BuildPhase.CopyFilesSettings(
destination: .productsDirectory,
subpath: "include/$(PRODUCT_NAME)"
subpath: "include/$(PRODUCT_NAME)",
phaseOrder: .preCompile
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This being .preCompile is a prime example of why these changes are needed.

@brentleyjones
Copy link
Collaborator Author

Even with these changes the new build system is broken. That doesn't make these changes not needed though. Eventually Xcode 10 will be fixed, but being fixed will still warrant these changes.

@toshi0383
Copy link
Collaborator

toshi0383 commented Sep 15, 2018

@brentleyjones

which should be used instead of postbuildScripts 99% of the time

Question: What do you expect for remaining 1% of them?

Also I think sources's buildPhase structure is getting too complicated. It should look as same as we see on Xcode.
Ideally I expect a format like this.

        buildPhase:
          copyFiles:
            destination: productsDirectory
            subpath: include
          compileSources:  // <- This simply makes the processing order clearer.
          runScript:
            path: my-script.sh

@brentleyjones
Copy link
Collaborator Author

Question: What do you expect for remaining 1% of them?

When you want to post-process something that has been copied into the products folder (like adjusting application icons for debug versus releases).

@brentleyjones
Copy link
Collaborator Author

Also I think sources's buildPhase structure is getting too complicated. It should look as same as we see on Xcode.
Ideally I expect a format like this.

With how we specify sources and run scripts, that wouldn't be possible right now.

Sources/ProjectSpec/TargetSource.swift Outdated Show resolved Hide resolved
Sources/ProjectSpec/Target.swift Show resolved Hide resolved
Docs/ProjectSpec.md Outdated Show resolved Hide resolved
@yonaskolb
Copy link
Owner

Looks like the tests need to be updated

With Xcode 10 dependent targets won't start compiling until compilation and all run scripts are done for the target. This means that your run script should run before Copy Files (and Copy Resources, etc.) phases unless it needs to run later, to allow dependent targets to compile faster.
Will be reused similar to `generateBuildScript()` for copy files phases at different orders.
Copy Files phases don't stop dependent targets from starting to compile. If some of the files being copied are needed for the dependent target to compile then they need to happen before the Compile Sources phase. This change allows specifying that.
With Xcode 10 run scripts will prevent dependent targets from starting to compile. The Carthage copy-frameworks script should be right after compilation to speed up compilation.
Also cleanup the documentation and add more tests for the newly added `postCompileScripts`.
@brentleyjones
Copy link
Collaborator Author

@yonaskolb Rebased and tests fixed.

@brentleyjones
Copy link
Collaborator Author

@yonaskolb Care to give this another look?

@@ -279,8 +283,9 @@ extension Target: NamedJSONDictionaryConvertible {
directlyEmbedCarthageDependencies = jsonDictionary.json(atKeyPath: "directlyEmbedCarthageDependencies")
requiresObjCLinking = jsonDictionary.json(atKeyPath: "requiresObjCLinking")

prebuildScripts = jsonDictionary.json(atKeyPath: "prebuildScripts") ?? []
postbuildScripts = jsonDictionary.json(atKeyPath: "postbuildScripts") ?? []
preBuildScripts = jsonDictionary.json(atKeyPath: "preBuildScripts") ?? jsonDictionary.json(atKeyPath: "prebuildScripts") ?? []
Copy link
Owner

Choose a reason for hiding this comment

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

Makes me think the lint command in #214 could also be used to highlight deprecations

Docs/ProjectSpec.md Show resolved Hide resolved
@@ -275,6 +276,9 @@ A source can be provided via a string (the path) or an object of the form:
- `sharedSupport`
- `plugins`
- [ ] **subpath**: **String** - The path inside of the destination to copy the files.
- [ ] **phaseOrder**: **String** - When the Copy Files phase should execute in relation to other phases. This can be one of the following values:
Copy link
Owner

Choose a reason for hiding this comment

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

Does this need to be exposed to users? Would it ever be required? I'd rather keep the options we expose low. XcodeGen is supposed to remove all those sorts of decisions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I felt it should be exposed since a user could choose to have a specific set of resources copied before compilation. We currently have those covered, AFAIK, but others might have more exotic needs.

Copy link
Owner

Choose a reason for hiding this comment

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

I'd rather leave this out for now, and only add it if it someone has a need for it 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@yonaskolb Coming back from WWDC I've learned that the way I'm doing module map copying currently isn't the best. While hacking through a local solution before figuring out how XcodeGen should be updated I ran into wanting to specify the phase order of the copy phase. Essentially I need to copy files before compilation. Wondering how you feel about me exposing this option now?

@yonaskolb
Copy link
Owner

yonaskolb commented Nov 2, 2018

Hi @brentleyjones. Would you be able to get this branch up to date to resolve the conflicts?

@brentleyjones
Copy link
Collaborator Author

@yonaskolb Yeah, I'll try to get to it today 😄.

@brentleyjones
Copy link
Collaborator Author

@yonaskolb Assuming tests pass, I believe this is all merged up. I also removed the ability to specify copy files phase ordering.

Copy link
Owner

@yonaskolb yonaskolb left a comment

Choose a reason for hiding this comment

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

Fantastic, thanks @brentleyjones! 😄

@yonaskolb yonaskolb merged commit 50ed421 into master Nov 8, 2018
@yonaskolb yonaskolb deleted the copy-files-ordering branch November 8, 2018 10:31
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

3 participants