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.
5 #ifndef TOOLS_GN_VISIBILITY_H_
6 #define TOOLS_GN_VISIBILITY_H_
10 #include "base/basictypes.h"
11 #include "base/strings/string_piece.h"
12 #include "tools/gn/source_dir.h"
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).
32 VisPattern(Type type
, const SourceDir
& dir
, const base::StringPiece
& name
);
35 bool Matches(const Label
& label
) const;
37 Type
type() const { return type_
; }
38 const SourceDir
& dir() const { return dir_
; }
39 const std::string
& name() const { return name_
; }
44 // Used when type_ == PRIVATE and PRIVATE_RECURSIVE. This specifies the
45 // directory that to which the pattern is private to.
48 // Empty name means match everything. Otherwise the name must match
53 // Defaults to private visibility (only the current file).
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
);
61 // Sets the visibility to be public.
64 // Sets the visibility to be private to the given directory.
65 void SetPrivate(const SourceDir
& current_dir
);
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;
71 // Returns a string listing the visibility. |indent| number of spaces will
72 // be added on the left side of the output. If |include_brackets| is set, the
73 // result will be wrapped in "[ ]" and the contents further indented. The
74 // result will end in a newline.
75 std::string
Describe(int indent
, bool include_brackets
) const;
77 // Converts the given input string to a pattern. This does special stuff
78 // to treat the pattern as a label. Sets the error on failure.
79 static VisPattern
GetPattern(const SourceDir
& current_dir
,
83 // Helper function to check visibility between the given two items. If
84 // to is invisible to from, returns false and sets the error.
85 static bool CheckItemVisibility(const Item
* from
, const Item
* to
, Err
* err
);
87 // Helper function to fill an item's visibility from the "visibility" value
88 // in the current scope.
89 static bool FillItemVisibility(Item
* item
, Scope
* scope
, Err
* err
);
92 std::vector
<VisPattern
> patterns_
;
94 DISALLOW_COPY_AND_ASSIGN(Visibility
);
97 #endif // TOOLS_GN_VISIBILITY_H_