Skip to content

Commit

Permalink
Add new option to support compiling a single project
Browse files Browse the repository at this point in the history
  • Loading branch information
tbezman committed Apr 13, 2022
1 parent ed53bb0 commit e4b86a9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
8 changes: 8 additions & 0 deletions compiler/crates/relay-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ struct CompileCommand {
#[clap(long, short)]
watch: bool,

/// Compile a single project
#[clap(long, short)]
project: Option<String>,

/// Compile using this config file. If not provided, searches for a config in
/// package.json under the `relay` key or `relay.config.json` files among other up
/// from the current working directory.
Expand Down Expand Up @@ -205,6 +209,10 @@ async fn handle_compiler_command(command: CompileCommand) -> Result<(), Error> {

let mut config = get_config(command.config)?;

if let Some(project_to_retain) = command.project {
config.retain_project(project_to_retain);
}

if command.validate {
config.artifact_writer = Box::new(ArtifactValidationWriter::default());
}
Expand Down
5 changes: 5 additions & 0 deletions compiler/crates/relay-compiler/src/compiler_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ impl ProjectSet {
existing_names.push(project_name);
}

pub fn retain_project(&mut self, project_name_to_keep: ProjectName) {
self.0
.retain(|project_name| *project_name == project_name_to_keep);
}

pub fn iter(&self) -> slice::Iter<'_, StringKey> {
self.0.iter()
}
Expand Down
19 changes: 18 additions & 1 deletion compiler/crates/relay-compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use sha1::{Digest, Sha1};
use std::env::current_dir;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;
use std::{fmt, vec};
use watchman_client::pdu::ScmAwareClockData;
Expand Down Expand Up @@ -400,6 +401,18 @@ Example file:
.filter(|project_config| project_config.enabled)
}

// Remove projects other than `project_name_to_retain`. Used for the `--project` flag.
pub fn retain_project(&mut self, project_name_to_retain: String) {
let project_name_to_retain = StringKey::from_str(project_name_to_retain.as_str()).unwrap();

self.projects
.retain(|key, _| *key == project_name_to_retain);

for (_, project_set) in &mut self.sources {
project_set.retain_project(project_name_to_retain);
}
}

/// Validated internal consistency of the config.
fn validate_consistency(&self, errors: &mut Vec<ConfigValidationError>) {
let mut project_names = FnvHashSet::default();
Expand Down Expand Up @@ -510,7 +523,11 @@ impl fmt::Debug for Config {
} = self;

fn option_fn_to_string<T>(option: &Option<T>) -> &'static str {
if option.is_some() { "Some(Fn)" } else { "None" }
if option.is_some() {
"Some(Fn)"
} else {
"None"
}
}

f.debug_struct("Config")
Expand Down

0 comments on commit e4b86a9

Please sign in to comment.