Add info
command to help get some information
This commit is contained in:
parent
0a4b0af141
commit
5c6cdf5ab6
@ -121,6 +121,9 @@ pub struct ConfigInfo {
|
||||
pub gcc_path: String,
|
||||
config_file: Option<String>,
|
||||
cg_gcc_path: Option<PathBuf>,
|
||||
// Needed for the `info` command which doesn't want to actually download the lib if needed,
|
||||
// just to set the `gcc_path` field to display it.
|
||||
pub no_download: bool,
|
||||
}
|
||||
|
||||
impl ConfigInfo {
|
||||
@ -204,7 +207,7 @@ impl ConfigInfo {
|
||||
return Err(format!(
|
||||
"{}: invalid commit hash `{}`",
|
||||
commit_hash_file.display(),
|
||||
commit
|
||||
commit,
|
||||
));
|
||||
}
|
||||
let output_dir = output_dir.join(commit);
|
||||
@ -217,9 +220,17 @@ impl ConfigInfo {
|
||||
)
|
||||
})?;
|
||||
}
|
||||
let output_dir = output_dir.canonicalize().map_err(|err| {
|
||||
format!(
|
||||
"Failed to get absolute path of `{}`: {:?}",
|
||||
output_dir.display(),
|
||||
err
|
||||
)
|
||||
})?;
|
||||
|
||||
let libgccjit_so_name = "libgccjit.so";
|
||||
let libgccjit_so = output_dir.join(libgccjit_so_name);
|
||||
if !libgccjit_so.is_file() {
|
||||
if !libgccjit_so.is_file() && !self.no_download {
|
||||
// Download time!
|
||||
let tempfile_name = "libgccjit.so.download";
|
||||
let tempfile = output_dir.join(tempfile_name);
|
||||
@ -283,28 +294,12 @@ impl ConfigInfo {
|
||||
|
||||
println!("Downloaded libgccjit.so version {} successfully!", commit);
|
||||
create_symlink(
|
||||
&libgccjit_so.canonicalize().map_err(|err| {
|
||||
format!(
|
||||
"Failed to get absolute path of `{}`: {:?}",
|
||||
libgccjit_so.display(),
|
||||
err,
|
||||
)
|
||||
})?,
|
||||
&libgccjit_so,
|
||||
output_dir.join(&format!("{}.0", libgccjit_so_name)),
|
||||
)?;
|
||||
}
|
||||
|
||||
self.gcc_path = output_dir
|
||||
.canonicalize()
|
||||
.map_err(|err| {
|
||||
format!(
|
||||
"Failed to get absolute path of `{}`: {:?}",
|
||||
output_dir.display(),
|
||||
err
|
||||
)
|
||||
})?
|
||||
.display()
|
||||
.to_string();
|
||||
self.gcc_path = output_dir.display().to_string();
|
||||
println!("Using `{}` as path for libgccjit", self.gcc_path);
|
||||
Ok(())
|
||||
}
|
||||
|
19
build_system/src/info.rs
Normal file
19
build_system/src/info.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use crate::config::ConfigInfo;
|
||||
|
||||
pub fn run() -> Result<(), String> {
|
||||
let mut config = ConfigInfo::default();
|
||||
|
||||
// We skip binary name and the `info` command.
|
||||
let mut args = std::env::args().skip(2);
|
||||
while let Some(arg) = args.next() {
|
||||
if arg == "--help" {
|
||||
println!("Display the path where the libgccjit will be located");
|
||||
return Ok(());
|
||||
}
|
||||
config.parse_argument(&arg, &mut args)?;
|
||||
}
|
||||
config.no_download = true;
|
||||
config.setup_gcc_path()?;
|
||||
println!("{}", config.gcc_path);
|
||||
Ok(())
|
||||
}
|
@ -5,6 +5,7 @@ mod build;
|
||||
mod cargo;
|
||||
mod clean;
|
||||
mod config;
|
||||
mod info;
|
||||
mod prepare;
|
||||
mod rustc_info;
|
||||
mod test;
|
||||
@ -29,6 +30,7 @@ Available commands for build_system:
|
||||
prepare : Run prepare command
|
||||
build : Run build command
|
||||
test : Run test command
|
||||
info: : Run info command
|
||||
--help : Show this message"
|
||||
);
|
||||
}
|
||||
@ -39,6 +41,7 @@ pub enum Command {
|
||||
Prepare,
|
||||
Build,
|
||||
Test,
|
||||
Info,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -52,6 +55,7 @@ fn main() {
|
||||
Some("prepare") => Command::Prepare,
|
||||
Some("build") => Command::Build,
|
||||
Some("test") => Command::Test,
|
||||
Some("info") => Command::Info,
|
||||
Some("--help") => {
|
||||
usage();
|
||||
process::exit(0);
|
||||
@ -70,6 +74,7 @@ fn main() {
|
||||
Command::Prepare => prepare::run(),
|
||||
Command::Build => build::run(),
|
||||
Command::Test => test::run(),
|
||||
Command::Info => info::run(),
|
||||
} {
|
||||
eprintln!("Command failed to run: {e}");
|
||||
process::exit(1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user