Skip to content

Commit

Permalink
chore: use $ROVER_BIN to override with local exe
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Jun 22, 2021
1 parent c5a7157 commit 592dea2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 26 deletions.
2 changes: 1 addition & 1 deletion xtask/src/commands/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion xtask/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
27 changes: 19 additions & 8 deletions xtask/src/tools/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ impl CargoRunner {
})
}

pub(crate) fn build(&self, target: Target) -> Result<Utf8PathBuf> {
pub(crate) fn build(&self, target: &Target, release: bool) -> Result<Utf8PathBuf> {
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");
}
Expand All @@ -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<()> {
Expand Down Expand Up @@ -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],
Expand Down
15 changes: 9 additions & 6 deletions xtask/src/tools/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ impl GitRunner {

pub(crate) fn clone_supergraph_demo(&self) -> Result<Utf8PathBuf> {
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)
}
}
22 changes: 12 additions & 10 deletions xtask/src/tools/make.rs
Original file line number Diff line number Diff line change
@@ -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<Self> {
pub(crate) fn new(verbose: bool, rover_exe: Utf8PathBuf) -> Result<Self> {
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 {
Expand Down

0 comments on commit 592dea2

Please sign in to comment.