diff --git a/util/launcher/launcher_main.rs b/util/launcher/launcher_main.rs index 0fe27a47f1..10a2a09ff8 100644 --- a/util/launcher/launcher_main.rs +++ b/util/launcher/launcher_main.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; use std::fs::File; -use std::io::{BufReader, BufRead}; +use std::io::{BufRead, BufReader}; use std::path::PathBuf; use std::process::Command; use std::vec::Vec; @@ -11,7 +11,7 @@ use std::os::unix::process::CommandExt; /// This string must match the one found in `_create_test_launcher` const LAUNCHFILES_ENV_PATH: &'static str = ".launchfiles/env"; -/// Load environment variables from a uniquly formatted +/// Load environment variables from a uniquly formatted fn environ() -> BTreeMap { let mut environ = BTreeMap::new(); @@ -21,7 +21,7 @@ fn environ() -> BTreeMap { let env_path = std::env::args().nth(0).expect("arg 0 was not set") + LAUNCHFILES_ENV_PATH; let file = File::open(env_path).expect("Failed to load the environment file"); - // Variables will have the `${pwd}` variable replaced which is rendered by + // Variables will have the `${pwd}` variable replaced which is rendered by // `@rules_rust//rust/private:util.bzl::expand_locations` let pwd = std::env::current_dir().expect("Failed to get current working directory"); let pwd_str = pwd.to_string_lossy(); @@ -35,25 +35,28 @@ fn environ() -> BTreeMap { environ.insert( key.expect("Key is not set"), - line.expect("Failed to read line").replace("${pwd}", &pwd_str), + line.expect("Failed to read line") + .replace("${pwd}", &pwd_str), ); key = None; } - + environ } /// Locate the executable based on the name of the launcher executable fn executable() -> PathBuf { let mut exec_path = std::env::args().nth(0).expect("arg 0 was not set"); - let stem_index = exec_path.rfind(".launcher").expect("This executable should always contain `.launcher`"); + let stem_index = exec_path + .rfind(".launcher") + .expect("This executable should always contain `.launcher`"); // Remove the substring from the exec path for _char in ".launcher".chars() { exec_path.remove(stem_index); } - + PathBuf::from(exec_path) } @@ -67,9 +70,9 @@ fn args() -> Vec { #[cfg(target_family = "unix")] fn exec(environ: BTreeMap, executable: PathBuf, args: Vec) { let error = Command::new(&executable) - .envs(environ.iter()) - .args(args) - .exec(); + .envs(environ.iter()) + .args(args) + .exec(); panic!("Process failed to start: {:?} with {:?}", executable, error) } @@ -79,10 +82,10 @@ fn exec(environ: BTreeMap, executable: PathBuf, args: Vec, executable: PathBuf, args: Vec) { let output = Command::new(executable) - .envs(environ.iter()) - .args(args) - .output() - .expect("Failed to run process"); + .envs(environ.iter()) + .args(args) + .output() + .expect("Failed to run process"); std::process::exit(output.status.code().unwrap_or(1)); } diff --git a/util/process_wrapper/process_wrapper.cc b/util/process_wrapper/process_wrapper.cc index e9d7ee7c86..2d84a4fa11 100644 --- a/util/process_wrapper/process_wrapper.cc +++ b/util/process_wrapper/process_wrapper.cc @@ -157,7 +157,8 @@ int PW_MAIN(int argc, const CharType* argv[], const CharType* envp[]) { } // Have the last values added take precedence over the first. - // This is simpler than needing to track duplicates and explicitly override them. + // This is simpler than needing to track duplicates and explicitly override + // them. std::reverse(environment_block.begin(), environment_block.end()); int exit_code = System::Exec(exec_path, arguments, environment_block, diff --git a/util/process_wrapper/system.h b/util/process_wrapper/system.h index 57b730663d..8abf744e5f 100644 --- a/util/process_wrapper/system.h +++ b/util/process_wrapper/system.h @@ -54,7 +54,7 @@ class System { // It is meant to be called once during the lifetime of the parent process static int Exec(const StrType& executable, const Arguments& arguments, const EnvironmentBlock& environment_block, - const StrType& stdout_file,const StrType& stderr_file); + const StrType& stdout_file, const StrType& stderr_file); }; } // namespace process_wrapper diff --git a/util/process_wrapper/system_posix.cc b/util/process_wrapper/system_posix.cc index 0c5e8cb6c6..1c6550b761 100644 --- a/util/process_wrapper/system_posix.cc +++ b/util/process_wrapper/system_posix.cc @@ -33,7 +33,7 @@ namespace process_wrapper { namespace { class OutputPipe { -public: + public: static constexpr size_t kReadEndDesc = 0; static constexpr size_t kWriteEndDesc = 1; @@ -97,7 +97,7 @@ class OutputPipe { return true; } -private: + private: void Close(size_t idx) { if (output_pipe_desc_[idx] > 0) { close(output_pipe_desc_[idx]); @@ -107,7 +107,7 @@ class OutputPipe { int output_pipe_desc_[2] = {-1}; }; -} // namespace +} // namespace System::StrType System::GetWorkingDirectory() { const size_t kMaxBufferLength = 4096; diff --git a/util/process_wrapper/system_windows.cc b/util/process_wrapper/system_windows.cc index 6496258a01..e7c1a89c1f 100644 --- a/util/process_wrapper/system_windows.cc +++ b/util/process_wrapper/system_windows.cc @@ -94,7 +94,7 @@ std::string GetLastErrorAsStr() { } class OutputPipe { -public: + public: static constexpr size_t kReadEndHandle = 0; static constexpr size_t kWriteEndHandle = 1; @@ -181,7 +181,7 @@ class OutputPipe { return true; } -private: + private: void Close(size_t idx) { if (output_pipe_handles_[idx] != nullptr) { ::CloseHandle(output_pipe_handles_[idx]); @@ -191,7 +191,7 @@ class OutputPipe { HANDLE output_pipe_handles_[2] = {nullptr}; }; -} // namespace +} // namespace System::StrType System::GetWorkingDirectory() { constexpr DWORD kMaxBufferLength = 4096; @@ -243,7 +243,7 @@ int System::Exec(const System::StrType& executable, /*dwCreationFlags*/ 0 #if defined(UNICODE) | CREATE_UNICODE_ENVIRONMENT -#endif // defined(UNICODE) +#endif // defined(UNICODE) , /*lpEnvironment*/ environment_block_win.empty() ? nullptr @@ -277,4 +277,4 @@ int System::Exec(const System::StrType& executable, return exit_status; } -} // namespace process_wrapper +} // namespace process_wrapper diff --git a/util/process_wrapper/utils.cc b/util/process_wrapper/utils.cc index d63627fb0c..41401af845 100644 --- a/util/process_wrapper/utils.cc +++ b/util/process_wrapper/utils.cc @@ -70,7 +70,8 @@ bool ReadFileToArray(const System::StrType& file_path, } // a \ at the end of a line allows us to escape the new line break, - // \\ yields a single \, so \\\ translates to a single \ and a new line escape + // \\ yields a single \, so \\\ translates to a single \ and a new line + // escape int end_backslash_count = 0; for (std::string::reverse_iterator rit = read_line.rbegin(); rit != read_line.rend() && *rit == '\\'; ++rit) { @@ -98,6 +99,6 @@ bool ReadFileToArray(const System::StrType& file_path, } } return true; -} +} } // namespace process_wrapper