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

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

Issue 46313003: Implement target visibility in GN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « tools/gn/variables.cc ('k') | tools/gn/visibility.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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_VISIBILITY_H_
6 #define TOOLS_GN_VISIBILITY_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/strings/string_piece.h"
12 #include "tools/gn/source_dir.h"
13
14 class Err;
15 class Item;
16 class Label;
17 class Scope;
18 class Value;
19
20 class Visibility {
21 public:
22 class VisPattern {
23 public:
24 enum Type {
25 MATCH = 1, // Exact match for a given target.
26 DIRECTORY, // Only targets in the file in the given directory.
27 RECURSIVE_DIRECTORY // The given directory and any subdir.
28 // (also indicates "public" when dir is empty).
29 };
30
31 VisPattern();
32 VisPattern(Type type, const SourceDir& dir, const base::StringPiece& name);
33 ~VisPattern();
34
35 bool Matches(const Label& label) const;
36
37 Type type() const { return type_; }
38 const SourceDir& dir() const { return dir_; }
39 const std::string& name() const { return name_; }
40
41 private:
42 Type type_;
43
44 // Used when type_ == PRIVATE and PRIVATE_RECURSIVE. This specifies the
45 // directory that to which the pattern is private to.
46 SourceDir dir_;
47
48 // Empty name means match everything. Otherwise the name must match
49 // exactly.
50 std::string name_;
51 };
52
53 // Defaults to private visibility (only the current file).
54 Visibility();
55 ~Visibility();
56
57 // Set the visibility to the thing specified by the given value. On failure,
58 // returns false and sets the error.
59 bool Set(const SourceDir& current_dir, const Value& value, Err* err);
60
61 // Sets the visibility to be public.
62 void SetPublic();
63
64 // Sets the visibility to be private to the given directory.
65 void SetPrivate(const SourceDir& current_dir);
66
67 // Returns true if the target with the given label can depend on one with the
68 // current visibility.
69 bool CanSeeMe(const Label& label) const;
70
71 // Returns a string listing the visibility.
72 std::string Describe() const;
73
74 // Converts the given input string to a pattern. This does special stuff
75 // to treat the pattern as a label. Sets the error on failure.
76 static VisPattern GetPattern(const SourceDir& current_dir,
77 const Value& value,
78 Err* err);
79
80 // Helper function to check visibility between the given two items. If
81 // to is invisible to from, returns false and sets the error.
82 static bool CheckItemVisibility(const Item* from, const Item* to, Err* err);
83
84 // Helper function to fill an item's visibility from the "visibility" value
85 // in the current scope.
86 static bool FillItemVisibility(Item* item, Scope* scope, Err* err);
87
88 private:
89 std::vector<VisPattern> patterns_;
90
91 DISALLOW_COPY_AND_ASSIGN(Visibility);
92 };
93
94 #endif // TOOLS_GN_VISIBILITY_H_
OLDNEW
« no previous file with comments | « tools/gn/variables.cc ('k') | tools/gn/visibility.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698