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

Unified Diff: tools/gn/function_process_file_template.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/function_exec_script.cc ('k') | tools/gn/function_read_file.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/function_process_file_template.cc
diff --git a/tools/gn/function_process_file_template.cc b/tools/gn/function_process_file_template.cc
new file mode 100644
index 0000000000000000000000000000000000000000..18e1425fba1ab3855f4ae82db1a442b7334a6e63
--- /dev/null
+++ b/tools/gn/function_process_file_template.cc
@@ -0,0 +1,65 @@
+// 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/file_template.h"
+#include "tools/gn/functions.h"
+#include "tools/gn/parse_tree.h"
+
+/*
+process_file_template: Do template expansion over a list of files.
+
+ process_file_template(source_list, template)
+
+ process_file_template applies a template list to a source file list,
+ returning the result of applying each template to each source. This is
+ typically used for computing output file names from input files.
+
+Arguments:
+
+ The source_list is a list of file names.
+
+ The template can be a string or a list. If it is a list, multiple output
+ strings are generated for each input.
+
+ The following template substrings are used in the template arguments
+ and are replaced with the corresponding part of the input file name:
+
+ "{{source}}": The entire source name.
+
+ "{{source_name_part}}": The source name with no path or extension.
+
+Example:
+
+ sources = [
+ "foo.idl",
+ "bar.idl",
+ ]
+ myoutputs = process_file_template(
+ sources,
+ [ "$target_gen_dir/{{source_name_part}}.cc",
+ "$target_gen_dir/{{source_name_part}}.h" ])
+
+ The result in this case will be:
+ [ "/out/Debug/foo.cc"
+ "/out/Debug/foo.h"
+ "/out/Debug/bar.cc"
+ "/out/Debug/bar.h" ]
+*/
+Value ExecuteProcessFileTemplate(Scope* scope,
+ const FunctionCallNode* function,
+ const std::vector<Value>& args,
+ Err* err) {
+ if (args.size() != 2) {
+ *err = Err(function->function(), "Expected two arguments");
+ return Value();
+ }
+
+ FileTemplate file_template(args[1], err);
+ if (err->has_error())
+ return Value();
+
+ Value ret(function, Value::LIST);
+ file_template.Apply(args[0], function, &ret.list_value(), err);
+ return ret;
+}
« no previous file with comments | « tools/gn/function_exec_script.cc ('k') | tools/gn/function_read_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698