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

Add --show-dependencies option to dump external dependencies #302

Merged
merged 1 commit into from
May 5, 2016

Conversation

bhargavg
Copy link
Contributor

@bhargavg bhargavg commented Apr 30, 2016

Dump the external dependencies (along with their dependencies) to console.

Sample output for Vapor (v0.7.0):

$ swift-build --show-dependencies
.
├── C7<https://github.com/open-swift/C7.git@0.5.0>
├── S4<https://github.com/open-swift/S4.git@0.4.0>
│   └── C7<https://github.com/open-swift/C7.git@0.5.0>
├── String<https://github.com/Zewo/String.git@0.5.1>
├── StructuredData<https://github.com/Zewo/StructuredData.git@0.5.0>
│   └── C7<https://github.com/open-swift/C7.git@0.5.0>
├── JSON<https://github.com/Zewo/JSON.git@0.5.0>
│   └── StructuredData<https://github.com/Zewo/StructuredData.git@0.5.0>
│       └── C7<https://github.com/open-swift/C7.git@0.5.0>
├── Strand<https://github.com/ketzusaka/Strand.git@1.2.3>
├── Hummingbird<https://github.com/ketzusaka/Hummingbird.git@1.4.0>
│   ├── Strand<https://github.com/ketzusaka/Strand.git@1.2.3>
│   └── C7<https://github.com/open-swift/C7.git@0.5.0>
├── CryptoEssentials<https://github.com/CryptoKitten/CryptoEssentials.git@0.5.2>
├── HMAC<https://github.com/CryptoKitten/HMAC.git@0.5.2>
│   └── CryptoEssentials<https://github.com/CryptoKitten/CryptoEssentials.git@0.5.2>
├── SHA2<https://github.com/CryptoKitten/SHA2.git@0.5.1>
│   └── CryptoEssentials<https://github.com/CryptoKitten/CryptoEssentials.git@0.5.2>
└── Vapor<https://github.com/qutheory/vapor@0.7.0>
    ├── S4<https://github.com/open-swift/S4.git@0.4.0>
    │   └── C7<https://github.com/open-swift/C7.git@0.5.0>
    ├── String<https://github.com/Zewo/String.git@0.5.1>
    ├── JSON<https://github.com/Zewo/JSON.git@0.5.0>
    │   └── StructuredData<https://github.com/Zewo/StructuredData.git@0.5.0>
    │       └── C7<https://github.com/open-swift/C7.git@0.5.0>
    ├── Hummingbird<https://github.com/ketzusaka/Hummingbird.git@1.4.0>
    │   ├── Strand<https://github.com/ketzusaka/Strand.git@1.2.3>
    │   └── C7<https://github.com/open-swift/C7.git@0.5.0>
    ├── HMAC<https://github.com/CryptoKitten/HMAC.git@0.5.2>
    │   └── CryptoEssentials<https://github.com/CryptoKitten/CryptoEssentials.git@0.5.2>
    └── SHA2<https://github.com/CryptoKitten/SHA2.git@0.5.1>
        └── CryptoEssentials<https://github.com/CryptoKitten/CryptoEssentials.git@0.5.2>

Only plain text option is supported as of now. Code is extensible to support additional formats like Dot and JSON.

Will add support for other formats in my next PRs.

@czechboy0
Copy link
Member

Hi @bhargavg, great stuff!

In the example, I would only expect the Vapor dependency and its dependency tree to be shown. AFAI understand the output, you're actually printing the dependency tree of all the leaf dependencies. So I'd only expect this to be output:

─── Vapor<https://github.com/qutheory/vapor@0.7.0>
    ├── S4<https://github.com/open-swift/S4.git@0.4.0>
    │   └── C7<https://github.com/open-swift/C7.git@0.5.0>
    ├── String<https://github.com/Zewo/String.git@0.5.1>
    ├── JSON<https://github.com/Zewo/JSON.git@0.5.0>
    │   └── StructuredData<https://github.com/Zewo/StructuredData.git@0.5.0>
    │       └── C7<https://github.com/open-swift/C7.git@0.5.0>
    ├── Hummingbird<https://github.com/ketzusaka/Hummingbird.git@1.4.0>
    │   ├── Strand<https://github.com/ketzusaka/Strand.git@1.2.3>
    │   └── C7<https://github.com/open-swift/C7.git@0.5.0>
    ├── HMAC<https://github.com/CryptoKitten/HMAC.git@0.5.2>
    │   └── CryptoEssentials<https://github.com/CryptoKitten/CryptoEssentials.git@0.5.2>
    └── SHA2<https://github.com/CryptoKitten/SHA2.git@0.5.1>
        └── CryptoEssentials<https://github.com/CryptoKitten/CryptoEssentials.git@0.5.2>

