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

Prevent generation of redundant file elements #515

Merged
merged 4 commits into from Oct 3, 2019

Conversation

kwridan
Copy link
Collaborator

@kwridan kwridan commented Sep 28, 2019

Resolves #514

Short description πŸ“

File elements for all dependencies and products within a graph were always generated and included in projects without applying any filtering.
This led to the inclusion of redundant file elements in top level projects (for products & dependencies that they didn't require)

In this example:

Dependencies:

  • Framework2 -> Framework3
  • Framework4 -> Framework4
  • Framework5 -> ARKit.framework however

The highlighted elements are redundant

Screenshot 2019-09-28 at 16 22 45

Solution πŸ“¦

Leverage the business logic with the Graph to determine which file references are needed.

Implementation πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

  • Update DependencyReference.product to include product name
  • Add helper methods to Graph to allow listing all dependency references for a project
  • Update ProjectFileElements to leverage new helper
  • Update helpers to also resolve local swift packages
  • Add fixture
  • Update change log

Test Plan πŸ› :

  • Generate the fixture fixtures/ios_app_with_frameworks via tuist generate
  • Open the generated Workspace
  • Verify the Framework3 project doesn't contain file references for Framework5
  • Verify the Framework3 project doesn't contain file references for ARKit.framework
  • Verify the Framework4 project doesn't contain file references for ARKit.framework

@pepicrft
Copy link
Contributor

Is this ready for review @kwridan ?

@kwridan
Copy link
Collaborator Author

kwridan commented Sep 29, 2019

will rebase it ontop of master, there are a few additional changes needed for the swift packages dependencies too

@kwridan kwridan changed the title Prevent generation of redundant file elements 🚧 Prevent generation of redundant file elements Sep 29, 2019

references.append(contentsOf: otherTargetFrameworks)

return Set(references).sorted()
}

func copyProductDependencies(path: AbsolutePath, target: Target) -> [DependencyReference] {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think copyProductDependencies is a bit ambiguous. What does it mean? What about including a note like this one explaining why this method is useful?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

return Set(dependencies).sorted()
}

func allDependencyReferences(for project: Project, system: Systeming) throws -> [DependencyReference] {
Copy link
Contributor

Choose a reason for hiding this comment

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

We really need to get rid of the dependency injection for the System class 😬

@pepicrft
Copy link
Contributor

The PR is looking good @kwridan πŸ‘

- File elements for all dependencies are products within a graph were always generated and included in projects without applying any filtering
- This led to the inclusion of redundant file elements in top level projects (for products & dependencies that they didn't require)
- The graph helper methods are now consulted to obtain a list of dependency references that are known to be required by the project
- Additional helpers methods on graph were add to help unify / share some of the business logic regarding which dependencies are needed

Test Plan:

- Generate the fixture `fixtures/ios_app_with_frameworks` via `tuist generate`
- Open the generated Workspace
- Verify the `Framework3` project doesn't contain file references for `Framework5`
- Verify the `Framework3` project doesn't contain file references for `ARKit.framework`
- Verify the `Framework4` project doesn't contain file references for `ARKit.framework`
@kwridan kwridan force-pushed the fixes/redundant-file-elements branch from 98f5df6 to ce93970 Compare September 30, 2019 18:56
@kwridan kwridan changed the title 🚧 Prevent generation of redundant file elements Prevent generation of redundant file elements Sep 30, 2019
@kwridan
Copy link
Collaborator Author

kwridan commented Sep 30, 2019

Thanks for taking a look @pepibumur!

@tuistbot
Copy link
Contributor

1 Warning
⚠️ Have you introduced any user-facing changes? If so, please take some time to update the documentation. Keeping the documentation up to date makes it easier for users to learn how to use Tuist.

Generated by 🚫 Danger

@codecov
Copy link

codecov bot commented Sep 30, 2019

Codecov Report

Merging #515 into master will decrease coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #515      +/-   ##
==========================================
- Coverage    91.6%   91.53%   -0.08%     
==========================================
  Files         358      358              
  Lines       19343    19339       -4     
==========================================
- Hits        17720    17701      -19     
- Misses       1623     1638      +15
Impacted Files Coverage Ξ”
...atorTests/Generator/ProjectFileElementsTests.swift 99.65% <100%> (-0.02%) ⬇️
Tests/TuistGeneratorTests/Graph/GraphTests.swift 100% <100%> (ΓΈ) ⬆️
Sources/TuistGenerator/Graph/Graph.swift 95.22% <100%> (-2.54%) ⬇️
...tGeneratorTests/Generator/LinkGeneratorTests.swift 100% <100%> (ΓΈ) ⬆️
...TuistGenerator/Generator/ProjectFileElements.swift 97.44% <100%> (-0.16%) ⬇️
...urces/TuistGenerator/Generator/LinkGenerator.swift 94.82% <100%> (-0.13%) ⬇️
Sources/TuistGenerator/Models/Target.swift 85.71% <0%> (-10.39%) ⬇️
Sources/TuistGenerator/Models/Product.swift 96% <0%> (+0.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update c359fe9...03b659a. Read the comment docs.


references.append(contentsOf: otherTargetFrameworks)

return Set(references).sorted()
}

func copyProductDependencies(path: AbsolutePath, target: Target) -> [DependencyReference] {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -153,6 +147,20 @@ class ProjectFileElements {
isReference: $0.isReference)
})

// Local Packages
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 need to think about this further ...

The inconsistency here is that all other dependencies are resolved via allDependencyReferences whereas this one isn't included there yet.

@kwridan kwridan merged commit b6c822d into tuist:master Oct 3, 2019
@kwridan kwridan deleted the fixes/redundant-file-elements branch October 3, 2019 20:51
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.

Generated projects contain redundant file elements from dependency projects
3 participants