Skip to content

Commit

Permalink
do not restrict version range when probing --modversion
Browse files Browse the repository at this point in the history
this should fix the crate with a pkgconf 2.0.0 breaking change
  • Loading branch information
selfisekai committed Aug 4, 2023
1 parent 576f550 commit 4ea97bc
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub fn target_supported() -> bool {
pub fn get_variable(package: &str, variable: &str) -> Result<String, Error> {
let arg = format!("--variable={}", variable);
let cfg = Config::new();
let out = cfg.run(package, &[&arg])?;
let out = cfg.run(package, &[&arg], false)?;
Ok(str::from_utf8(&out).unwrap().trim_end().to_owned())
}

Expand Down Expand Up @@ -393,7 +393,7 @@ impl Config {
let mut library = Library::new();

let output = self
.run(name, &["--libs", "--cflags"])
.run(name, &["--libs", "--cflags"], true)
.map_err(|e| match e {
Error::Failure { command, output } => Error::ProbeFailure {
name: name.to_owned(),
Expand All @@ -404,7 +404,7 @@ impl Config {
})?;
library.parse_libs_cflags(name, &output, self);

let output = self.run(name, &["--modversion"])?;
let output = self.run(name, &["--modversion"], false)?;
library.parse_modversion(str::from_utf8(&output).unwrap());

Ok(library)
Expand Down Expand Up @@ -476,7 +476,7 @@ impl Config {
self.statik.unwrap_or_else(|| self.infer_static(name))
}

fn run(&self, name: &str, args: &[&str]) -> Result<Vec<u8>, Error> {
fn run(&self, name: &str, args: &[&str], restrict_version: bool) -> Result<Vec<u8>, Error> {
let pkg_config_exe = self.targetted_env_var("PKG_CONFIG");
let fallback_exe = if pkg_config_exe.is_none() {
Some(OsString::from("pkgconf"))
Expand All @@ -485,11 +485,11 @@ impl Config {
};
let exe = pkg_config_exe.unwrap_or_else(|| OsString::from("pkg-config"));

let mut cmd = self.command(exe, name, args);
let mut cmd = self.command(exe, name, args, restrict_version);

match cmd.output().or_else(|e| {
if let Some(exe) = fallback_exe {
self.command(exe, name, args).output()
self.command(exe, name, args, restrict_version).output()
} else {
Err(e)
}
Expand All @@ -511,7 +511,7 @@ impl Config {
}
}

fn command(&self, exe: OsString, name: &str, args: &[&str]) -> Command {
fn command(&self, exe: OsString, name: &str, args: &[&str], restrict_version: bool) -> Command {
let mut cmd = Command::new(exe);
if self.is_static(name) {
cmd.arg("--static");
Expand All @@ -534,23 +534,25 @@ impl Config {
cmd.env("PKG_CONFIG_ALLOW_SYSTEM_CFLAGS", "1");
}
cmd.arg(name);
match self.min_version {
Bound::Included(ref version) => {
cmd.arg(&format!("{} >= {}", name, version));
}
Bound::Excluded(ref version) => {
cmd.arg(&format!("{} > {}", name, version));
}
_ => (),
}
match self.max_version {
Bound::Included(ref version) => {
cmd.arg(&format!("{} <= {}", name, version));
if restrict_version {
match self.min_version {
Bound::Included(ref version) => {
cmd.arg(&format!("{} >= {}", name, version));
}
Bound::Excluded(ref version) => {
cmd.arg(&format!("{} > {}", name, version));
}
_ => (),
}
Bound::Excluded(ref version) => {
cmd.arg(&format!("{} < {}", name, version));
match self.max_version {
Bound::Included(ref version) => {
cmd.arg(&format!("{} <= {}", name, version));
}
Bound::Excluded(ref version) => {
cmd.arg(&format!("{} < {}", name, version));
}
_ => (),
}
_ => (),
}
cmd
}
Expand Down

0 comments on commit 4ea97bc

Please sign in to comment.