mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 14:58:03 +03:00
Add edenfsctl --checkout-dir flag
Summary: Adds a flag to edenfsctl to let us specify a checkout directory outside our current working directory. This is necessary if we're going to use `buck2 run edenfsctl` as an `eden-dev` replacement, since buck requires us to run from the source directory, which may be different from the checkout we want edenfsctl to operate on. With this change, we can approximate `eden-dev` like this: ``` % buck2 run edenfsctl -- --config-dir=$HOME/local/eden-dev-state --checkout-dir=$HOME/fbsource-dev trace fs ``` This is implemented by altering both the Rust and Python entry points to accept the new flag and change to the given directory. Reviewed By: xavierd Differential Revision: D38961247 fbshipit-source-id: 814306871ebf01f1cabab87c98e85adce68b4ac8
This commit is contained in:
parent
32d557fb05
commit
832520f857
@ -2180,6 +2180,7 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
parser.add_argument(
|
||||
"--home-dir", help="Path to directory where .edenrc config file is stored."
|
||||
)
|
||||
parser.add_argument("--checkout-dir", help=argparse.SUPPRESS)
|
||||
parser.add_argument(
|
||||
"--version", "-v", action="store_true", help="Print EdenFS version."
|
||||
)
|
||||
@ -2227,6 +2228,17 @@ def normalize_path_arg(path_arg: str, may_need_tilde_expansion: bool = False) ->
|
||||
return path_arg
|
||||
|
||||
|
||||
def set_working_directory(args: argparse.Namespace) -> Optional[int]:
|
||||
if args.checkout_dir is None:
|
||||
return
|
||||
|
||||
try:
|
||||
os.chdir(args.checkout_dir)
|
||||
except OSError as e:
|
||||
print(f"Unable to change to checkout directory: {e}", file=sys.stderr)
|
||||
return EX_OSFILE
|
||||
|
||||
|
||||
def is_working_directory_stale() -> bool:
|
||||
try:
|
||||
os.getcwd()
|
||||
@ -2277,6 +2289,10 @@ Please run "cd / && cd -" to update your shell's working directory."""
|
||||
|
||||
|
||||
async def async_main(parser: argparse.ArgumentParser, args: argparse.Namespace) -> int:
|
||||
set_return_code = set_working_directory(args)
|
||||
if set_return_code is not None:
|
||||
return set_return_code
|
||||
|
||||
# Before doing anything else check that the current working directory is valid.
|
||||
# This helps catch the case where a user is trying to run the EdenFS CLI inside
|
||||
# a stale eden mount point.
|
||||
|
@ -61,6 +61,10 @@ pub struct MainCommand {
|
||||
#[clap(long, parse(from_str = expand_path))]
|
||||
home_dir: Option<PathBuf>,
|
||||
|
||||
/// Path to directory within a checkout.
|
||||
#[clap(long, parse(from_str = expand_path), hide = true)]
|
||||
checkout_dir: Option<PathBuf>,
|
||||
|
||||
#[clap(long)]
|
||||
pub debug: bool,
|
||||
|
||||
@ -151,7 +155,21 @@ impl MainCommand {
|
||||
)
|
||||
}
|
||||
|
||||
fn set_working_directory(&self) -> Result<()> {
|
||||
if let Some(checkout_dir) = &self.checkout_dir {
|
||||
std::env::set_current_dir(checkout_dir).with_context(|| {
|
||||
format!(
|
||||
"Unable to change to checkout directory: {}",
|
||||
checkout_dir.display()
|
||||
)
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run(self) -> Result<ExitCode> {
|
||||
self.set_working_directory()?;
|
||||
|
||||
// For command line program, we don't really need concurrency. Schedule everything in
|
||||
// current thread should be sufficient.
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
|
Loading…
Reference in New Issue
Block a user