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

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

Issue 2156173003: Re-land r406064 "[GN] Add JSON project writer". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clear dependency 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 | « tools/gn/visibility.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 #include "tools/gn/visibility.h" 5 #include "tools/gn/visibility.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
8 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/values.h"
9 #include "tools/gn/err.h" 11 #include "tools/gn/err.h"
10 #include "tools/gn/filesystem_utils.h" 12 #include "tools/gn/filesystem_utils.h"
11 #include "tools/gn/item.h" 13 #include "tools/gn/item.h"
12 #include "tools/gn/label.h" 14 #include "tools/gn/label.h"
13 #include "tools/gn/scope.h" 15 #include "tools/gn/scope.h"
14 #include "tools/gn/value.h" 16 #include "tools/gn/value.h"
15 #include "tools/gn/variables.h" 17 #include "tools/gn/variables.h"
16 18
17 Visibility::Visibility() { 19 Visibility::Visibility() {
18 } 20 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 78 }
77 79
78 for (const auto& pattern : patterns_) 80 for (const auto& pattern : patterns_)
79 result += inner_indent_string + pattern.Describe() + "\n"; 81 result += inner_indent_string + pattern.Describe() + "\n";
80 82
81 if (include_brackets) 83 if (include_brackets)
82 result += outer_indent_string + "]\n"; 84 result += outer_indent_string + "]\n";
83 return result; 85 return result;
84 } 86 }
85 87
88 std::unique_ptr<base::Value> Visibility::AsValue() const {
89 auto* res = new base::ListValue();
90 for (const auto& pattern : patterns_)
91 res->AppendString(pattern.Describe());
92
93 return WrapUnique(res);
94 }
95
86 // static 96 // static
87 bool Visibility::CheckItemVisibility(const Item* from, 97 bool Visibility::CheckItemVisibility(const Item* from,
88 const Item* to, 98 const Item* to,
89 Err* err) { 99 Err* err) {
90 if (!to->visibility().CanSeeMe(from->label())) { 100 if (!to->visibility().CanSeeMe(from->label())) {
91 std::string to_label = to->label().GetUserVisibleName(false); 101 std::string to_label = to->label().GetUserVisibleName(false);
92 *err = Err(from->defined_from(), "Dependency not allowed.", 102 *err = Err(from->defined_from(), "Dependency not allowed.",
93 "The item " + from->label().GetUserVisibleName(false) + "\n" 103 "The item " + from->label().GetUserVisibleName(false) + "\n"
94 "can not depend on " + to_label + "\n" 104 "can not depend on " + to_label + "\n"
95 "because it is not in " + to_label + "'s visibility list: " + 105 "because it is not in " + to_label + "'s visibility list: " +
96 to->visibility().Describe(0, true)); 106 to->visibility().Describe(0, true));
97 return false; 107 return false;
98 } 108 }
99 return true; 109 return true;
100 } 110 }
101 111
102 // static 112 // static
103 bool Visibility::FillItemVisibility(Item* item, Scope* scope, Err* err) { 113 bool Visibility::FillItemVisibility(Item* item, Scope* scope, Err* err) {
104 const Value* vis_value = scope->GetValue(variables::kVisibility, true); 114 const Value* vis_value = scope->GetValue(variables::kVisibility, true);
105 if (vis_value) 115 if (vis_value)
106 item->visibility().Set(scope->GetSourceDir(), *vis_value, err); 116 item->visibility().Set(scope->GetSourceDir(), *vis_value, err);
107 else // Default to public. 117 else // Default to public.
108 item->visibility().SetPublic(); 118 item->visibility().SetPublic();
109 return !err->has_error(); 119 return !err->has_error();
110 } 120 }
OLDNEW
« no previous file with comments | « tools/gn/visibility.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698