Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(743)

Unified Diff: tools/gn/function_define_rule.cc

Issue 21114002: Add initial prototype for the GN meta-buildsystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add owners and readme Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/filesystem_utils_unittest.cc ('k') | tools/gn/function_exec_script.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/function_define_rule.cc
diff --git a/tools/gn/function_define_rule.cc b/tools/gn/function_define_rule.cc
new file mode 100644
index 0000000000000000000000000000000000000000..afbed9e6204e32bb1aba209fc7a108d7063a6ffd
--- /dev/null
+++ b/tools/gn/function_define_rule.cc
@@ -0,0 +1,37 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "tools/gn/functions.h"
+
+#include "tools/gn/parse_tree.h"
+#include "tools/gn/scope.h"
+#include "tools/gn/value.h"
+
+Value ExecuteDefineRule(Scope* scope,
+ const FunctionCallNode* function,
+ const std::vector<Value>& args,
+ BlockNode* block,
+ Err* err) {
+ // TODO(brettw) determine if the function is built-in and throw an error if
+ // it is.
+ if (args.size() != 1) {
+ *err = Err(function->function(),
+ "Need exactly one string arg to define_rule.");
+ return Value();
+ }
+ if (!args[0].VerifyTypeIs(Value::STRING, err))
+ return Value();
+ std::string rule_name = args[0].string_value();
+
+ const FunctionCallNode* existing_rule = scope->GetRule(rule_name);
+ if (existing_rule) {
+ *err = Err(function, "Duplicate rule definition.",
+ "A rule with this name was already defined.");
+ err->AppendSubErr(Err(existing_rule->function(), "Previous definition."));
+ return Value();
+ }
+
+ scope->AddRule(rule_name, function);
+ return Value();
+}
« no previous file with comments | « tools/gn/filesystem_utils_unittest.cc ('k') | tools/gn/function_exec_script.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698