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

Side by Side Diff: tools/gn/function_toolchain.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, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/function_template.cc ('k') | tools/gn/function_write_file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "tools/gn/err.h"
6 #include "tools/gn/functions.h"
7 #include "tools/gn/parse_tree.h"
8 #include "tools/gn/scheduler.h"
9 #include "tools/gn/scope.h"
10 #include "tools/gn/settings.h"
11 #include "tools/gn/toolchain.h"
12
13 namespace {
14
15 // This is jsut a unique value to take the address of to use as the key for
16 // the toolchain property on a scope.
17 const int kToolchainPropertyKey = 0;
18
19 // Reads the given string from the scope (if present) and puts the result into
20 // dest. If the value is not a string, sets the error and returns false.
21 bool ReadString(Scope& scope, const char* var, std::string* dest, Err* err) {
22 const Value* v = scope.GetValue(var, true);
23 if (!v)
24 return true; // Not present is fine.
25
26 if (!v->VerifyTypeIs(Value::STRING, err))
27 return false;
28 *dest = v->string_value();
29 return true;
30 }
31
32 } // namespace
33
34 Value ExecuteToolchain(Scope* scope,
35 const FunctionCallNode* function,
36 const std::vector<Value>& args,
37 BlockNode* block,
38 Err* err) {
39 if (!EnsureNotProcessingImport(function, scope, err) ||
40 !EnsureNotProcessingBuildConfig(function, scope, err))
41 return Value();
42
43 // Note that we don't want to use MakeLabelForScope since that will include
44 // the toolchain name in the label, and toolchain labels don't themselves
45 // have toolchain names.
46 const SourceDir& input_dir = SourceDirForFunctionCall(function);
47 Label label(input_dir, args[0].string_value(), SourceDir(), std::string());
48 if (g_scheduler->verbose_logging())
49 g_scheduler->Log("Generating toolchain", label.GetUserVisibleName(true));
50
51 // This object will actually be copied into the one owned by the toolchain
52 // manager, but that has to be done in the lock.
53 Toolchain toolchain(label);
54
55 Scope block_scope(scope);
56 block_scope.SetProperty(&kToolchainPropertyKey, &toolchain);
57 block->ExecuteBlockInScope(&block_scope, err);
58 block_scope.SetProperty(&kToolchainPropertyKey, NULL);
59 if (err->has_error())
60 return Value();
61 if (!block_scope.CheckForUnusedVars(err))
62 return Value();
63
64 const BuildSettings* build_settings = scope->settings()->build_settings();
65 {
66 // Save the toolchain definition in the toolchain manager and mark the
67 // corresponding item in the dependency tree resolved so that targets
68 // that depend on this toolchain know it's ready.
69 base::AutoLock lock(build_settings->item_tree().lock());
70 build_settings->toolchain_manager().SetToolchainDefinitionLocked(
71 toolchain, function->GetRange(), err);
72 build_settings->item_tree().MarkItemGeneratedLocked(label);
73 }
74 return Value();
75 }
76
77 Value ExecuteTool(Scope* scope,
78 const FunctionCallNode* function,
79 const std::vector<Value>& args,
80 BlockNode* block,
81 Err* err) {
82 // Find the toolchain definition we're executing inside of. The toolchain
83 // function will set a property pointing to it that we'll pick up.
84 Toolchain* toolchain = reinterpret_cast<Toolchain*>(
85 scope->GetProperty(&kToolchainPropertyKey, NULL));
86 if (!toolchain) {
87 *err = Err(function->function(), "tool() called outside of toolchain().",
88 "The tool() function can only be used inside a toolchain() "
89 "definition.");
90 return Value();
91 }
92
93 if (!EnsureSingleStringArg(function, args, err))
94 return Value();
95 const std::string& tool_name = args[0].string_value();
96 Toolchain::ToolType tool_type = Toolchain::ToolNameToType(tool_name);
97 if (tool_type == Toolchain::TYPE_NONE) {
98 *err = Err(args[0], "Unknown tool type");
99 return Value();
100 }
101
102 // Run the tool block.
103 Scope block_scope(scope);
104 block->ExecuteBlockInScope(&block_scope, err);
105 if (err->has_error())
106 return Value();
107
108 // Extract the stuff we need.
109 Toolchain::Tool t;
110 if (!ReadString(block_scope, "command", &t.command, err) ||
111 !ReadString(block_scope, "depfile", &t.depfile, err) ||
112 !ReadString(block_scope, "deps", &t.deps, err) ||
113 !ReadString(block_scope, "description", &t.description, err) ||
114 !ReadString(block_scope, "pool", &t.pool, err) ||
115 !ReadString(block_scope, "restat", &t.restat, err) ||
116 !ReadString(block_scope, "rspfile", &t.rspfile, err) ||
117 !ReadString(block_scope, "rspfile_content", &t.rspfile_content, err))
118 return Value();
119
120 // Make sure there weren't any vars set in this tool that were unused.
121 if (!block_scope.CheckForUnusedVars(err))
122 return Value();
123
124 toolchain->SetTool(tool_type, t);
125 return Value();
126 }
OLDNEW
« no previous file with comments | « tools/gn/function_template.cc ('k') | tools/gn/function_write_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698