This commit is contained in:
Sebastian Miasojed
2024-11-07 15:15:52 +01:00
parent 4f6debcbe3
commit d260472330
4 changed files with 39 additions and 24 deletions
+14 -12
View File
@@ -22,7 +22,7 @@ impl Process for NativeProcess {
let mut stdin = std::io::stdin();
let mut stdout = std::io::stdout();
let mut stderr = std::io::stderr();
let mut buffer = Vec::with_capacity(16384);
match input_file {
Some(ins) => {
@@ -39,7 +39,7 @@ impl Process for NativeProcess {
}
}
}
let input: Input = revive_common::deserialize_from_slice(buffer.as_slice())?;
let result = input.contract.compile(
input.project,
@@ -47,7 +47,7 @@ impl Process for NativeProcess {
input.include_metadata_hash,
input.debug_config,
);
match result {
Ok(build) => {
let output = Output::new(build);
@@ -66,16 +66,16 @@ impl Process for NativeProcess {
}
}
}
/// Runs this process recursively to compile a single contract.
fn call(input: Input) -> anyhow::Result<Output> {
let input_json = serde_json::to_vec(&input).expect("Always valid");
let executable = match EXECUTABLE.get() {
Some(executable) => executable.to_owned(),
None => std::env::current_exe()?,
};
let mut command = Command::new(executable.as_path());
command.stdin(std::process::Stdio::piped());
command.stdout(std::process::Stdio::piped());
@@ -84,7 +84,7 @@ impl Process for NativeProcess {
let process = command.spawn().map_err(|error| {
anyhow::anyhow!("{:?} subprocess spawning error: {:?}", executable, error)
})?;
#[cfg(debug_assertions)]
if let Some(dbg_config) = &input.debug_config {
dbg_config
@@ -97,13 +97,15 @@ impl Process for NativeProcess {
)
})?;
}
process
.stdin
.as_ref()
.ok_or_else(|| anyhow::anyhow!("{:?} stdin getting error", executable))?
.write_all(input_json.as_slice())
.map_err(|error| anyhow::anyhow!("{:?} stdin writing error: {:?}", executable, error))?;
.map_err(|error| {
anyhow::anyhow!("{:?} stdin writing error: {:?}", executable, error)
})?;
let output = process.wait_with_output().map_err(|error| {
anyhow::anyhow!("{:?} subprocess output error: {:?}", executable, error)
})?;
@@ -113,9 +115,9 @@ impl Process for NativeProcess {
String::from_utf8_lossy(output.stderr.as_slice()).to_string(),
);
}
let output: Output =
revive_common::deserialize_from_slice(output.stdout.as_slice()).map_err(|error| {
let output: Output = revive_common::deserialize_from_slice(output.stdout.as_slice())
.map_err(|error| {
anyhow::anyhow!(
"{:?} subprocess output parsing error: {}",
executable,