Skip to content

Commit 5c6cdf5

Browse files
Add info command to help get some information
1 parent 0a4b0af commit 5c6cdf5

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

build_system/src/config.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ pub struct ConfigInfo {
121121
pub gcc_path: String,
122122
config_file: Option<String>,
123123
cg_gcc_path: Option<PathBuf>,
124+
// Needed for the `info` command which doesn't want to actually download the lib if needed,
125+
// just to set the `gcc_path` field to display it.
126+
pub no_download: bool,
124127
}
125128

126129
impl ConfigInfo {
@@ -204,7 +207,7 @@ impl ConfigInfo {
204207
return Err(format!(
205208
"{}: invalid commit hash `{}`",
206209
commit_hash_file.display(),
207-
commit
210+
commit,
208211
));
209212
}
210213
let output_dir = output_dir.join(commit);
@@ -217,9 +220,17 @@ impl ConfigInfo {
217220
)
218221
})?;
219222
}
223+
let output_dir = output_dir.canonicalize().map_err(|err| {
224+
format!(
225+
"Failed to get absolute path of `{}`: {:?}",
226+
output_dir.display(),
227+
err
228+
)
229+
})?;
230+
220231
let libgccjit_so_name = "libgccjit.so";
221232
let libgccjit_so = output_dir.join(libgccjit_so_name);
222-
if !libgccjit_so.is_file() {
233+
if !libgccjit_so.is_file() && !self.no_download {
223234
// Download time!
224235
let tempfile_name = "libgccjit.so.download";
225236
let tempfile = output_dir.join(tempfile_name);
@@ -283,28 +294,12 @@ impl ConfigInfo {
283294

284295
println!("Downloaded libgccjit.so version {} successfully!", commit);
285296
create_symlink(
286-
&libgccjit_so.canonicalize().map_err(|err| {
287-
format!(
288-
"Failed to get absolute path of `{}`: {:?}",
289-
libgccjit_so.display(),
290-
err,
291-
)
292-
})?,
297+
&libgccjit_so,
293298
output_dir.join(&format!("{}.0", libgccjit_so_name)),
294299
)?;
295300
}
296301

297-
self.gcc_path = output_dir
298-
.canonicalize()
299-
.map_err(|err| {
300-
format!(
301-
"Failed to get absolute path of `{}`: {:?}",
302-
output_dir.display(),
303-
err
304-
)
305-
})?
306-
.display()
307-
.to_string();
302+
self.gcc_path = output_dir.display().to_string();
308303
println!("Using `{}` as path for libgccjit", self.gcc_path);
309304
Ok(())
310305
}

build_system/src/info.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::config::ConfigInfo;
2+
3+
pub fn run() -> Result<(), String> {
4+
let mut config = ConfigInfo::default();
5+
6+
// We skip binary name and the `info` command.
7+
let mut args = std::env::args().skip(2);
8+
while let Some(arg) = args.next() {
9+
if arg == "--help" {
10+
println!("Display the path where the libgccjit will be located");
11+
return Ok(());
12+
}
13+
config.parse_argument(&arg, &mut args)?;
14+
}
15+
config.no_download = true;
16+
config.setup_gcc_path()?;
17+
println!("{}", config.gcc_path);
18+
Ok(())
19+
}

build_system/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod build;
55
mod cargo;
66
mod clean;
77
mod config;
8+
mod info;
89
mod prepare;
910
mod rustc_info;
1011
mod test;
@@ -29,6 +30,7 @@ Available commands for build_system:
2930
prepare : Run prepare command
3031
build : Run build command
3132
test : Run test command
33+
info: : Run info command
3234
--help : Show this message"
3335
);
3436
}
@@ -39,6 +41,7 @@ pub enum Command {
3941
Prepare,
4042
Build,
4143
Test,
44+
Info,
4245
}
4346

4447
fn main() {
@@ -52,6 +55,7 @@ fn main() {
5255
Some("prepare") => Command::Prepare,
5356
Some("build") => Command::Build,
5457
Some("test") => Command::Test,
58+
Some("info") => Command::Info,
5559
Some("--help") => {
5660
usage();
5761
process::exit(0);
@@ -70,6 +74,7 @@ fn main() {
7074
Command::Prepare => prepare::run(),
7175
Command::Build => build::run(),
7276
Command::Test => test::run(),
77+
Command::Info => info::run(),
7378
} {
7479
eprintln!("Command failed to run: {e}");
7580
process::exit(1);

0 commit comments

Comments
 (0)