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

Side by Side Diff: tools/gn/args.h

Issue 2092623002: GN: Don't define argument overrides globally (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 5 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
« no previous file with comments | « no previous file | tools/gn/args.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/containers/hash_tables.h" 8 #include "base/containers/hash_tables.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 22 matching lines...) Expand all
33 void AddArgOverrides(const Scope::KeyValueMap& overrides); 33 void AddArgOverrides(const Scope::KeyValueMap& overrides);
34 34
35 // Returns the value corresponding to the given argument name, or NULL if no 35 // Returns the value corresponding to the given argument name, or NULL if no
36 // argument is set. 36 // argument is set.
37 const Value* GetArgOverride(const char* name) const; 37 const Value* GetArgOverride(const char* name) const;
38 38
39 // Gets all overrides set on the build. 39 // Gets all overrides set on the build.
40 Scope::KeyValueMap GetAllOverrides() const; 40 Scope::KeyValueMap GetAllOverrides() const;
41 41
42 // Sets up the root scope for a toolchain. This applies the default system 42 // Sets up the root scope for a toolchain. This applies the default system
43 // flags, then any overrides stored in this object, then applies any 43 // flags and saves the toolchain overrides so they can be applied to
44 // toolchain overrides specified in the argument. 44 // declare_args blocks that appear when loading files in that toolchain.
45 void SetupRootScope(Scope* dest, 45 void SetupRootScope(Scope* dest,
46 const Scope::KeyValueMap& toolchain_overrides) const; 46 const Scope::KeyValueMap& toolchain_overrides) const;
47 47
48 // Sets up the given scope with arguments passed in. 48 // Sets up the given scope with arguments passed in.
49 // 49 //
50 // If the values specified in the args are not already set, the values in 50 // If the values specified in the args are not already set, the values in
51 // the args list will be used (which are assumed to be the defaults), but 51 // the args list will be used (which are assumed to be the defaults), but
52 // they will not override the system defaults or the current overrides. 52 // they will not override the system defaults or the current overrides.
53 // 53 //
54 // All args specified in the input will be marked as "used". 54 // All args specified in the input will be marked as "used".
55 // 55 //
56 // On failure, the err will be set and it will return false. 56 // On failure, the err will be set and it will return false.
57 bool DeclareArgs(const Scope::KeyValueMap& args, 57 bool DeclareArgs(const Scope::KeyValueMap& args,
58 Scope* scope_to_set, 58 Scope* scope_to_set,
59 Err* err) const; 59 Err* err) const;
60 60
61 // Checks to see if any of the overrides ever used were never declared as 61 // Checks to see if any of the overrides ever used were never declared as
62 // arguments. If there are, this returns false and sets the error. 62 // arguments. If there are, this returns false and sets the error.
63 bool VerifyAllOverridesUsed(Err* err) const; 63 bool VerifyAllOverridesUsed(Err* err) const;
64 64
65 // Adds all declared arguments to the given output list. If the values exist 65 // Adds all declared arguments to the given output list. If the values exist
66 // in the list already, their values will be overwriten, but other values 66 // in the list already, their values will be overwriten, but other values
67 // already in the list will remain. 67 // already in the list will remain.
68 void MergeDeclaredArguments(Scope::KeyValueMap* dest) const; 68 void MergeDeclaredArguments(Scope::KeyValueMap* dest) const;
69 69
70 private: 70 private:
71 using DeclaredArgumentsPerToolchain = 71 using ArgumentsPerToolchain =
72 base::hash_map<const Settings*, Scope::KeyValueMap>; 72 base::hash_map<const Settings*, Scope::KeyValueMap>;
73 73
74 // Sets the default config based on the current system. 74 // Sets the default config based on the current system.
75 void SetSystemVarsLocked(Scope* scope) const; 75 void SetSystemVarsLocked(Scope* scope) const;
76 76
77 // Sets the given vars on the given scope. 77 // Sets the given already declared vars on the given scope.
78 void ApplyOverridesLocked(const Scope::KeyValueMap& values, 78 void ApplyOverridesLocked(const Scope::KeyValueMap& values,
79 Scope* scope) const; 79 Scope* scope) const;
80 80
81 void SaveOverrideRecordLocked(const Scope::KeyValueMap& values) const; 81 void SaveOverrideRecordLocked(const Scope::KeyValueMap& values) const;
82 82
83 // Returns the KeyValueMap used for arguments declared for the specified 83 // Returns the KeyValueMap used for arguments declared for the specified
84 // toolchain. 84 // toolchain.
85 Scope::KeyValueMap& DeclaredArgumentsForToolchainLocked(Scope* scope) const; 85 Scope::KeyValueMap& DeclaredArgumentsForToolchainLocked(Scope* scope) const;
86 86
87 // Returns the KeyValueMap used for overrides for the specified
88 // toolchain.
89 Scope::KeyValueMap& OverridesForToolchainLocked(Scope* scope) const;
90
87 // Since this is called during setup which we assume is single-threaded, 91 // Since this is called during setup which we assume is single-threaded,
88 // this is not protected by the lock. It should be set only during init. 92 // this is not protected by the lock. It should be set only during init.
89 Scope::KeyValueMap overrides_; 93 Scope::KeyValueMap overrides_;
90 94
91 mutable base::Lock lock_; 95 mutable base::Lock lock_;
92 96
93 // Maintains a list of all overrides we've ever seen. This is the main 97 // Maintains a list of all overrides we've ever seen. This is the main
94 // |overrides_| as well as toolchain overrides. Tracking this allows us to 98 // |overrides_| as well as toolchain overrides. Tracking this allows us to
95 // check for overrides that were specified but never used. 99 // check for overrides that were specified but never used.
96 mutable Scope::KeyValueMap all_overrides_; 100 mutable Scope::KeyValueMap all_overrides_;
97 101
98 // Maps from Settings (which corresponds to a toolchain) to the map of 102 // Maps from Settings (which corresponds to a toolchain) to the map of
99 // declared variables. This is used to tracks all variables declared in any 103 // declared variables. This is used to tracks all variables declared in any
100 // buildfile. This is so we can see if the user set variables on the command 104 // buildfile. This is so we can see if the user set variables on the command
101 // line that are not used anywhere. Each map is toolchain specific as each 105 // line that are not used anywhere. Each map is toolchain specific as each
102 // toolchain may define variables in different locations. 106 // toolchain may define variables in different locations.
103 mutable DeclaredArgumentsPerToolchain declared_arguments_per_toolchain_; 107 mutable ArgumentsPerToolchain declared_arguments_per_toolchain_;
108
109 // Overrides for individual toolchains. This is necessary so we
110 // can apply the correct override for the current toolchain, once
111 // we see an argument declaration.
112 mutable ArgumentsPerToolchain toolchain_overrides_;
104 113
105 DISALLOW_ASSIGN(Args); 114 DISALLOW_ASSIGN(Args);
106 }; 115 };
107 116
108 #endif // TOOLS_GN_ARGS_H_ 117 #endif // TOOLS_GN_ARGS_H_
OLDNEW
« no previous file with comments | « no previous file | tools/gn/args.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698