Skip to content
Permalink
Browse files

Call ninja directly from build.rs (denoland#2020)

  • Loading branch information...
ry committed Mar 30, 2019
1 parent c9614d8 commit 6744bb8d750b9ab11d2ec9448334732b98feb58a
Showing with 49 additions and 23 deletions.
  1. +1 −1 cli/build.rs
  2. +1 −1 core/build.rs
  3. +1 −1 tools/format.py
  4. +37 −9 { → tools}/gn.rs
  5. +9 −11 tools/hyper_hello.rs
@@ -1,7 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// Run "cargo build -vv" if you want to see gn output.
mod gn {
include!("../gn.rs");
include!("../tools/gn.rs");
}

fn main() {
@@ -1,7 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// Run "cargo build -vv" if you want to see gn output.
mod gn {
include!("../gn.rs");
include!("../tools/gn.rs");
}

fn main() {
@@ -46,4 +46,4 @@ def qrun(cmd, env=None):
"third_party/rustfmt/" + platform() + "/rustfmt",
"--config-path",
rustfmt_config,
] + find_exts(["cli", "core"], [".rs"]))
] + find_exts(["cli", "core", "tools"], [".rs"]))
@@ -8,6 +8,7 @@ use std::process::Command;

pub struct Build {
gn_mode: String,
root: PathBuf,
pub gn_out_dir: String,
pub gn_out_path: PathBuf,
pub check_only: bool,
@@ -29,14 +30,14 @@ impl Build {
// cd into workspace root.
assert!(env::set_current_dir("..").is_ok());

let cwd = env::current_dir().unwrap();
let root = env::current_dir().unwrap();
// If not using host default target the output folder will change
// target/release will become target/$TARGET/release
// Gn should also be using this output directory as well
// most things will work with gn using the default
// output directory but some tests depend on artifacts
// being in a specific directory relative to the main build output
let gn_out_path = cwd.join(format!("target/{}", gn_mode.clone()));
let gn_out_path = root.join(format!("target/{}", gn_mode.clone()));
let gn_out_dir = normalize_path(&gn_out_path);

// Tell Cargo when to re-run this file. We do this first, so these directives
@@ -69,6 +70,7 @@ impl Build {
gn_out_path,
check_only,
gn_mode,
root,
}
}

@@ -77,21 +79,47 @@ impl Build {
let status = Command::new("python")
.env("DENO_BUILD_PATH", &self.gn_out_dir)
.env("DENO_BUILD_MODE", &self.gn_mode)
.env("DEPOT_TOOLS_WIN_TOOLCHAIN", "0")
.arg("./tools/setup.py")
.status()
.expect("setup.py failed");
assert!(status.success());
}

// TODO(ry) call ninja directly here, not python.
let status = Command::new("python")
.env("DENO_BUILD_PATH", &self.gn_out_dir)
.env("DENO_BUILD_MODE", &self.gn_mode)
.arg("./tools/build.py")
let mut ninja = Command::new("third_party/depot_tools/ninja");
let ninja = if !cfg!(target_os = "windows") {
&mut ninja
} else {
// Windows needs special configuration. This is similar to the function of
// python_env() in //tools/util.py.
let python_path: Vec<String> = vec![
"third_party/python_packages",
"third_party/python_packages/win32",
"third_party/python_packages/win32/lib",
"third_party/python_packages/Pythonwin",
].into_iter()
.map(|p| self.root.join(p).into_os_string().into_string().unwrap())
.collect();
let orig_path = String::from(";")
+ &env::var_os("PATH").unwrap().into_string().unwrap();
let path = self
.root
.join("third_party/python_packages/pywin32_system32")
.into_os_string()
.into_string()
.unwrap();
ninja
.env("PYTHONPATH", python_path.join(";"))
.env("PATH", path + &orig_path)
.env("DEPOT_TOOLS_WIN_TOOLCHAIN", "0")
};

let status = ninja
.arg(gn_target)
.arg("-v")
.arg("-C")
.arg(&self.gn_out_dir)
.status()
.expect("build.py failed");
.expect("ninja failed");
assert!(status.success());
}
}
@@ -4,10 +4,10 @@
#![deny(warnings)]
extern crate hyper;

use std::env;
use hyper::{Body, Response, Server};
use hyper::service::service_fn_ok;
use hyper::rt::{self, Future};
use hyper::service::service_fn_ok;
use hyper::{Body, Response, Server};
use std::env;

static PHRASE: &'static [u8] = b"Hello World!";

@@ -22,17 +22,15 @@ fn main() {
// new_service is run for each connection, creating a 'service'
// to handle requests for that specific connection.
let new_service = || {
// This is the `Service` that will handle the connection.
// `service_fn_ok` is a helper to convert a function that
// returns a Response into a `Service`.
service_fn_ok(|_| {
Response::new(Body::from(PHRASE))
})
// This is the `Service` that will handle the connection.
// `service_fn_ok` is a helper to convert a function that
// returns a Response into a `Service`.
service_fn_ok(|_| Response::new(Body::from(PHRASE)))
};

let server = Server::bind(&addr)
.serve(new_service)
.map_err(|e| eprintln!("server error: {}", e));
.serve(new_service)
.map_err(|e| eprintln!("server error: {}", e));

println!("Listening on http://{}", addr);

0 comments on commit 6744bb8

Please sign in to comment.
You can’t perform that action at this time.