diff options
author | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
commit | 1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch) | |
tree | 7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/cc/src/bin | |
parent | 5ecd8cf2cba827454317368b68571df0d13d7842 (diff) | |
download | fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip |
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/cc/src/bin')
-rw-r--r-- | vendor/cc/src/bin/gcc-shim.rs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/cc/src/bin/gcc-shim.rs b/vendor/cc/src/bin/gcc-shim.rs new file mode 100644 index 0000000..e5b5372 --- /dev/null +++ b/vendor/cc/src/bin/gcc-shim.rs @@ -0,0 +1,70 @@ +#![cfg_attr(test, allow(dead_code))] + +use std::env; +use std::fs::File; +use std::io::{self, prelude::*}; +use std::path::PathBuf; + +fn main() { + let mut args = env::args(); + let program = args.next().expect("Unexpected empty args"); + + let out_dir = PathBuf::from( + env::var_os("GCCTEST_OUT_DIR") + .unwrap_or_else(|| panic!("{}: GCCTEST_OUT_DIR not found", program)), + ); + + // Find the first nonexistent candidate file to which the program's args can be written. + let candidate = (0..).find_map(|i| { + let candidate = out_dir.join(format!("out{}", i)); + + if candidate.exists() { + // If the file exists, commands have already run. Try again. + None + } else { + Some(candidate) + } + }).unwrap_or_else(|| panic!("Cannot find the first nonexistent candidate file to which the program's args can be written under out_dir '{}'", out_dir.display())); + + // Create a file and record the args passed to the command. + let f = File::create(&candidate).unwrap_or_else(|e| { + panic!( + "{}: can't create candidate: {}, error: {}", + program, + candidate.display(), + e + ) + }); + let mut f = io::BufWriter::new(f); + + (|| { + for arg in args { + writeln!(f, "{}", arg)?; + } + + f.flush()?; + + let mut f = f.into_inner()?; + f.flush()?; + f.sync_all() + })() + .unwrap_or_else(|e| { + panic!( + "{}: can't write to candidate: {}, error: {}", + program, + candidate.display(), + e + ) + }); + + // Create a file used by some tests. + let path = &out_dir.join("libfoo.a"); + File::create(path).unwrap_or_else(|e| { + panic!( + "{}: can't create libfoo.a: {}, error: {}", + program, + path.display(), + e + ) + }); +} |