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

Migrate to cargo 0.42 for Cargo.lock v2 support #5

Closed
wants to merge 4 commits into from

Conversation

str4d
Copy link
Contributor

@str4d str4d commented Mar 4, 2021

Closes #4.

@str4d
Copy link
Contributor Author

str4d commented Mar 4, 2021

I've also locally updated all dependencies beyond what is necessary to fix #4. The resulting diff vs this PR is:

diff --git a/Cargo.toml b/Cargo.toml
index 33375db..8422fef 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,11 +10,11 @@ repository = "https://github.com/Henning-K/cargo-authors"
 version = "0.5.0"
 
 [dependencies]
-cargo = "0.42"
+anyhow = "1"
+cargo = "0.51"
 docopt = "1.1"
-failure = "0.1"
 lazy_static = "1.4.0"
 regex = "1.3"
-ripemd160 = "0.8.0"
+ripemd160 = "0.9"
 serde = { version="1.0", features=["derive"] }
 serde_json = "1.0"
diff --git a/src/main.rs b/src/main.rs
index 9399e60..b054a77 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,13 +1,12 @@
 extern crate cargo;
+use cargo::core::compiler::RustcTargetData;
+use cargo::core::resolver::{ForceAllTargets, HasDevUnits};
 use cargo::core::Workspace;
 use cargo::core::{resolver::ResolveOpts, shell::Shell};
 use cargo::ops::{self, Packages};
 use cargo::util::{CargoResult, CliError, Config};
 use cargo::CliResult;
 
-#[macro_use]
-extern crate failure;
-
 extern crate regex;
 use regex::Regex;
 
@@ -89,8 +88,17 @@ impl<'a> DependencyAccumulator<'a> {
         // here starts the code ripped from cargo::ops::cargo_output_metadata.rs
         // because the visibility of the result's (ExportInfo) members returned from
         // cargo::ops::metadata_full()/output_metadata() hinders evaluation
+        let target_data = RustcTargetData::new(&ws, &[])?;
         let specs = Packages::All.to_package_id_specs(&ws)?;
-        let deps = ops::resolve_ws_with_opts(&ws, ResolveOpts::everything(), &specs)?;
+        let deps = ops::resolve_ws_with_opts(
+            &ws,
+            &target_data,
+            &[],
+            &ResolveOpts::everything(),
+            &specs,
+            HasDevUnits::Yes,
+            ForceAllTargets::Yes,
+        )?;
         let package_set = deps.pkg_set;
         // here ends the ripped code
 
@@ -159,11 +167,12 @@ fn real_main(flags: Flags, config: &Config) -> CliResult {
         Err(ref e) => {
             println!("error: {}", e);
 
-            for e in e.iter_causes() {
+            for e in e.chain() {
                 println!("caused by: {}", e);
             }
 
-            println!("backtrace: {:?}", e.backtrace());
+            // Nightly-only.
+            // println!("backtrace: {:?}", e.backtrace());
 
             ::std::process::exit(1);
         }
@@ -205,10 +214,7 @@ fn main() {
         let args: Vec<_> = env::args_os()
             .map(|s| {
                 s.into_string().map_err(|s| {
-                    CliError::new(
-                        failure::format_err!("invalid argument detected: {:?}", s),
-                        1334,
-                    )
+                    CliError::new(anyhow::anyhow!("invalid argument detected: {:?}", s), 1334)
                 })
             })
             .collect::<Result<_, CliError>>()?;

LMK if you'd like me to add that to this PR.

@str4d str4d mentioned this pull request Mar 4, 2021
@str4d
Copy link
Contributor Author

str4d commented Mar 4, 2021

Opened #6 with the above, and another update. Feel free to merge that PR instead of this if you prefer.

@Henning-K
Copy link
Owner

Opened #6 with the above, and another update. Feel free to merge that PR instead of this if you prefer.

Merged #6 instead, so closing this one.

@Henning-K Henning-K closed this Mar 4, 2021
@str4d str4d deleted the 4-lockfile-v2 branch March 4, 2021 13:52
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.

Lockfile parsing fails with "invalid serialized PackageId for key package.dependencies"
2 participants