diff --git a/src/build.cc b/src/build.cc index 7e0a540..98352da 100644 --- a/src/build.cc +++ b/src/build.cc @@ -814,9 +814,29 @@ size_t CloudCommandRunner::CanRunMore() const { return capacity; } + bool CloudCommandRunner::StartCommand(Edge* edge) { string command = edge->EvaluateCommand(); auto spawn = RemoteExecutor::RemoteSpawn::CreateRemoteSpawn(edge); + string cmd_rule =spawn->edge->rule().name(); + if(config_.rbe_config.local_only_rules.find(cmd_rule) != config_.rbe_config.local_only_rules.end()){ + SubprocessSet subprocset; + Subprocess* subproc = subprocset.Add(spawn->command,edge->use_console()); + if (!subproc) { + return false; + } + return true; + } + for(auto &cmd:config_.rbe_config.fuzzy_rules){ + if(cmd.find(cmd_rule)!=std::string::npos){ + SubprocessSet subprocset; + Subprocess* subproc = subprocset.Add(spawn->command,edge->use_console()); + if (!subproc) { + return false; + } + return true; + } + } RemoteProcess* remoteproc = remote_procs_.Add(spawn); if (!remoteproc) return false; diff --git a/src/build.h b/src/build.h index 5b1057e..86662b9 100644 --- a/src/build.h +++ b/src/build.h @@ -168,6 +168,9 @@ struct ProjectConfig { std::string project_root; // project root directory. eg: ~/proj std::map rbe_properties; // remote build execution properties std::string grpc_url; + std::set local_only_rules; + std::set remote_no_cache_rules; + std::set fuzzy_rules; }; /// Options (e.g. verbosity, parallelism) passed to a build. struct BuildConfig { diff --git a/src/rbe_config.cc b/src/rbe_config.cc index b9e8f7e..e617ff2 100644 --- a/src/rbe_config.cc +++ b/src/rbe_config.cc @@ -10,6 +10,7 @@ #include #include #include "rbe_config.h" +#include bool load_config_file(BuildConfig &config) { std::string config_file = "/etc/ninja2.conf"; @@ -65,3 +66,35 @@ void load_devcontainer_config(const std::string& project_root, BuildConfig &conf config.rbe_config.rbe_properties["workload-isolation-type"] = "docker"; } } + +const std::string COMMANDFILE ="/command_cloudbuild.yml"; + +void load_command_file(const std::string& project_root, BuildConfig &config){ + std::string commandFilePath=project_root+COMMANDFILE; + std::ifstream file(commandFilePath); + YAML::Node command_set; + if (file.is_open()){ + command_set = YAML::LoadFile(commandFilePath); + } else { + std::cout << "YAML file not found,no filter command.\n"; + return; + } + if (command_set) { + if (command_set["commands"]["local_only"]) { + for (const auto& cmd : command_set["commands"]["local_only"]) { + config.rbe_config.local_only_rules.insert(cmd.as()); + } + } + if (command_set["commands"]["remote_no_cache"]) { + for (const auto& cmd : command_set["commands"]["remote_no_cache"]) { + config.rbe_config.remote_no_cache_rules.insert(cmd.as()); + } + } + if (command_set["commands"]["fuzzy_rule"]) { + for (const auto& cmd : command_set["commands"]["fuzzy_rule"]) { + config.rbe_config.fuzzy_rules.insert(cmd.as()); + } + } + + } +} \ No newline at end of file diff --git a/src/rbe_config.h b/src/rbe_config.h index aa7ff9c..5413faa 100644 --- a/src/rbe_config.h +++ b/src/rbe_config.h @@ -12,3 +12,5 @@ bool load_config_file(BuildConfig &config); // Loads the devcontainer configuration from the specified project root void load_devcontainer_config(const std::string& project_root, BuildConfig &config); + +void load_command_file(const std::string& project_root, BuildConfig &config);