Or what was the Package.swift of the example above?

@czechboy0
Copy link
Member

Also, I think it would be valuable to print the allowed version range, instead of the resolved version in each dependency. That's so that if there's a version conflict, it'd be obvious which two versions are clashing. Does that make sense?

@ddunbar
Copy link
Contributor

ddunbar commented Apr 30, 2016

Would it be too "magic" to hide the URL string if a package is already depended upon by something earlier in the graph? I think this would make it easier to read and see shared dependencies.

@czechboy0
Copy link
Member

@ddunbar I actually wanted to see the full URLs so that I can easily spot conflicting forks of the same project.

pkgVersion = version.description
} else {
pkgVersion = "unspecified"
}
Copy link
Contributor

@kostiakoval kostiakoval May 1, 2016

Choose a reason for hiding this comment

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

how about small code simplification?

let pkgVersion = package.version?.description ?? "unspecified"

@bhargavg
Copy link
Contributor Author

bhargavg commented May 1, 2016

AFAI understand the output, you're actually printing the dependency tree of all the leaf dependencies.

Good catch, I was actually printing all the leaf dependencies, which is wrong. Modified it to start the graph from root external dependencies.

$ cat Package.swift
import PackageDescription

let package = Package(
    name: "testvapor",
    dependencies: [
        .Package(url: "https://github.com/qutheory/vapor", Version(0,7,0))
    ]
)

$ swift-build --show-dependencies
.
└── Vapor<https://github.com/qutheory/vapor@0.7.0>
    ├── S4<https://github.com/open-swift/S4.git@0.4.0>
    │   └── C7<https://github.com/open-swift/C7.git@0.5.0>
    ├── String<https://github.com/Zewo/String.git@0.5.1>
    ├── JSON<https://github.com/Zewo/JSON.git@0.5.0>
    │   └── StructuredData<https://github.com/Zewo/StructuredData.git@0.5.0>
    │       └── C7<https://github.com/open-swift/C7.git@0.5.0>
    ├── Hummingbird<https://github.com/ketzusaka/Hummingbird.git@1.4.0>
    │   ├── Strand<https://github.com/ketzusaka/Strand.git@1.2.3>
    │   └── C7<https://github.com/open-swift/C7.git@0.5.0>
    ├── HMAC<https://github.com/CryptoKitten/HMAC.git@0.5.2>
    │   └── CryptoEssentials<https://github.com/CryptoKitten/CryptoEssentials.git@0.5.2>
    └── SHA2<https://github.com/CryptoKitten/SHA2.git@0.5.1>
        └── CryptoEssentials<https://github.com/CryptoKitten/CryptoEssentials.git@0.5.2>

Now for the second point you mentioned:

Also, I think it would be valuable to print the allowed version range, instead of the resolved version in each dependency. That's so that if there's a version conflict, it'd be obvious which two versions are clashing.

I think, there are few issues with this approach:

  • Indicating version range doesn't tell you which version SwiftPM picked up
  • Incase of dependency hell, user has to manually scan through all the dependencies looking for a version clash

IMHO, indicating the version conflicts can be handled differently.

When there are unsolvable version requirements, we show an error message as follows:

error: The dependency graph could not be satisfied (url/of/dependency)

This error doesn't give enough info as to which all dependencies caused the failure.

If we can modify the error as follows, I think it will better help user in finding the problematic dependencies:

error: The dependency graph could not be satisfied
DepC(@v0.1.0) requires DepA(@v0.1.0)
DepB(@v0.1.0) requires DepA(@v0.2.0)

So, I suggest, we modify error reporting code rather than modifying --show-dependencies to handle this.

@ddunbar @mxcl thoughts?

@bhargavg bhargavg force-pushed the add-show-dependencies branch 3 times, most recently from 406dc94 to 7e05898 Compare May 1, 2016 13:59
@czechboy0
Copy link
Member

