Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #174 from cloudflare/refactor-wranglerjs-installat…
Browse files Browse the repository at this point in the history
…ion-2

Refactor wranglerjs installation (part 2)
  • Loading branch information
ashleygwilliams authored May 31, 2019
2 parents 4519dc2 + b1e492b commit 7fc96cf
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = "MIT/Apache-2.0"
description = "wrangle your workers, CLI for rustwasm Cloudflare workers!"
readme = "README.md"
categories = ["wasm"]
build = "build.rs"

[dependencies]
atty = "0.2.11"
Expand Down
4 changes: 4 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
displayName: "cargo install cargo-generate"
- script: cargo test --locked
displayName: "cargo test --locked"
env:
RUST_LOG: info

- job: test_wrangler_nightly
displayName: "Run wrangler tests (nightly)"
Expand All @@ -46,6 +48,8 @@ jobs:
displayName: "cargo install cargo-generate"
- script: cargo test --locked
displayName: "cargo test --locked"
env:
RUST_LOG: info

- job: dist_linux
displayName: "Dist Linux binary"
Expand Down
15 changes: 15 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::env;

fn main() {
if let Ok(profile) = env::var("PROFILE") {
if profile == "debug" {
println!("cargo:rustc-cfg=feature={:?}", profile);
println!(
"cargo:rustc-env=SOURCE_DIR={:?}",
env::current_dir().unwrap()
);
} else {
println!("cargo:rustc-env=SOURCE_DIR={:?}", "");
}
}
}
2 changes: 1 addition & 1 deletion src/install/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod krate;
mod target;
pub mod target;

use binary_install::{Cache, Download};
use krate::Krate;
Expand Down
6 changes: 6 additions & 0 deletions src/install/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ pub const WINDOWS: bool = cfg!(target_os = "windows");

#[allow(non_upper_case_globals)]
pub const x86_64: bool = cfg!(target_arch = "x86_64");

// Capture if {Wrangler} is in release or debug mode
pub const DEBUG: bool = cfg!(feature = "debug");

// Capture source location, only in debug mode.
pub const SOURCE_DIR: &'static str = env!("SOURCE_DIR");
30 changes: 23 additions & 7 deletions src/wranglerjs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,31 @@ pub fn env_dep_installed(tool: &str) -> Result<(), failure::Error> {
Ok(())
}

// Use the env-provided source directory and remove the quotes
fn get_source_dir() -> PathBuf {
let mut dir = install::target::SOURCE_DIR.to_string();
dir.remove(0);
dir.remove(dir.len() - 1);
Path::new(&dir).to_path_buf()
}

// Install {wranglerjs} from our GitHub releases
pub fn install(cache: &Cache) -> Result<PathBuf, failure::Error> {
let tool_name = "wranglerjs";
let version = env!("CARGO_PKG_VERSION");
let wranglerjs_path = install::install_artifact(tool_name, "cloudflare", cache, version)?;
info!("wranglerjs downloaded at: {:?}", wranglerjs_path.path());

run_npm_install(wranglerjs_path.path()).expect("could not install wranglerjs dependencies");
Ok(wranglerjs_path.path())
let wranglerjs_path = if install::target::DEBUG {
let source_path = get_source_dir();
let wranglerjs_path = source_path.join("wranglerjs");
info!("wranglerjs at: {:?}", wranglerjs_path);
wranglerjs_path
} else {
let tool_name = "wranglerjs";
let version = env!("CARGO_PKG_VERSION");
let wranglerjs_path = install::install_artifact(tool_name, "cloudflare", cache, version)?;
info!("wranglerjs downloaded at: {:?}", wranglerjs_path.path());
wranglerjs_path.path()
};

run_npm_install(wranglerjs_path.clone()).expect("could not install wranglerjs dependencies");
Ok(wranglerjs_path)
}

// We inject some code at the top-level of the Worker; called {prologue}.
Expand Down

0 comments on commit 7fc96cf

Please sign in to comment.