I'd love to hear suggestions as to how to debug my build.rs
script which fails on travis-ci. It's relatively simple. One part does some C compiling with the gcc
crate (and probably works fine), but the other bit tries to use git to create a module storing version information. It works fine for me (on two different versions of Debian), but fails on travis. Here is the code:
use std::process::Command;
use std::io::{Write};
fn main() {
let mut stat = Command::new("git")
.args(&["describe", "--dirty"])
.output().expect("unable to call git describe?");
if !stat.status.success() || stat.stdout.len() < 5 {
stat = Command::new("git")
.args(&["revparse", "HEAD"])
.output().expect("unable to call git revparse?");
}
let mut version = stat.stdout;
if version.len() > 1 {
let newlen = version.len()-1;
version.truncate(newlen);
}
if version.len() < 5 {
version.extend(b"(unknown version)");
}
// The following attempts to atomically create version.rs, in case
// two cargos are running simultaneously. Rust does not document
// rename as atomic, but on posix systems it currently is.
{
let mut file = std::fs::File::create("src/version.rs~").expect("error creating version.rs");
file.write(b"/// The version of fac\npub static VERSION: &'static str = \"")
.expect("error writing to file");
file.write(&version).expect("error writing to file");
file.write(b"\";\n").expect("error writing to file");
}
std::fs::rename("src/version.rs~", "src/version.rs")
.expect("failed to rename version.rs");
}
Travis fails with:
thread 'main' panicked at 'unable to call git describe?: Error { repr: Os { code: 2, message: "No such file or directory" } }', /checkout/src/libcore/result.rs:859
but I'm puzzled. I've verified that git is in the path, so I can't see what file or directory git describe
could have failed to find. Any suggestions as to what might be wrong? Or can any of you suggest a better way to extract git version information for a detailed --version
flag?
Here is the travis output:
and a link to the actual build script I used (which has a few debug prints):
https://github.com/droundy/fac/blob/master/build.rs