summaryrefslogtreecommitdiffstats
path: root/vendor/pkg-config/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/pkg-config/src/lib.rs')
-rw-r--r--vendor/pkg-config/src/lib.rs89
1 files changed, 52 insertions, 37 deletions
diff --git a/vendor/pkg-config/src/lib.rs b/vendor/pkg-config/src/lib.rs
index e9395be46..3653032e8 100644
--- a/vendor/pkg-config/src/lib.rs
+++ b/vendor/pkg-config/src/lib.rs
@@ -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 = run(cfg.command(package, &[&arg]))?;
+ let out = cfg.run(package, &[&arg])?;
Ok(str::from_utf8(&out).unwrap().trim_end().to_owned())
}
@@ -392,17 +392,19 @@ impl Config {
let mut library = Library::new();
- let output = run(self.command(name, &["--libs", "--cflags"])).map_err(|e| match e {
- Error::Failure { command, output } => Error::ProbeFailure {
- name: name.to_owned(),
- command,
- output,
- },
- other => other,
- })?;
+ let output = self
+ .run(name, &["--libs", "--cflags"])
+ .map_err(|e| match e {
+ Error::Failure { command, output } => Error::ProbeFailure {
+ name: name.to_owned(),
+ command,
+ output,
+ },
+ other => other,
+ })?;
library.parse_libs_cflags(name, &output, self);
- let output = run(self.command(name, &["--modversion"]))?;
+ let output = self.run(name, &["--modversion"])?;
library.parse_modversion(str::from_utf8(&output).unwrap());
Ok(library)
@@ -444,7 +446,7 @@ impl Config {
match (env::var("TARGET"), env::var("HOST")) {
(Ok(target), Ok(host)) => {
let kind = if host == target { "HOST" } else { "TARGET" };
- let target_u = target.replace("-", "_");
+ let target_u = target.replace('-', "_");
self.env_var_os(&format!("{}_{}", var_base, target))
.or_else(|| self.env_var_os(&format!("{}_{}", var_base, target_u)))
@@ -474,10 +476,42 @@ impl Config {
self.statik.unwrap_or_else(|| self.infer_static(name))
}
- fn command(&self, name: &str, args: &[&str]) -> Command {
- let exe = self
- .targetted_env_var("PKG_CONFIG")
- .unwrap_or_else(|| OsString::from("pkg-config"));
+ fn run(&self, name: &str, args: &[&str]) -> 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"))
+ } else {
+ None
+ };
+ let exe = pkg_config_exe.unwrap_or_else(|| OsString::from("pkg-config"));
+
+ let mut cmd = self.command(exe, name, args);
+
+ match cmd.output().or_else(|e| {
+ if let Some(exe) = fallback_exe {
+ self.command(exe, name, args).output()
+ } else {
+ Err(e)
+ }
+ }) {
+ Ok(output) => {
+ if output.status.success() {
+ Ok(output.stdout)
+ } else {
+ Err(Error::Failure {
+ command: format!("{:?}", cmd),
+ output,
+ })
+ }
+ }
+ Err(cause) => Err(Error::Command {
+ command: format!("{:?}", cmd),
+ cause,
+ }),
+ }
+ }
+
+ fn command(&self, exe: OsString, name: &str, args: &[&str]) -> Command {
let mut cmd = Command::new(exe);
if self.is_static(name) {
cmd.arg("--static");
@@ -768,8 +802,8 @@ impl Library {
}
}
- let mut linker_options = words.iter().filter(|arg| arg.starts_with("-Wl,"));
- while let Some(option) = linker_options.next() {
+ let linker_options = words.iter().filter(|arg| arg.starts_with("-Wl,"));
+ for option in linker_options {
let mut pop = false;
let mut ld_option = vec![];
for subopt in option[4..].split(',') {
@@ -795,7 +829,7 @@ impl Library {
}
fn parse_modversion(&mut self, output: &str) {
- self.version.push_str(output.lines().nth(0).unwrap().trim());
+ self.version.push_str(output.lines().next().unwrap().trim());
}
}
@@ -815,25 +849,6 @@ fn is_static_available(name: &str, system_roots: &[PathBuf], dirs: &[PathBuf]) -
})
}
-fn run(mut cmd: Command) -> Result<Vec<u8>, Error> {
- match cmd.output() {
- Ok(output) => {
- if output.status.success() {
- Ok(output.stdout)
- } else {
- Err(Error::Failure {
- command: format!("{:?}", cmd),
- output,
- })
- }
- }
- Err(cause) => Err(Error::Command {
- command: format!("{:?}", cmd),
- cause,
- }),
- }
-}
-
/// Split output produced by pkg-config --cflags and / or --libs into separate flags.
///
/// Backslash in output is used to preserve literal meaning of following byte. Different words are