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

allow to override libname using version features #16

Closed
wants to merge 55 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
caad78b
run cargo fmt
Apr 30, 2020
a78bfac
use ? instead of deprecated try!
Apr 30, 2020
2c7f626
update error-chain dep
Apr 30, 2020
44460ad
update toml dep
Apr 30, 2020
321a308
fix toplevel_ref_arg clippy warning
Apr 30, 2020
e1fc36e
port to Rust 2018
Apr 30, 2020
50b1eac
allow to override lib name
Apr 30, 2020
34951b3
factor out has_feature()
Apr 30, 2020
9557e93
add feature-versions
Apr 30, 2020
07b8b70
disable PKG_CONFIG_ALLOW_SYSTEM_LIBS
Apr 30, 2020
af9be0f
move tests to the main crate
May 2, 2020
e198c6e
export lib include paths as env variable
May 1, 2020
bd0e27b
remove deny warnings
May 2, 2020
331bab3
stop relying on pkg-config to print cargo metadata
May 2, 2020
faab013
add env variables mock for tests
May 2, 2020
6133caa
allow user to override build flags using env variable
May 3, 2020
bb6a87a
use our own Library struct instead of pkg-config's
May 3, 2020
118982b
support NO_PKG_CONFIG env variables
May 3, 2020
e632535
add source field indicating the source of a library
May 6, 2020
aeea975
ensure that manually defined deps have at least one lib
May 6, 2020
b963e52
add ErrorKind::InvalidMetadata
May 6, 2020
3c2fcfe
add Config object to the API using builder pattern
May 6, 2020
f03845b
tests: factor out create_config()
May 6, 2020
bd4f969
add hooks to internally build libs
May 6, 2020
3499f24
fully replace error-chain by this-error
May 8, 2020
dfa2894
rename to system-deps
Jun 19, 2020
b03ec87
rename METADEPS_* env variables
Jun 19, 2020
1fb4e57
rename toml section
Jun 19, 2020
231e607
README: update
Jun 19, 2020
bc4b1e5
doc: sync with README
Jun 19, 2020
47a1c5d
Cargo: add documentation and readme
Jun 19, 2020
65d4da0
toml: move back to metadata section
Jun 19, 2020
5c5fafe
1.2.0
Jun 19, 2020
192e0b7
Cargo: update description
Jun 19, 2020
3585b22
README: update system-deps version
Jun 19, 2020
fe2892f
README: simplify doc
Jun 19, 2020
acf3e8f
improve doc
Jun 22, 2020
07900f3
doc: fix default BUILD_INTERNAL
Jun 22, 2020
e0ae62a
test: factor out test_build_internal()
Jun 22, 2020
1a6dcc7
pass lib name to build internal closure
Jun 22, 2020
9487145
add SYSTEM_DEPS_BUILD_INTERNAL env variable
Jun 22, 2020
a290841
ignore needless_doctest_main clippy warnings
Jun 22, 2020
22e6778
1.3.0
Jun 22, 2020
5aab5dd
pass real lib name to build internal closure
Jun 22, 2020
6d193fa
1.3.1
Jun 22, 2020
44d0397
README: fix a couple of typos
ao2 Jun 23, 2020
a22397f
add environment variable enum
Jun 23, 2020
2a54c93
tests: sort flags before comparing
Jun 23, 2020
c15d04a
trigger rebuild if system-deps env variables changed
Jun 23, 2020
0cb92ab
add LICENSE files
Jul 10, 2020
4b22eca
1.3.2
Jul 10, 2020
c19b181
update deps
Aug 27, 2020
64bfa04
change version features syntax
Oct 29, 2020
15a0590
generalize feature overrides
Oct 29, 2020
70c5825
allow to override libname using version features
Oct 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: factor out test_build_internal()
  • Loading branch information
Guillaume Desmottes committed Jun 22, 2020
commit e0ae62a12eb12fbd8ac1615b2a6e038946550e3f
96 changes: 36 additions & 60 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,113 +350,89 @@ fn override_no_pkg_config_error() {
);
}

