• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
9 #include <string_view>
10 #include <vector>
11 
12 #include "gn/label_pattern.h"
13 #include "gn/source_dir.h"
14 
15 namespace base {
16 class Value;
17 }
18 
19 class Err;
20 class Item;
21 class Label;
22 class Scope;
23 class Value;
24 
25 class Visibility {
26  public:
27   // Defaults to private visibility (only the current file).
28   Visibility();
29   ~Visibility();
30 
31   // Set the visibility to the thing specified by the given value. On failure,
32   // returns false and sets the error.
33   bool Set(const SourceDir& current_dir,
34            std::string_view source_root,
35            const Value& value,
36            Err* err);
37 
38   // Sets the visibility to be public.
39   void SetPublic();
40 
41   // Sets the visibility to be private to the given directory.
42   void SetPrivate(const SourceDir& current_dir);
43 
44   // Returns true if the target with the given label can depend on one with the
45   // current visibility.
46   bool CanSeeMe(const Label& label) const;
47 
48   // Returns a string listing the visibility. |indent| number of spaces will
49   // be added on the left side of the output. If |include_brackets| is set, the
50   // result will be wrapped in "[ ]" and the contents further indented. The
51   // result will end in a newline.
52   std::string Describe(int indent, bool include_brackets) const;
53 
54   // Returns value representation of this visibility
55   std::unique_ptr<base::Value> AsValue() const;
56 
57   // Helper function to check visibility between the given two items. If
58   // to is invisible to from, returns false and sets the error.
59   static bool CheckItemVisibility(const Item* from, const Item* to, bool is_external_deps, Err* err);
60 
61   // Helper function to fill an item's visibility from the "visibility" value
62   // in the current scope.
63   static bool FillItemVisibility(Item* item, Scope* scope, Err* err);
64 
65  private:
66   std::vector<LabelPattern> patterns_;
67 
68   Visibility(const Visibility&) = delete;
69   Visibility& operator=(const Visibility&) = delete;
70 };
71 
72 #endif  // TOOLS_GN_VISIBILITY_H_
73