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