Fix for finding dependency version in lockfile v2

With lockfile v2 a version is not required for dependencies if the lock
file only contains a single entry for a specified crate.  However, without
a version present, at a later stage, a dependant crate will not be found
in the metadata cache which causes the dependency to be ignored completely.
This commit tries to infer the version of dependant crates when the
version specifier is missing from the contents of the lockfile.
This commit is contained in:
Bas Zalmstra 2020-01-03 11:59:38 +01:00 committed by Emilio Cobos Álvarez
parent 3639d6b23a
commit 8fabbfa4b5
14 changed files with 166 additions and 0 deletions

View File

@ -135,6 +135,26 @@ impl Cargo {
.map(|dep| {
let (dep_name, dep_version) = parse_dep_string(dep);
// If a version was not specified find the only package with the name of the dependency
let dep_version = dep_version.or_else(|| {
let mut versions = self.metadata.packages.iter().filter_map(|package| {
if package.name_and_version.name != dep_name {
return None;
}
package.name_and_version.version.as_ref().map(|v| v.as_str())
});
// If the iterator contains more items, meaning multiple versions of the same
// package are present, warn! amd abort.
let version = versions.next();
if versions.next().is_none() {
version
} else {
warn!("when looking for a version for package {}, multiple versions where found", dep_name);
None
}
});
// Try to find the cfgs in the Cargo.toml
let cfg = self
.metadata

View File

@ -0,0 +1,11 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct dep_struct {
uint32_t x;
double y;
} dep_struct;
uint32_t get_x(const dep_struct *dep_struct);

View File

@ -0,0 +1,19 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct dep_struct {
uint32_t x;
double y;
} dep_struct;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
uint32_t get_x(const dep_struct *dep_struct);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

View File

@ -0,0 +1,11 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct {
uint32_t x;
double y;
} dep_struct;
uint32_t get_x(const dep_struct *dep_struct);

View File

@ -0,0 +1,19 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct {
uint32_t x;
double y;
} dep_struct;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
uint32_t get_x(const dep_struct *dep_struct);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

View File

@ -0,0 +1,15 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <new>
struct dep_struct {
uint32_t x;
double y;
};
extern "C" {
uint32_t get_x(const dep_struct *dep_struct);
} // extern "C"

View File

@ -0,0 +1,11 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
struct dep_struct {
uint32_t x;
double y;
};
uint32_t get_x(const struct dep_struct *dep_struct);

View File

@ -0,0 +1,19 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
struct dep_struct {
uint32_t x;
double y;
};
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
uint32_t get_x(const struct dep_struct *dep_struct);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

12
tests/rust/dep_v2/Cargo.lock generated Normal file
View File

@ -0,0 +1,12 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "dep"
version = "0.1.0"
[[package]]
name = "expand-dep"
version = "0.1.0"
dependencies = [
"dep",
]

View File

@ -0,0 +1,8 @@
[package]
name = "expand-dep"
version = "0.1.0"
authors = ["cbindgen"]
edition = "2018"
[dependencies]
dep = { path = "dep" }

View File

@ -0,0 +1,3 @@
[parse]
parse_deps = true
include = ["dep"]

View File

@ -0,0 +1,7 @@
[package]
name = "dep"
version = "0.1.0"
authors = ["cbindgen"]
edition = "2018"
[dependencies]

View File

@ -0,0 +1,5 @@
#[repr(C)]
pub struct dep_struct {
pub x: u32,
pub y: f64,
}

View File

@ -0,0 +1,6 @@
use dep::dep_struct;
#[no_mangle]
pub unsafe extern "C" fn get_x(dep_struct: *const dep_struct) -> u32 {
dep_struct.read().x
}