[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / tools / gn / label_pattern.h
blob5c032603ee8d90d5edf79972c9c3210bca087478
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_LABEL_PATTERN_H_
6 #define TOOLS_GN_LABEL_PATTERN_H_
8 #include "base/strings/string_piece.h"
9 #include "tools/gn/label.h"
10 #include "tools/gn/source_dir.h"
12 class Err;
13 class Value;
15 extern const char kLabelPattern_Help[];
17 // A label pattern is a simple pattern that matches labels. It is used for
18 // specifying visibility and other times when multiple targets need to be
19 // referenced.
20 class LabelPattern {
21 public:
22 enum Type {
23 MATCH = 1, // Exact match for a given target.
24 DIRECTORY, // Only targets in the file in the given directory.
25 RECURSIVE_DIRECTORY // The given directory and any subdir.
26 // (also indicates "public" when dir is empty).
29 LabelPattern();
30 LabelPattern(Type type,
31 const SourceDir& dir,
32 const base::StringPiece& name,
33 const Label& toolchain_label);
34 ~LabelPattern();
36 // Converts the given input string to a pattern. This does special stuff
37 // to treat the pattern as a label. Sets the error on failure.
38 static LabelPattern GetPattern(const SourceDir& current_dir,
39 const Value& value,
40 Err* err);
42 // Returns true if the given input string might match more than one thing.
43 static bool HasWildcard(const std::string& str);
45 // Returns true if this pattern matches the given label.
46 bool Matches(const Label& label) const;
48 // Returns a string representation of this pattern.
49 std::string Describe() const;
51 Type type() const { return type_; }
53 const SourceDir& dir() const { return dir_; }
54 const std::string& name() const { return name_; }
56 const Label& toolchain() const { return toolchain_; }
57 void set_toolchain(const Label& tc) { toolchain_ = tc; }
59 private:
60 // If nonempty, specifies the toolchain to use. If empty, this will match
61 // all toolchains. This is independent of the match type.
62 Label toolchain_;
64 Type type_;
66 // Used when type_ == PRIVATE and PRIVATE_RECURSIVE. This specifies the
67 // directory that to which the pattern is private to.
68 SourceDir dir_;
70 // Empty name means match everything. Otherwise the name must match
71 // exactly.
72 std::string name_;
75 #endif // TOOLS_GN_LABEL_PATTERN_H_