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

crate_universe now renders json formatted lockfiles #692

Merged
merged 7 commits into from
Apr 19, 2021
Merged

crate_universe now renders json formatted lockfiles #692

merged 7 commits into from
Apr 19, 2021

Conversation

UebelAndre
Copy link
Collaborator

@UebelAndre UebelAndre commented Apr 17, 2021

Notable changes in this PR:

  • crate_universe lockfile attributes are now rendered as json files instead of starlark dumps
  • crate_universe_resolver now accepts a repository_dir argument for the path to the new repository. This should be preferable to a single output file for all dependencies.
  • The cargo-raze dependenciy has been updated to a pin which implements the required sorting and de-serialization.
  • Formatted use declarations
  • Updated dependencies
  • CARGO and RUSTC environment variables are now ignored in determining the digest. This should be safe given that cargo version is an input to generating the lockfile hash.
  • repository_template has been renamed to crate_registry_template, which is more correct.
  • The json module is now used to handle generating the config .json file

@google-cla google-cla bot added the cla: yes label Apr 17, 2021
@UebelAndre
Copy link
Collaborator Author

UebelAndre commented Apr 17, 2021

This lack of 4.0 is really driving me insane....

bazel --nomaster_bazelrc --bazelrc=/dev/null version
2021/04/17 23:18:02 Downloading https://releases.bazel.build/3.5.0/release/bazel-3.5.0-linux-x86_64...
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
Build label: 3.5.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Sep 2 20:11:46 2020 (1599077506)
Build timestamp: 1599077506
Build timestamp as int: 1599077506
 
ERROR: /var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/ec321eb2cc2d0f8f91b676b6d4c66c29/external/rules_rust/crate_universe/defs.bzl:35:20: name 'json' is not defined
ERROR: /var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/ec321eb2cc2d0f8f91b676b6d4c66c29/external/rules_rust/crate_universe/defs.bzl:46:42: name 'json' is not defined
ERROR: /var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/ec321eb2cc2d0f8f91b676b6d4c66c29/external/rules_rust/crate_universe/defs.bzl:48:12: name 'json' is not defined
ERROR: /var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/ec321eb2cc2d0f8f91b676b6d4c66c29/external/rules_rust/crate_universe/defs.bzl:333:12: name 'json' is not defined
ERROR: /var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/ec321eb2cc2d0f8f91b676b6d4c66c29/external/rules_rust/crate_universe/defs.bzl:361:12: name 'json' is not defined
ERROR: error loading package '': Extension 'crate_universe/defs.bzl' has errors
Traceback (most recent call last):
  File "bazelci.py", line 3383, in <module>
    sys.exit(main())
  File "bazelci.py", line 3349, in main
    execute_commands(
  File "bazelci.py", line 1081, in execute_commands
    bazel_version = print_bazel_version_info(bazel_binary, platform)
  File "bazelci.py", line 1315, in print_bazel_version_info
    execute_command(
  File "bazelci.py", line 2066, in execute_command
    return subprocess.run(
  File "/usr/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['bazel', '--nomaster_bazelrc', '--bazelrc=/dev/null', 'info']' returned non-zero exit status 2.

@UebelAndre UebelAndre marked this pull request as ready for review April 18, 2021 01:30
Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Thanks for pushing this forwards!

crate_universe/defs.bzl Outdated Show resolved Hide resolved
generate_dependencies(config, &opt)
}

fn reuse_lockfile(config: Config, lockfile: &Path, opt: &Opt) -> anyhow::Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This structure in general doesn't quite look like I was imagining it would, but I think that's because this is an incremental step which will enable future change?

I'm imagining fn main() ending up looking like:

// ...

let resolver = config.preprocess()?;

let lockfile_caching_resolver = LockfileCachingResolver::new(resolver, &opt.lockfile);

let consolidator = match lockfile_caching_resolver.resolve(&lockfile) {
    Ok(consolidator) => consolidator,
    Err(ResolverError::OutOfDateLockFile) => {
        // Error about lockfile being out of date
    },
    Err(err) => { return Err(err); },
};

let renderer = consolidator.consolidate()?;

// ...

The idea being that if we're using a lockfile, we'll treat that as a cache of the Resolver::resolve function and unconditionally perform consolidation and rendering exactly the same as if we'd missed the cache because no lockfile was in use.

That would also allow us to remove everything except toml and resolver_config from Resolver, and accordingly from the lockfile hash, and would allow the lockfile to just contain the hash, resolved_packages and probably member_packages_version_mapping.

That's a little different from your current structure which puts a conditional around everything after Config parsing, stores effectively a whole Renderer in the lockfile, and accordingly still has to keep lots of things factored into the hash.

Do we have the same destination in mind, or were you thinking something different?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What you're describing sounds like a good approach to me. I ended up doing this because I thought it was the simpler change and the fastest path to getting well formed lockfiles. Most of the time on this PR was spent trying to figure out what was going on so definitely a more incremental change than a strong directional one.

crate_universe/src/main.rs Outdated Show resolved Hide resolved
Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>
UebelAndre and others added 2 commits April 19, 2021 07:24
Co-authored-by: Daniel Wagner-Hall <dawagner@gmail.com>
Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

LGTM - would appreciate applying my last suggestion before merging, if you don't mind!

@illicitonion illicitonion merged commit 4ea9bfe into bazelbuild:main Apr 19, 2021
@UebelAndre UebelAndre deleted the lock branch April 19, 2021 14:57
yagehu pushed a commit to yagehu/rules_rust that referenced this pull request Apr 23, 2021
Notable changes in this PR:
- `crate_universe` `lockfile` attributes are now rendered as json files instead of starlark dumps
- The `cargo-raze` dependenciy has been updated to a pin which implements the required sorting and de-serialization.
- Formatted `use` declarations
- Updated dependencies
- `CARGO` and `RUSTC` environment variables are now ignored in determining the digest. This should be safe given that `cargo version` is an input to generating the lockfile hash.
- `repository_template` has been renamed to `crate_registry_template`, which is more correct.
- The [json](https://docs.bazel.build/versions/master/skylark/lib/json.html) module is now used to handle generating the config `.json` file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants