• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef TOOLS_GN_CONFIG_H_
6 #define TOOLS_GN_CONFIG_H_
7 
8 #include "base/logging.h"
9 #include "base/macros.h"
10 #include "gn/config_values.h"
11 #include "gn/item.h"
12 #include "gn/label_ptr.h"
13 #include "gn/unique_vector.h"
14 
15 // Represents a named config in the dependency graph.
16 //
17 // A config can list other configs. We track both the data assigned directly
18 // on the config, this list of sub-configs, and (when the config is resolved)
19 // the resulting values of everything merged together. The flatten step
20 // means we can avoid doing a recursive config walk for every target to compute
21 // flags.
22 class Config : public Item {
23  public:
24   // We track the set of build files that may affect this config, please refer
25   // to Scope for how this is determined.
26   Config(const Settings* settings,
27          const Label& label,
28          const SourceFileSet& build_dependency_files = {});
29   ~Config() override;
30 
31   // Item implementation.
32   Config* AsConfig() override;
33   const Config* AsConfig() const override;
34   bool OnResolved(Err* err) override;
35 
36   // The values set directly on this config. This will not contain data from
37   // sub-configs.
own_values()38   ConfigValues& own_values() { return own_values_; }
own_values()39   const ConfigValues& own_values() const { return own_values_; }
40 
41   // The values that represent this config and all sub-configs combined into
42   // one. This is only valid after the config is resolved (when we know the
43   // contents of the sub-configs).
resolved_values()44   const ConfigValues& resolved_values() const {
45     DCHECK(resolved_);
46     if (configs_.empty())  // No sub configs, just use the regular values.
47       return own_values_;
48     return composite_values_;
49   }
50 
51   // List of sub-configs.
configs()52   const UniqueVector<LabelConfigPair>& configs() const { return configs_; }
configs()53   UniqueVector<LabelConfigPair>& configs() { return configs_; }
54 
55  private:
56   ConfigValues own_values_;
57 
58   // Contains the own_values combined with sub-configs. Most configs don't have
59   // sub-configs. So as an optimization, this is not populated if there are no
60   // items in configs_. The resolved_values() getter handles this.
61   bool resolved_ = false;
62   ConfigValues composite_values_;
63 
64   UniqueVector<LabelConfigPair> configs_;
65 
66   DISALLOW_COPY_AND_ASSIGN(Config);
67 };
68 
69 #endif  // TOOLS_GN_CONFIG_H_
70