Skip to content

Commit

Permalink
Add support for custom command filtering in project root
Browse files Browse the repository at this point in the history
  • Loading branch information
Retmvv committed Dec 31, 2024
1 parent f39ff75 commit 7e0e96f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ struct ProjectConfig {
std::string project_root; // project root directory. eg: ~/proj
std::map<std::string, std::string> rbe_properties; // remote build execution properties
std::string grpc_url;
std::set<std::string> local_only_rules;
std::set<std::string> remote_no_cache_rules;
std::set<std::string> fuzzy_rules;
};
/// Options (e.g. verbosity, parallelism) passed to a build.
struct BuildConfig {
Expand Down
33 changes: 33 additions & 0 deletions src/rbe_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <yaml-cpp/yaml.h>
#include <json/json.h>
#include "rbe_config.h"
#include <filesystem>

bool load_config_file(BuildConfig &config) {
std::string config_file = "/etc/ninja2.conf";
Expand Down Expand Up @@ -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<std::string>());
}
}
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<std::string>());
}
}
if (command_set["commands"]["fuzzy_rule"]) {
for (const auto& cmd : command_set["commands"]["fuzzy_rule"]) {
config.rbe_config.fuzzy_rules.insert(cmd.as<std::string>());
}
}

}
}
2 changes: 2 additions & 0 deletions src/rbe_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 7e0e96f

Please sign in to comment.