Skip to content

traverse local depedencies from package.swift #382

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

Conversation

aelam
Copy link
Contributor

@aelam aelam commented Aug 1, 2022

  1. local/remote/edited dependency has remote/edited dependencies, Package.resolved covers them
  2. remote/edited dependency has a local dependency, the local dependency must have been declared in root Package.swift
  3. local dependency has a local dependency, traverse it and find the local dependencies only recursively
  4. pins include all remote and edited packages for 1, 2

3: requires traverse, 4: reads from package.resolved

@swift-server-bot
Copy link

Can one of the admins verify this patch?

3 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@aelam aelam force-pushed the fix/wl-depedencies-from-workspace-state-traverse branch from c76f207 to a29a4ce Compare August 1, 2022 13:45
if (!workspaceState) {
return [];
}
const inUseDependencies = await this.getInUseDependencies(workspaceState, folderContext);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a comment saying why we have to do this

return new Set<string>(folderContext?.swiftPackage.resolved?.pins.map(pin => pin.identity));
}

private async getAllLocalDependencySet(
Copy link
Contributor

Choose a reason for hiding this comment

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

Function headers? You've added them for the other functions

* @param showingDependencies result of dependencies that are showing in the tree
* @returns
*/
private async getChildLocalDependencySet(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth having this.getChildLocalDependencySet return a Set instead of passing a Set in to be filled. When you are parsing children of children you could combine the sets. It makes for slightly cleaner code.

Copy link
Contributor Author

@aelam aelam Aug 10, 2022

Choose a reason for hiding this comment

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

Maybe convert to a stack version?

Copy link
Contributor

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

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

In general looks good. Just a few minor comments

* Why not using `workspace-state.json` directly?
* * `workspace-state.json` contains all necessary dependencies but it also contains dependencies that are not in use.
* Here is the implementation details:
* 1. local/remote/edited dependency has remote/edited dependencies, Package.resolved covers them
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adam-fowler

After I tried more cases, I just found item 1 is wrong. originally I saw edited remote package is in Package.resolved <-- but it's not . perhaps I prepared a wrong test case
the test case is

  1. A depends on B, B depends on C
  2. swift package edit C, C will dissapear from Package.resolved

This means we can only check if C is in use by traversing from root or we just show edited dependencies out anyway.

then we have to go back to the original discuss point.
It seems traversing is the only way to get correct dependencies graph

Currently I added getEditedDependencySet which read edited packages from workspace-state.json, but it's still wrong. because once A is removed from Package.swift. C is still in workspace-state.json as edited. so it will still be in the list (deleting state.json could fix the issue)

lemme summarize a bit again

  1. tranverse from root, this is the best result [ no missing items, no extra items, but concern about performance]
  2. load dependencies from workspace-state.json [no missing items, but sometimes extra items, no performance issue (deleting state.json could fix the issue)]
  3. current PR, traversing local dependencies + reading editing from state.json + remote packages from pin [extra editing packages sometimes (deleting state.json could fix the issue)]

my preference is 1 >= 2 >= 3

What do you think

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. This is a real performance issue
  2. Yeah workspace-state.json would be the best solution, but it isn't kept up to date. I don't know what the implications of deleting the workspace-state.json every time we resolve is. I have added this issue to the SwiftPM repo Removing a dependency from the Package.swift does not remove it from workspace-state.json swift-package-manager#5727
  3. I'm happy to go with this temporarily. It improves on our current situation.

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 also created a PR swiftlang/swift-package-manager#5700
if it can be accepted, workspace-state.json file could be watched in future

swiftlang/swift-package-manager#5727 I'm not sure if they will treat it as a bug, because they may still treat the unused dependencies as "ManagedDepdency", hopefully, they can fix this issue

@aelam aelam marked this pull request as ready for review August 13, 2022 13:07
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.

3 participants