#[test]
fn build_internal_always() {
fn test_build_internal(
path: &'static str,
env: Vec<(&'static str, &'static str)>,
lib: &'static str,
) -> Result<(HashMap<String, Library>, bool), (Error, bool)> {
let called = Rc::new(Cell::new(false));
let called_clone = called.clone();
let config = create_config(
"toml-good",
vec![("SYSTEM_DEPS_TESTLIB_BUILD_INTERNAL", "always")],
)
.add_build_internal("testlib", move |version| {
let config = create_config(path, env).add_build_internal(lib, move |version| {
called_clone.replace(true);
assert_eq!(version, "1");
let lib = pkg_config::Config::new()
let mut lib = pkg_config::Config::new()
.print_system_libs(false)
.cargo_metadata(false)
.probe("testlib")
.probe(lib)
.unwrap();
lib.version = version.to_string();
Ok(Library::from_pkg_config(lib))
});

let (libraries, _flags) = config.probe_full().unwrap();
match config.probe_full() {
Ok((libraries, _flags)) => Ok((libraries, called.get())),
Err(e) => Err((e, called.get())),
}
}

assert_eq!(called.get(), true);
#[test]
fn build_internal_always() {
let (libraries, called) = test_build_internal(
"toml-good",
vec![("SYSTEM_DEPS_TESTLIB_BUILD_INTERNAL", "always")],
"testlib",
)
.unwrap();

assert_eq!(called, true);
assert!(libraries.get("testlib").is_some());
}

#[test]
fn build_internal_auto_not_called() {
// No need to build the lib as the existing version is new enough
let called = Rc::new(Cell::new(false));
let called_clone = called.clone();
let config = create_config(
let (libraries, called) = test_build_internal(
"toml-good",
vec![("SYSTEM_DEPS_TESTLIB_BUILD_INTERNAL", "auto")],
"testlib",
)
.add_build_internal("testlib", move |_version| {
called_clone.replace(true);
let lib = pkg_config::Config::new()
.print_system_libs(false)
.cargo_metadata(false)
.probe("testlib")
.unwrap();
Ok(Library::from_pkg_config(lib))
});

let (libraries, _flags) = config.probe_full().unwrap();
.unwrap();

assert_eq!(called.get(), false);
assert_eq!(called, false);
assert!(libraries.get("testlib").is_some());
}

#[test]
fn build_internal_auto_called() {
// Version 5 is not available so we should try building
let called = Rc::new(Cell::new(false));
let called_clone = called.clone();
let config = create_config(
let (libraries, called) = test_build_internal(
"toml-feature-versions",
vec![
("SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL", "auto"),
("CARGO_FEATURE_V5", ""),
],
"testdata",
)
.add_build_internal("testdata", move |version| {
called_clone.replace(true);
assert_eq!(version, "5");
let mut lib = pkg_config::Config::new()
.print_system_libs(false)
.cargo_metadata(false)
.probe("testdata")
.unwrap();
lib.version = "5.0".to_string();
Ok(Library::from_pkg_config(lib))
});

let (libraries, _flags) = config.probe_full().unwrap();
.unwrap();

assert_eq!(called.get(), true);
assert_eq!(called, true);
assert!(libraries.get("testdata").is_some());
}

#[test]
fn build_internal_auto_never() {
// Version 5 is not available but we forbid to build the lib
let called = Rc::new(Cell::new(false));
let called_clone = called.clone();
let config = create_config(
let (err, called) = test_build_internal(
"toml-feature-versions",
vec![
("SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL", "never"),
("CARGO_FEATURE_V5", ""),
],
"testdata",
)
.add_build_internal("testdata", move |version| {
called_clone.replace(true);
assert_eq!(version, "5");
let lib = pkg_config::Config::new()
.print_system_libs(false)
.cargo_metadata(false)
.probe("testdata")
.unwrap();
Ok(Library::from_pkg_config(lib))
});
.unwrap_err();

let err = config.probe_full().unwrap_err();
assert!(matches!(err, Error::PkgConfig(..)));

assert_eq!(called.get(), false);
assert_eq!(called, false);
}

#[test]
Expand Down