OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef TOOLS_GN_ARGS_H_ | 5 #ifndef TOOLS_GN_ARGS_H_ |
6 #define TOOLS_GN_ARGS_H_ | 6 #define TOOLS_GN_ARGS_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // | 54 // |
55 // On failure, the err will be set and it will return false. | 55 // On failure, the err will be set and it will return false. |
56 bool DeclareArgs(const Scope::KeyValueMap& args, | 56 bool DeclareArgs(const Scope::KeyValueMap& args, |
57 Scope* scope_to_set, | 57 Scope* scope_to_set, |
58 Err* err) const; | 58 Err* err) const; |
59 | 59 |
60 // Checks to see if any of the overrides ever used were never declared as | 60 // Checks to see if any of the overrides ever used were never declared as |
61 // arguments. If there are, this returns false and sets the error. | 61 // arguments. If there are, this returns false and sets the error. |
62 bool VerifyAllOverridesUsed(Err* err) const; | 62 bool VerifyAllOverridesUsed(Err* err) const; |
63 | 63 |
64 // Like VerifyAllOverridesUsed but takes the lists of overrides specified and | |
65 // parameters declared. | |
66 static bool VerifyAllOverridesUsed( | |
67 const Scope::KeyValueMap& overrides, | |
68 const Scope::KeyValueMap& declared_arguments, | |
69 Err* err); | |
70 | |
71 // Adds all declared arguments to the given output list. If the values exist | 64 // Adds all declared arguments to the given output list. If the values exist |
72 // in the list already, their values will be overwriten, but other values | 65 // in the list already, their values will be overwriten, but other values |
73 // already in the list will remain. | 66 // already in the list will remain. |
74 void MergeDeclaredArguments(Scope::KeyValueMap* dest) const; | 67 void MergeDeclaredArguments(Scope::KeyValueMap* dest) const; |
75 | 68 |
76 private: | 69 private: |
| 70 using DeclaredArgumentsPerToolchain = |
| 71 base::hash_map<const Settings*, Scope::KeyValueMap>; |
| 72 |
77 // Sets the default config based on the current system. | 73 // Sets the default config based on the current system. |
78 void SetSystemVarsLocked(Scope* scope) const; | 74 void SetSystemVarsLocked(Scope* scope) const; |
79 | 75 |
80 // Sets the given vars on the given scope. | 76 // Sets the given vars on the given scope. |
81 void ApplyOverridesLocked(const Scope::KeyValueMap& values, | 77 void ApplyOverridesLocked(const Scope::KeyValueMap& values, |
82 Scope* scope) const; | 78 Scope* scope) const; |
83 | 79 |
84 void SaveOverrideRecordLocked(const Scope::KeyValueMap& values) const; | 80 void SaveOverrideRecordLocked(const Scope::KeyValueMap& values) const; |
85 | 81 |
| 82 // Returns the KeyValueMap used for arguments declared for the specified |
| 83 // toolchain. |
| 84 Scope::KeyValueMap& DeclaredArgumentsForToolchainLocked(Scope* scope) const; |
| 85 |
86 // Since this is called during setup which we assume is single-threaded, | 86 // Since this is called during setup which we assume is single-threaded, |
87 // this is not protected by the lock. It should be set only during init. | 87 // this is not protected by the lock. It should be set only during init. |
88 Scope::KeyValueMap overrides_; | 88 Scope::KeyValueMap overrides_; |
89 | 89 |
90 mutable base::Lock lock_; | 90 mutable base::Lock lock_; |
91 | 91 |
92 // Maintains a list of all overrides we've ever seen. This is the main | 92 // Maintains a list of all overrides we've ever seen. This is the main |
93 // |overrides_| as well as toolchain overrides. Tracking this allows us to | 93 // |overrides_| as well as toolchain overrides. Tracking this allows us to |
94 // check for overrides that were specified but never used. | 94 // check for overrides that were specified but never used. |
95 mutable Scope::KeyValueMap all_overrides_; | 95 mutable Scope::KeyValueMap all_overrides_; |
96 | 96 |
97 // Tracks all variables declared in any buildfile. This is so we can see if | 97 // Maps from Settings (which corresponds to a toolchain) to the map of |
98 // the user set variables on the command line that are not used anywhere. | 98 // declared variables. This is used to tracks all variables declared in any |
99 mutable Scope::KeyValueMap declared_arguments_; | 99 // buildfile. This is so we can see if the user set variables on the command |
| 100 // line that are not used anywhere. Each map is toolchain specific as each |
| 101 // toolchain may define variables in different locations. |
| 102 mutable DeclaredArgumentsPerToolchain declared_arguments_per_toolchain_; |
100 | 103 |
101 Args& operator=(const Args& other); // Disallow assignment. | 104 Args& operator=(const Args& other); // Disallow assignment. |
102 }; | 105 }; |
103 | 106 |
104 #endif // TOOLS_GN_ARGS_H_ | 107 #endif // TOOLS_GN_ARGS_H_ |
OLD | NEW |