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

Use stack ls dependencies json #1364

Merged
merged 35 commits into from
Jun 22, 2020
Merged

Use stack ls dependencies json #1364

merged 35 commits into from
Jun 22, 2020

Conversation

aherrmann
Copy link
Member

@aherrmann aherrmann commented Jun 12, 2020

This is a step towards #1310

Version 2.3.1 of stack introduced stack ls dependencies json. With this PR we make use of that feature to determine the package dependency graph and package versions, instead of the previous approach of parsing the dot formatted dependency graph.

Following the example of rules_jvm_external this vendors the Starlark JSON parser from https://github.com/erickj/bazel_json.

This PR also separates the step that determines the dependency graph from the step that fetches the package sources. This is in preparation for #1310 where we'll want to store the dependency graph and package locations in a lock file and perform the fetching in a separate repository rule that can depend on a lock file alone.

I have verified that the resulting external workspaces are equivalent
up to expected differences by comparing the results of bazel fetch @stackage//:all in the example directory and @stackage//:all and @ghcide//:all in the project root. Note, dictionaries are iterated in insertion order. To compare the results before and after this commit one has to sort the contents of package.bzl and BUILD.bazel by package name first.

The old mechanism did not respect Cabal revisions. This new implementation fetches the correct Cabal revisions as defined in the Stackage snapshot.
(This difference was due to not passing --resolver to stack unpack as is required.)

@aherrmann aherrmann force-pushed the stack-json branch 2 times, most recently from 29ac2ef to 5c440c6 Compare June 14, 2020 13:23
Copy link
Contributor

@hanshoglund hanshoglund left a comment

Choose a reason for hiding this comment

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

Looks good, just a few comments.

third_party/bazel_json/LICENSE Outdated Show resolved Hide resolved
haskell/cabal.bzl Show resolved Hide resolved
haskell/cabal.bzl Show resolved Hide resolved
aherrmann added a commit that referenced this pull request Jun 22, 2020
@aherrmann aherrmann added the merge-queue merge on green CI label Jun 22, 2020
aherrmann added 11 commits June 22, 2020 15:41
buildifier chokes on a nested WORKSPACE file.
ls dependencies json was introduced in 2.3
Previously, the strategy was to first fetch all packages listed by the
user in the `packages` attribute to `stack_snapshot` and then use them
as "local packages" to determine all transitive dependencies. This
interleaves the fetching of remote packages with the dependency
resolution which prevents us from persisting the results of dependency
resolution in a lock file.

The new strategy implemented by this commit is to instead generate a
local "dummy" package that lists all packages specified by the user as
its dependencies and generate a `stack.yaml` file that captures all
Cabal flags, package version overrides, and vendored packages. Stack is
then invoked on these two files to determine the transitive dependency
graph without first fetching any packages into the external Bazel
workspace. The package sources are only fetched in a later step.

This separation allows to store the package metadata in a lock file and
let Bazel fetch package sources separately based on the information in
the lock file in future.

I have verified that the resulting external workspaces are equivalent
up to expected differences by comparing the results of `bazel fetch
@stackage//:all` in the `example` directory, similarly for `@stackage`
and `@ghcide` in the project directory. Note, dictionaries are iterated
in insertion order. To compare the results before and after this commit
one has to sort the contents of `package.bzl` and `BUILD.bazel` by
package name first.
It's no longer necessary to separate the loop that determines the
dependencies from the loop that discovers the packages. With this change
the loops are merged into a single loop that just converts the metadata
returned by `stack ls dependencies json` into the format that
`stack_snapshot` expects.
@aherrmann
Copy link
Member Author

/azp run

@aherrmann
Copy link
Member Author

@Mergifyio refresh

@mergify
Copy link
Contributor

mergify bot commented Jun 22, 2020

Command refresh: success

@aherrmann
Copy link
Member Author

Mergify seems to be stuck showing the following conflicting queues on this PR and #1367.

The following pull requests are queued:
#1367, #1364 (priority: medium)

The following pull requests are queued:
#1364, #1367 (priority: medium)

Merging manually.

@aherrmann aherrmann merged commit f8660ec into master Jun 22, 2020
@aherrmann aherrmann deleted the stack-json branch June 22, 2020 15:42
@mergify mergify bot removed the merge-queue merge on green CI label Jun 22, 2020
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