diff --git a/xtask/src/commands/dist.rs b/xtask/src/commands/dist.rs index 3efa5f08fc..85ca567264 100644 --- a/xtask/src/commands/dist.rs +++ b/xtask/src/commands/dist.rs @@ -14,7 +14,7 @@ impl Dist { pub fn run(&self, verbose: bool) -> Result<()> { let cargo_runner = CargoRunner::new(verbose)?; let binary_path = cargo_runner - .build(self.target.to_owned()) + .build(&self.target, true) .with_context(|| "Could not build Rover.")?; if !cfg!(windows) { diff --git a/xtask/src/commands/test.rs b/xtask/src/commands/test.rs index aa6758722f..22ed3916aa 100644 --- a/xtask/src/commands/test.rs +++ b/xtask/src/commands/test.rs @@ -12,11 +12,14 @@ pub struct Test { impl Test { pub fn run(&self, verbose: bool) -> Result<()> { + let release = false; let cargo_runner = CargoRunner::new(verbose)?; let git_runner = GitRunner::new(verbose)?; - let make_runner = MakeRunner::new(verbose)?; + let make_runner = + MakeRunner::new(verbose, cargo_runner.get_bin_path(&self.target, release))?; cargo_runner.test(self.target.to_owned())?; + cargo_runner.build(&self.target, release)?; let repo_path = git_runner.clone_supergraph_demo()?; make_runner.test_supergraph_demo(&repo_path)?; diff --git a/xtask/src/tools/cargo.rs b/xtask/src/tools/cargo.rs index 4fa9925409..625d6e521a 100644 --- a/xtask/src/tools/cargo.rs +++ b/xtask/src/tools/cargo.rs @@ -23,9 +23,12 @@ impl CargoRunner { }) } - pub(crate) fn build(&self, target: Target) -> Result { + pub(crate) fn build(&self, target: &Target, release: bool) -> Result { let target_str = target.to_string(); - let mut args = vec!["build", "--release", "--target", &target_str]; + let mut args = vec!["build", "--target", &target_str]; + if release { + args.push("--release"); + } if !target.composition_js() { args.push("--no-default-features"); } @@ -51,12 +54,7 @@ impl CargoRunner { } } self.cargo_exec(&args, Some(env))?; - Ok(self - .cargo_package_directory - .join("target") - .join(&target_str) - .join("release") - .join("rover")) + Ok(self.get_bin_path(target, release)) } pub(crate) fn lint(&self) -> Result<()> { @@ -89,6 +87,19 @@ impl CargoRunner { Ok(()) } + pub(crate) fn get_bin_path(&self, target: &Target, release: bool) -> Utf8PathBuf { + let mut path = self.cargo_package_directory.clone(); + path.push("target"); + path.push(target.to_string()); + if release { + path.push("release") + } else { + path.push("debug") + } + path.push("rover"); + path + } + fn cargo_exec( &self, args: &[&str], diff --git a/xtask/src/tools/git.rs b/xtask/src/tools/git.rs index 84a4099c5a..34fa79d0b9 100644 --- a/xtask/src/tools/git.rs +++ b/xtask/src/tools/git.rs @@ -28,15 +28,18 @@ impl GitRunner { pub(crate) fn clone_supergraph_demo(&self) -> Result { let repo_name = "supergraph-demo"; + let repo_url = format!("https://github.com/EverlastingBugstopper/{}", repo_name); + self.runner + .exec(&["clone", &repo_url], &self.temp_dir_path, None)?; + + let repo_path = self.temp_dir_path.join(repo_name); + self.runner.exec( - &[ - "clone", - &format!("https://github.com/apollographql/{}", repo_name), - ], - &self.temp_dir_path, + &["checkout", "avery/override-rover-location"], + &repo_path, None, )?; - Ok(self.temp_dir_path.join(repo_name)) + Ok(repo_path) } } diff --git a/xtask/src/tools/make.rs b/xtask/src/tools/make.rs index 17d7f99bb4..ef68dfd2b6 100644 --- a/xtask/src/tools/make.rs +++ b/xtask/src/tools/make.rs @@ -1,33 +1,35 @@ +use std::collections::HashMap; + use crate::tools::Runner; use crate::utils::CommandOutput; use anyhow::{anyhow, Context, Result}; -use camino::Utf8Path; +use camino::{Utf8Path, Utf8PathBuf}; pub(crate) struct MakeRunner { runner: Runner, + rover_exe: Utf8PathBuf, } impl MakeRunner { - pub(crate) fn new(verbose: bool) -> Result { + pub(crate) fn new(verbose: bool, rover_exe: Utf8PathBuf) -> Result { let runner = Runner::new("make", verbose)?; - Ok(MakeRunner { runner }) + Ok(MakeRunner { runner, rover_exe }) } pub(crate) fn test_supergraph_demo(&self, base_dir: &Utf8Path) -> Result<()> { - let output = self.runner.exec(&["demo"], base_dir, None)?; + let mut env = HashMap::new(); + env.insert("ROVER_BIN".to_string(), self.rover_exe.to_string()); + let output = self.runner.exec(&["ci"], base_dir, Some(env))?; assert_demo_includes(&output) - .with_context(|| "There were problems with the output of 'make'.") + .with_context(|| "There were problems with the output of 'make ci'.") } } fn assert_demo_includes(output: &CommandOutput) -> Result<()> { - let necessary_stdout = vec![ - "rover supergraph compose", - "🚀 Graph Router ready at http://localhost:4000/", - ]; - let necessary_stderr = vec!["Creating network", "allProducts", "Removing network"]; + let necessary_stdout = vec!["🚀 Graph Router ready at http://localhost:4000/"]; + let necessary_stderr = vec!["allProducts", "Removing network"]; let mut missing_strings = Vec::with_capacity(necessary_stderr.len() + necessary_stdout.len()); for necessary_string in necessary_stdout {