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

TargetScript output files are ignored if the files don't exist at generate time #5925

Open
dcramps opened this issue Feb 13, 2024 · 5 comments · May be fixed by #6534
Open

TargetScript output files are ignored if the files don't exist at generate time #5925

dcramps opened this issue Feb 13, 2024 · 5 comments · May be fixed by #6534
Assignees
Labels
💎 Bounty type:bug Something isn't working

Comments

@dcramps
Copy link
Contributor

dcramps commented Feb 13, 2024

What happened?

If a TargetScript specifies an output file it is not added to the script's output files in the generated project unless it already exists at the time tuist generate is run. Similarly, a file that does not exist at generate time is not added to the Compile Sources phase.

My use case here is that I have a target script that runs on build, specifying its output file. The file is added to the Compile Sources phase, and all is well: the script generates the file, so it exists by the time sources are compiled. With Tuist, this is not possible. In my own project I have hacked around it by using FileManager to create the file prior to returning the script, but that is super fragile and can break due to project caching.

A TargetScript requiring output files to exist to be included is definitely a bug, and in Tuist 4 is even more of a bug as files that exist are not included in output files for some reason.

For the Compile Sources part, I believe Tuist should, or should have the option to, include files in Compile Sources that do not exist, as it is perfectly reasonable for a script to generate those missing files.

Sample projects:
tuist3.zip
tuist4.zip

How do we reproduce it?

Tuist 3

  1. Run tuist generate on the attached sample tuist3.zip
  2. Open the TuistScriptOutputFiles target, and expand the Touch File.swift for TuistScriptOutputFiles phase under Build Phases
  3. Note that Output Files is empty
  4. Expand Compile Sources under Build Phases
  5. Note that File.swift is not included
  6. Run tuist generate again
  7. Note that Output Files is no longer empty
  8. Note that File.swift is now included in Compile Sources phase

Tuist 4

  1. Run tuist generate on the attached sample tuist4.zip
  2. Open the TuistScriptOutputFiles target, and expand the Touch File.swift for TuistScriptOutputFiles phase under Build Phases
  3. Note that Output Files is empty
  4. Expand Compile Sources under Build Phases
  5. Note that File.swift is not included
  6. Run tuist generate again
  7. Note that Output Files is still empty
  8. Note that File.swift is now included in Compile Sources phase

Error log

No errors

macOS version

14.3.1

Tuist version

3.42.3, 4.1.2

Xcode version

15.2

@dcramps dcramps added the type:bug Something isn't working label Feb 13, 2024
@fortmarek
Copy link
Member

/bounty 100

Copy link

algora-pbc bot commented Jun 16, 2024

💎 $100 bounty • Tuist

Steps to solve:

  1. Start working: Comment /attempt #5925 with your implementation plan
  2. Submit work: Create a pull request including /claim #5925 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to tuist/tuist!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @leszko11 Jul 18, 2024, 4:05:45 PM WIP

@abhishek818
Copy link

@fortmarek can i get this assigned?

@abhishek818
Copy link

seems like this would need a more deep dive in the codebase than i expected, unassigning myself as of now.

@leszko11
Copy link
Collaborator

leszko11 commented Jul 18, 2024

Hello 👋

I did some debugging and this is where we're loosing outputPaths value when file does not exist.

My first idea to fix that, was to take all targets scripts in ManifestGraphLoader and map outputPaths to SideEffectDescriptor and return them from load(path:) method, but I'm not able to map Path to AbsolutePath there.
Maybe TargetAction+ManifestMapper.swift is a better place to handle missing files?

/attempt #5925

@leszko11 leszko11 self-assigned this Jul 18, 2024
@leszko11 leszko11 linked a pull request Jul 19, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Bounty type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants