summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock16
-rw-r--r--Cargo.toml1
-rw-r--r--src/args.rs4
-rw-r--r--src/executor.rs77
4 files changed, 96 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c800ee5..1021c93 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -413,6 +413,15 @@ dependencies = [
]
[[package]]
+name = "indoc"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e5a75aeaaef0ce18b58056d306c27b07436fbb34b8816c53094b76dd81803136"
+dependencies = [
+ "unindent",
+]
+
+[[package]]
name = "iovec"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -795,6 +804,7 @@ dependencies = [
"enum-kinds",
"handlebars",
"hex",
+ "indoc",
"ipc-channel",
"libc",
"nix",
@@ -1081,6 +1091,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
+name = "unindent"
+version = "0.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7"
+
+[[package]]
name = "users"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 8438a71..280c840 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,6 +12,7 @@ clap = "3.0.0-beta.2"
enum-kinds = "0.5.1"
handlebars = "4.1.3"
hex = { version = "0.4.3", features = ["std", "serde"] }
+indoc = "1.0.3"
ipc-channel = { git = "https://github.com/servo/ipc-channel.git" }
libc = "0.2.84"
nix = "0.23.0"
diff --git a/src/args.rs b/src/args.rs
index 8fcfd77..9fe7db4 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -59,6 +59,10 @@ impl From<PlatformRelation> for Arg {
pub struct TaskArgs(HashMap<String, Rc<Arg>>);
impl TaskArgs {
+ pub fn contains_key(&self, key: &str) -> bool {
+ self.0.contains_key(key)
+ }
+
pub fn get(&self, key: &str) -> Option<&Rc<Arg>> {
self.0.get(key)
}
diff --git a/src/executor.rs b/src/executor.rs
index 69e869d..06b3610 100644
--- a/src/executor.rs
+++ b/src/executor.rs
@@ -1,5 +1,6 @@
use std::collections::{HashMap, HashSet};
+use indoc::indoc;
use serde::{Deserialize, Serialize};
use crate::{
@@ -155,6 +156,75 @@ impl<'ctx> Executor<'ctx> {
.collect())
}
+ fn task_setup(&self, task_ref: &TaskRef<'ctx>) -> Vec<&'static str> {
+ let mut ret = Vec::new();
+
+ ret.push(indoc! {"
+ export AR_FOR_BUILD=ar
+ export AS_FOR_BUILD=as
+ export DLLTOOL_FOR_BUILD=dlltool
+ export CC_FOR_BUILD=gcc
+ export CXX_FOR_BUILD=g++
+ export GCC_FOR_BUILD=gcc
+ export GFORTRAN_FOR_BUILD=gfortran
+ export GOC_FOR_BUILD=goc
+ export LD_FOR_BUILD=ld
+ export LIPO_FOR_BUILD=lipo
+ export NM_FOR_BUILD=nm
+ export OBJCOPY_FOR_BUILD=objcopy
+ export OBJDUMP_FOR_BUILD=objdump
+ export RANLIB_FOR_BUILD=ranlib
+ export STRIP_FOR_BUILD=strip
+ export WINDRES_FOR_BUILD=windres
+ export WINDMC_FOR_BUILD=windmc
+ "});
+
+ if task_ref.args.contains_key("build_to_host") {
+ ret.push(indoc! {"
+ export AR={{build_to_host.cross_compile}}ar
+ export AS={{build_to_host.cross_compile}}as
+ export DLLTOOL={{build_to_host.cross_compile}}dlltool
+ export CC={{build_to_host.cross_compile}}gcc
+ export CXX={{build_to_host.cross_compile}}g++
+ export GCC={{build_to_host.cross_compile}}gcc
+ export GFORTRAN={{build_to_host.cross_compile}}gfortran
+ export GOC={{build_to_host.cross_compile}}goc
+ export LD={{build_to_host.cross_compile}}ld
+ export LIPO={{build_to_host.cross_compile}}lipo
+ export NM={{build_to_host.cross_compile}}nm
+ export OBJCOPY={{build_to_host.cross_compile}}objcopy
+ export OBJDUMP={{build_to_host.cross_compile}}objdump
+ export RANLIB={{build_to_host.cross_compile}}ranlib
+ export STRIP={{build_to_host.cross_compile}}strip
+ export WINDRES={{build_to_host.cross_compile}}windres
+ export WINDMC={{build_to_host.cross_compile}}windmc
+ "});
+ }
+
+ if task_ref.args.contains_key("build_to_target") {
+ ret.push(indoc! {"
+ export AR_FOR_TARGET={{build_to_target.cross_compile}}ar
+ export AS_FOR_TARGET={{build_to_target.cross_compile}}as
+ export DLLTOOL_FOR_TARGET={{build_to_target.cross_compile}}dlltool
+ export CC_FOR_TARGET={{build_to_target.cross_compile}}gcc
+ export CXX_FOR_TARGET={{build_to_target.cross_compile}}g++
+ export GCC_FOR_TARGET={{build_to_target.cross_compile}}gcc
+ export GFORTRAN_FOR_TARGET={{build_to_target.cross_compile}}gfortran
+ export GOC_FOR_TARGET={{build_to_target.cross_compile}}goc
+ export LD_FOR_TARGET={{build_to_target.cross_compile}}ld
+ export LIPO_FOR_TARGET={{build_to_target.cross_compile}}lipo
+ export NM_FOR_TARGET={{build_to_target.cross_compile}}nm
+ export OBJCOPY_FOR_TARGET={{build_to_target.cross_compile}}objcopy
+ export OBJDUMP_FOR_TARGET={{build_to_target.cross_compile}}objdump
+ export RANLIB_FOR_TARGET={{build_to_target.cross_compile}}ranlib
+ export STRIP_FOR_TARGET={{build_to_target.cross_compile}}strip
+ export WINDRES_FOR_TARGET={{build_to_target.cross_compile}}windres
+ export WINDMC_FOR_TARGET={{build_to_target.cross_compile}}windmc
+ "});
+ }
+ ret
+ }
+
fn run_one(&self, task_ref: &TaskRef<'ctx>, runner: &impl runner::Runner) -> Result<TaskMeta> {
let task_def = &self.ctx[task_ref.id];
let task_deps = self.task_deps(task_ref)?;
@@ -179,9 +249,12 @@ impl<'ctx> Executor<'ctx> {
})
.unwrap_or_default();
+ let mut run = self.task_setup(task_ref);
+ run.push(&task_def.action.run);
+
let command = self
.tpl
- .eval(&task_def.action.run, &task_ref.args)
+ .eval(&run.concat(), &task_ref.args)
.with_context(|| {
format!("Failed to evaluate command template for task {}", task_ref)
})?;
@@ -207,7 +280,7 @@ impl<'ctx> Executor<'ctx> {
fs::mkdir(&state_dir)?;
let task = runner::Task {
- label: format!("{:#}", task_ref,),
+ label: format!("{:#}", task_ref),
input,
input_hash,
};