Skip to content

Commit 9d30ebb

Browse files
alunyovfacebook-github-bot
authored andcommitted
Check watchman availability
Reviewed By: captbaritone Differential Revision: D31995892 fbshipit-source-id: 2da8cab17f1d4ab3f66a743f896669030b6c4845
1 parent e5dd81f commit 9d30ebb

File tree

1 file changed

+30
-4
lines changed
  • compiler/crates/relay-compiler/src

1 file changed

+30
-4
lines changed

compiler/crates/relay-compiler/src/main.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ use relay_compiler::{
1212
config::{Config, SingleProjectConfigFile, TypegenLanguage},
1313
FileSourceKind, RemotePersister,
1414
};
15-
use std::{env::current_dir, path::PathBuf, sync::Arc};
15+
use std::{
16+
env::{self, current_dir},
17+
path::PathBuf,
18+
process::Command,
19+
sync::Arc,
20+
};
1621
use structopt::StructOpt;
1722

1823
#[derive(StructOpt)]
@@ -86,14 +91,23 @@ async fn main() {
8691
std::process::exit(1);
8792
});
8893
config.operation_persister = Some(Box::new(RemotePersister));
89-
// TODO: Check if watchman is available
90-
config.file_source_config = FileSourceKind::Glob;
94+
config.file_source_config = if should_use_watchman() {
95+
FileSourceKind::Watchman
96+
} else {
97+
FileSourceKind::Glob
98+
};
99+
100+
if opt.watch && !matches!(&config.file_source_config, FileSourceKind::Watchman) {
101+
panic!(
102+
"Cannot run relay in watch mode if `watchman` is not available (or explicitly disabled)."
103+
);
104+
}
91105

92106
let compiler = Compiler::new(Arc::new(config), Arc::new(common::NoopPerfLogger));
93107

94108
if opt.watch {
95109
if let Err(err) = compiler.watch().await {
96-
error!("{}", err);
110+
error!("Watchman error: {}", err);
97111
std::process::exit(1);
98112
}
99113
} else {
@@ -108,3 +122,15 @@ async fn main() {
108122
}
109123
}
110124
}
125+
126+
/// Check if `watchman` is available.
127+
/// Additionally, this method is checking for an existence of `FORCE_NO_WATCHMAN`
128+
/// environment variable. If this `FORCE_NO_WATCHMAN` is set, this method will return `false`
129+
/// and compiler will use non-watchman file finder.
130+
fn should_use_watchman() -> bool {
131+
let check_watchman = Command::new("watchman")
132+
.args(["list-capabilities"])
133+
.output();
134+
135+
check_watchman.is_ok() && env::var("FORCE_NO_WATCHMAN").is_err()
136+
}

0 commit comments

Comments
 (0)