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.
5 #include "tools/gn/config.h"
7 #include "tools/gn/err.h"
8 #include "tools/gn/input_file_manager.h"
9 #include "tools/gn/item_node.h"
10 #include "tools/gn/item_tree.h"
11 #include "tools/gn/scheduler.h"
13 Config::Config(const Settings
* settings
, const Label
& label
)
14 : Item(settings
, label
) {
20 Config
* Config::AsConfig() {
24 const Config
* Config::AsConfig() const {
29 Config
* Config::GetConfig(const Settings
* settings
,
30 const LocationRange
& specified_from_here
,
34 DCHECK(!label
.is_null());
36 ItemTree
* tree
= &settings
->build_settings()->item_tree();
37 base::AutoLock
lock(tree
->lock());
39 ItemNode
* node
= tree
->GetExistingNodeLocked(label
);
40 Config
* config
= NULL
;
42 config
= new Config(settings
, label
);
43 node
= new ItemNode(config
);
44 node
->set_originally_referenced_from_here(specified_from_here
);
45 tree
->AddNodeLocked(node
);
47 // Only schedule loading the given target if somebody is depending on it
48 // (and we optimize by not re-asking it to run the current file).
49 // Otherwise, we're probably generating it right now.
50 if (dep_from
&& dep_from
->label().dir() != label
.dir()) {
51 settings
->build_settings()->toolchain_manager().ScheduleInvocationLocked(
52 specified_from_here
, label
.GetToolchainLabel(), label
.dir(),
55 } else if ((config
= node
->item()->AsConfig())) {
56 // Previously saw this item as a config.
58 // If we have no dep_from, we're generating it. In this case, it had better
59 // not already be generated.
60 if (!dep_from
&& node
->state() != ItemNode::REFERENCED
) {
61 *err
= Err(specified_from_here
, "Duplicate config definition.",
62 "You already told me about a config with this name.");
66 // Previously saw this thing as a non-config.
67 *err
= Err(specified_from_here
,
68 "Config name already used.",
69 "Previously you specified a " +
70 node
->item()->GetItemTypeName() + " with this name instead.");
74 // Keep a record of the guy asking us for this dependency. We know if
75 // somebody is adding a dependency, that guy it himself not resolved.
77 if (!dep_from
->item_node()->AddDependency(
78 settings
->build_settings(), specified_from_here
, node
, err
))