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 SHA-256 to the local_repositories #47

Merged
merged 4 commits into from
Jun 5, 2018
Merged

Conversation

damienmg
Copy link
Member

@damienmg damienmg commented Jun 3, 2018

The SHA-256 is available from Cargo so it's easy to expose and it helps Bazel with caching and reproducibility.

This PR also contains 2 minor fixes:

  • Update Cargo.lock, the current one fail on my machine (Ubuntu 18.04)
  • Remove some unused variables and mark two modules as test config to remove unused warnings.

This is good practice to have them and we get them for free from Cargo.
The previous one doesn't build on my platform.
@damienmg
Copy link
Member Author

damienmg commented Jun 3, 2018

The update to cargo.lock is actually addressing the problem we see in Travis at HEAD.

Copy link
Member

@acmcarther acmcarther left a comment

Choose a reason for hiding this comment

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

The change looks great! Thanks for fixing the broken master and cleaning up those warnings as well.

@@ -10,7 +10,10 @@ def {{workspace.gen_workspace_prefix}}_fetch_remote_crates():
name = "{{workspace.gen_workspace_prefix}}__{{crate.pkg_name | slugify | replace(from="-", to="_")}}__{{crate.pkg_version | slugify | replace(from="-", to="_")}}",
url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/{{crate.pkg_name}}/{{crate.pkg_name}}-{{crate.pkg_version}}.crate",
type = "tar.gz",
strip_prefix = "{{crate.pkg_name}}-{{crate.pkg_version}}",
{% if crate.sha256
Copy link
Member

Choose a reason for hiding this comment

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

Nit: use "{%-" to accomplish the same thing as you're accomplishing by splitting the tag.

Example: https://github.com/google/cargo-raze/blob/master/impl/src/templates/crate.BUILD.template#L23

Copy link
Member Author

Choose a reason for hiding this comment

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

Much nicer. Done!

@@ -272,6 +273,9 @@ impl<'config> MetadataFetcher for CargoInternalsMetadataFetcher<'config> {
features.insert(feature.clone(), features_or_dependencies.clone());
}

// Cargo use SHA256 for checksum so we can use them directly
let sha256 = package.manifest().summary().checksum().and_then(|x| Some(x.to_string()));
Copy link
Member

Choose a reason for hiding this comment

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

Two Nits:

s/and_then(|x| Some(x.to_string()))/map(ToString::to_string)

The and_then is only necessary when the mapping function yields an option. map is similar but without the option. ToString::to_string is the direct reference to the method (though |x| x.to_string() is totally fine as well).

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@damienmg
Copy link
Member Author

damienmg commented Jun 4, 2018

PTAL. Thanks for the review!

@acmcarther
Copy link
Member

This PR needs a followup. Not usre how I missed this in review, but you added a field into a struct that I technically don't control the definition of -- Metadata.{...} is controlled by cargo as it's what they emit from cargo metadata.

SerializedPackage:
https://github.com/rust-lang/cargo/blob/9c78c3a17ac4bc0c8b3b837095f60aa84d09c426/src/cargo/core/package.rs#L32-L49

When I throw the switch to use cargo metadata instead of the internals, the new sha256 field will always be empty. I think Cargo team might be open to accepting a PR that adds this to their output though. I'll followup in #57

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

2 participants