diff options
| author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2016-02-19 14:47:23 +0900 |
|---|---|---|
| committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2016-02-19 14:47:43 +0900 |
| commit | a5ac4d969efdae60ba329f4229ef4c10f9c0836e (patch) | |
| tree | d97198541add2f3b66961614aa4034ba04cbef54 | |
| parent | 8f813fe5eca0abff285760b183db53670b51df69 (diff) | |
| download | platform_build_kati-a5ac4d969efdae60ba329f4229ef4c10f9c0836e.tar.gz platform_build_kati-a5ac4d969efdae60ba329f4229ef4c10f9c0836e.tar.bz2 platform_build_kati-a5ac4d969efdae60ba329f4229ef4c10f9c0836e.zip | |
[C++] Refactor handling of special targets
| -rw-r--r-- | dep.cc | 48 |
1 files changed, 31 insertions, 17 deletions
@@ -132,25 +132,27 @@ class DepBuilder { LOG_STAT("%zu implicit rules", implicit_rules_->size()); LOG_STAT("%zu suffix rules", suffix_rules_.size()); - auto found = rules_.find(Intern(".PHONY")); - if (found != rules_.end()) { - for (Symbol input : found->second->inputs) { - phony_.insert(input); - } + HandleSpecialTargets(); + } + + void HandleSpecialTargets() { + Loc loc; + vector<Symbol> targets; + + if (GetRuleInputs(Intern(".PHONY"), &targets, &loc)) { + for (Symbol t : targets) + phony_.insert(t); } - found = rules_.find(Intern(".KATI_RESTAT")); - if (found != rules_.end()) { - for (Symbol input : found->second->inputs) { - restat_.insert(input); - } + if (GetRuleInputs(Intern(".KATI_RESTAT"), &targets, &loc)) { + for (Symbol t : targets) + restat_.insert(t); } - found = rules_.find(Intern(".SUFFIXES")); - if (found != rules_.end()) { - if (found->second->inputs.empty()) { + if (GetRuleInputs(Intern(".SUFFIXES"), &targets, &loc)) { + if (targets.empty()) { suffix_rules_.clear(); } else { WARN("%s:%d: kati doesn't support .SUFFIXES with prerequisites", - LOCF(found->second->loc)); + LOCF(loc)); } } @@ -171,9 +173,8 @@ class DepBuilder { NULL }; for (const char** p = kUnsupportedBuiltinTargets; *p; p++) { - auto found = rules_.find(Intern(*p)); - if (found != rules_.end()) { - WARN("%s:%d: kati doesn't support %s", LOCF(found->second->loc), *p); + if (GetRuleInputs(Intern(*p), &targets, &loc)) { + WARN("%s:%d: kati doesn't support %s", LOCF(loc), *p); } } } @@ -228,6 +229,19 @@ class DepBuilder { return ::Exists(target.str()); } + bool GetRuleInputs(Symbol s, vector<Symbol>* o, Loc* l) { + auto found = rules_.find(s); + if (found == rules_.end()) + return false; + + o->clear(); + *l = found->second->loc; + for (Symbol i : found->second->inputs) { + o->push_back(i); + } + return true; + } + void PopulateRules(const vector<const Rule*>& rules) { for (const Rule* rule : rules) { if (rule->outputs.empty()) { |
