-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathbuild.rs
More file actions
86 lines (80 loc) · 3.34 KB
/
build.rs
File metadata and controls
86 lines (80 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use crate::Config;
use clap::ArgAction::SetTrue;
use clap::{Arg, ArgMatches};
use std::ffi::OsString;
use std::path::{Path, PathBuf};
pub fn cli() -> clap::Command {
clap::Command::new("build")
.about("Builds a spacetime module.")
.arg(
Arg::new("project_path")
.long("project-path")
.short('p')
.value_parser(clap::value_parser!(PathBuf))
.default_value(".")
.help("The system path (absolute or relative) to the project you would like to build")
)
.arg(
Arg::new("lint_dir")
.long("lint-dir")
.value_parser(clap::value_parser!(OsString))
.default_value("src")
.help("The directory to lint for nonfunctional print statements. If set to the empty string, skips linting.")
)
.arg(
// TODO: Make this into --extra-build-args (or something similar) that will get passed along to the language's compiler.
Arg::new("features")
.long("features")
.value_parser(clap::value_parser!(OsString))
.required(false)
.help("Additional features to pass to the build process (e.g. `--features feature1,feature2` for Rust modules).")
// We're hiding this because we think it deserves a refactor first (see the TODO above)
.hide(true)
)
.arg(
Arg::new("debug")
.long("debug")
.short('d')
.action(SetTrue)
.help("Builds the module using debug instead of release (intended to speed up local iteration, not recommended for CI)"),
)
}
pub async fn exec(_config: Config, args: &ArgMatches) -> Result<(PathBuf, &'static str), anyhow::Error> {
let project_path = args.get_one::<PathBuf>("project_path").unwrap();
let features = args.get_one::<OsString>("features");
let lint_dir = args.get_one::<OsString>("lint_dir").unwrap();
let lint_dir = if lint_dir.is_empty() {
None
} else {
Some(PathBuf::from(lint_dir))
};
let build_debug = args.get_flag("debug");
// Create the project path, or make sure the target project path is empty.
if project_path.exists() {
if !project_path.is_dir() {
return Err(anyhow::anyhow!(
"Fatal Error: path {} exists but is not a directory.",
project_path.display()
));
}
} else {
return Err(anyhow::anyhow!(
"Fatal Error: path {} does not exist.",
project_path.display()
));
}
let result = crate::tasks::build(project_path, lint_dir.as_deref(), build_debug, features)?;
println!("Build finished successfully.");
Ok(result)
}
pub async fn exec_with_argstring(
config: Config,
project_path: &Path,
arg_string: &str,
) -> Result<(PathBuf, &'static str), anyhow::Error> {
// Note: "build" must be the start of the string, because `build::cli()` is the entire build subcommand.
// If we don't include this, the args will be misinterpreted (e.g. as commands).
let arg_string = format!("build {} --project-path {}", arg_string, project_path.display());
let arg_matches = cli().get_matches_from(arg_string.split_whitespace());
exec(config.clone(), &arg_matches).await
}