|
| 1 | +use crate::build::compile::get_runtime_path_args; |
1 | 2 | use crate::build::packages;
|
2 | 3 | use crate::helpers::StrippedVerbatimPath;
|
| 4 | +use crate::project_context::ProjectContext; |
3 | 5 | use ahash::AHashSet;
|
| 6 | +use anyhow::{Result, anyhow}; |
4 | 7 | use std::fs::File;
|
5 | 8 | use std::io::Write;
|
6 | 9 | use std::path::Path;
|
7 | 10 | use std::path::PathBuf;
|
8 | 11 | use std::process::Command;
|
9 |
| - |
10 | 12 | // Namespaces work like the following: The build system will generate a file
|
11 | 13 | // called `MyModule.mlmap` which contains all modules that are in the namespace
|
12 | 14 | //
|
@@ -51,20 +53,47 @@ pub fn gen_mlmap(
|
51 | 53 | path
|
52 | 54 | }
|
53 | 55 |
|
54 |
| -pub fn compile_mlmap(package: &packages::Package, namespace: &str, bsc_path: &Path) { |
| 56 | +pub fn compile_mlmap( |
| 57 | + project_context: &ProjectContext, |
| 58 | + package: &packages::Package, |
| 59 | + namespace: &str, |
| 60 | + bsc_path: &Path, |
| 61 | +) -> Result<()> { |
55 | 62 | let build_path_abs = package.get_build_path();
|
56 | 63 | let mlmap_name = format!("{namespace}.mlmap");
|
57 |
| - let args = vec!["-w", "-49", "-color", "always", "-no-alias-deps", &mlmap_name]; |
| 64 | + let mut args: Vec<String> = vec![]; |
| 65 | + // include `-runtime-path` arg |
| 66 | + args.extend(get_runtime_path_args(&package.config, project_context)?); |
| 67 | + // remaining flags |
| 68 | + args.extend([ |
| 69 | + "-w".to_string(), |
| 70 | + "-49".to_string(), |
| 71 | + "-color".to_string(), |
| 72 | + "always".to_string(), |
| 73 | + "-no-alias-deps".to_string(), |
| 74 | + ]); |
| 75 | + args.push(mlmap_name.clone()); |
58 | 76 |
|
59 |
| - let _ = Command::new(bsc_path) |
| 77 | + let output = Command::new(bsc_path) |
60 | 78 | .current_dir(
|
61 | 79 | build_path_abs
|
62 | 80 | .canonicalize()
|
63 | 81 | .map(StrippedVerbatimPath::to_stripped_verbatim_path)
|
64 | 82 | .ok()
|
65 | 83 | .unwrap(),
|
66 | 84 | )
|
67 |
| - .args(args) |
68 |
| - .output() |
69 |
| - .expect("err"); |
| 85 | + .args(&args) |
| 86 | + .output()?; |
| 87 | + |
| 88 | + if !output.status.success() { |
| 89 | + let stderr = String::from_utf8_lossy(&output.stderr).to_string(); |
| 90 | + return Err(anyhow!( |
| 91 | + "Failed to compile namespace mlmap {} in {}: {}", |
| 92 | + namespace, |
| 93 | + build_path_abs.to_string_lossy(), |
| 94 | + stderr |
| 95 | + )); |
| 96 | + } |
| 97 | + |
| 98 | + Ok(()) |
70 | 99 | }
|
0 commit comments