@bhargavg Awesome! Yeah you make a good point, better diagnostics in the dependency clashes would probably solve the problem even better. On the other hand, the dependency range is what each package requires, not a specific version. As I see it the dependencies should represent what the packages "want" (version range), not what they "get" (resolved version).

import PackageType
import struct PackageDescription.Version

final class ShowDependencies {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need ShowDependencies class here? I think we can make dumpDependenciesOf a free function. It would be nicer to call it. ShowDependencies.dumpDependenciesOf( vs dumpDependenciesOf(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@bhargavg
Copy link
Contributor Author

bhargavg commented May 1, 2016

On the other hand, the dependency range is what each package requires, not a specific version. As I see it the dependencies should represent what the packages "want" (version range), not what they "get" (resolved version).

@czechboy0 If i understand you correctly, you are talking about the modified error output I proposed right? Yeah, that error message should have the range or explicit version specified in Package.swift file.

@czechboy0
Copy link
Member

@bhargavg I actually meant in the dump dependencies function. That I'd expect the representation of the wanted version range instead of the resolved function. But it's definitely something to discuss, we can change that later.

@ddunbar
Copy link
Contributor

ddunbar commented May 2, 2016

@czechboy0 I don't think you should be allowed to have two versions of the same package name in a graph, so conflicting forks shouldn't be possible (unless someone renamed it in the fork, which would then show up). I thought we currently enforced this (pretty sure it will fail to build, even if we don't).

@mxcl
Copy link
Contributor

mxcl commented May 2, 2016

Lovely!

@mxcl
Copy link
Contributor

mxcl commented May 2, 2016

If we'd like it to be more readable already (IMO this is fine to merge and we can tweak the usability after we've used it in real world settings), then I'd go with hiding the URLs unless there is a flag specified, same for ranges.

But this is a really great addition, thanks.

@mxcl
Copy link
Contributor

mxcl commented May 3, 2016

Will merge unless there are objections.

I may change the mode to --print-dependencies, maybe, don't know.

@bhargavg
Copy link
Contributor Author

bhargavg commented May 3, 2016

@mxcl, the reason why this is not yet merged is, there is no decision made on whether this option should print resolved dependencies -or- the dependent ranges for each dependency as mentioned in their Package.swift

Also, @czechboy0 brought up a case when the graph is unresolvable, how best this option helps the user in identifying the conflicting dependencies.

@mxcl
Copy link
Contributor

mxcl commented May 3, 2016

I don't think it is necessary to solve those issues before merging this PR. We will learn better what we need with this base functionality there to guide us.

@bhargavg
Copy link
Contributor Author

bhargavg commented May 4, 2016

Cool...!!! Can't wait to see this get merged.

@bhargavg bhargavg force-pushed the add-show-dependencies branch 2 times, most recently from 28380fa to 4868efd Compare May 4, 2016 18:17
Currently only plain text option is supported. But infrastructure is
written to support additional formats like Dot and JSON.
@aciidgh
Copy link
Contributor

aciidgh commented May 4, 2016

Huh. I think swift ci only available for me on my PRs?
@modocache @shahmishal Do you have any info about this?

@aciidgh
Copy link
Contributor

aciidgh commented May 4, 2016

@swift-ci please test

@bhargavg
Copy link
Contributor Author

bhargavg commented May 4, 2016

Seems like CI is not started, @mxcl Could you please start CI on this and merge if no modifications are needed?

@mxcl
Copy link
Contributor

mxcl commented May 4, 2016

@swift-ci Please test

@shahmishal
Copy link
Member

@aciidb0mb3r Can you please try again when you get a chance? Thanks!

@aciidgh
Copy link
Contributor

aciidgh commented May 5, 2016

@swift-ci please test

@aciidgh
Copy link
Contributor

aciidgh commented May 5, 2016

@shahmishal tried again, din work

@ddunbar
Copy link
Contributor

ddunbar commented May 5, 2016

The test failures were unrelated, merging.

@ddunbar ddunbar merged commit 67cbcc6 into swiftlang:master May 5, 2016
aciidgh pushed a commit to aciidgh/swift-package-manager that referenced this pull request Jan 11, 2019
Add support for configuring the build system scheduler
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

7 participants