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

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

Issue 552843005: Convert GN visibility to be a list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/variables.cc ('k') | tools/gn/visibility_unittest.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 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/strings/string_piece.h" 7 #include "base/strings/string_piece.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "tools/gn/err.h" 9 #include "tools/gn/err.h"
10 #include "tools/gn/filesystem_utils.h" 10 #include "tools/gn/filesystem_utils.h"
11 #include "tools/gn/item.h" 11 #include "tools/gn/item.h"
12 #include "tools/gn/label.h" 12 #include "tools/gn/label.h"
13 #include "tools/gn/scope.h" 13 #include "tools/gn/scope.h"
14 #include "tools/gn/value.h" 14 #include "tools/gn/value.h"
15 #include "tools/gn/variables.h" 15 #include "tools/gn/variables.h"
16 16
17 Visibility::Visibility() { 17 Visibility::Visibility() {
18 } 18 }
19 19
20 Visibility::~Visibility() { 20 Visibility::~Visibility() {
21 } 21 }
22 22
23 bool Visibility::Set(const SourceDir& current_dir, 23 bool Visibility::Set(const SourceDir& current_dir,
24 const Value& value, 24 const Value& value,
25 Err* err) { 25 Err* err) {
26 patterns_.clear(); 26 patterns_.clear();
27 27
28 // Allow a single string to be passed in to make the common case (just one 28 if (!value.VerifyTypeIs(Value::LIST, err)) {
29 // pattern) easier to specify. 29 CHECK(err->has_error());
30 if (value.type() == Value::STRING) { 30 return false;
31 patterns_.push_back(LabelPattern::GetPattern(current_dir, value, err));
32 return !err->has_error();
33 } 31 }
34 32
35 // If it's not a string, it should be a list of strings.
36 if (!value.VerifyTypeIs(Value::LIST, err))
37 return false;
38
39 const std::vector<Value>& list = value.list_value(); 33 const std::vector<Value>& list = value.list_value();
40 for (size_t i = 0; i < list.size(); i++) { 34 for (size_t i = 0; i < list.size(); i++) {
41 patterns_.push_back(LabelPattern::GetPattern(current_dir, list[i], err)); 35 patterns_.push_back(LabelPattern::GetPattern(current_dir, list[i], err));
42 if (err->has_error()) 36 if (err->has_error())
43 return false; 37 return false;
44 } 38 }
45 return true; 39 return true;
46 } 40 }
47 41
48 void Visibility::SetPublic() { 42 void Visibility::SetPublic() {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 102
109 // static 103 // static
110 bool Visibility::FillItemVisibility(Item* item, Scope* scope, Err* err) { 104 bool Visibility::FillItemVisibility(Item* item, Scope* scope, Err* err) {
111 const Value* vis_value = scope->GetValue(variables::kVisibility, true); 105 const Value* vis_value = scope->GetValue(variables::kVisibility, true);
112 if (vis_value) 106 if (vis_value)
113 item->visibility().Set(scope->GetSourceDir(), *vis_value, err); 107 item->visibility().Set(scope->GetSourceDir(), *vis_value, err);
114 else // Default to public. 108 else // Default to public.
115 item->visibility().SetPublic(); 109 item->visibility().SetPublic();
116 return !err->has_error(); 110 return !err->has_error();
117 } 111 }
OLDNEW
« no previous file with comments | « tools/gn/variables.cc ('k') | tools/gn/visibility_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698