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"
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
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).
30 LabelPattern(Type type
,
32 const base::StringPiece
& name
,
33 const Label
& toolchain_label
);
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
,
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
; }
60 // If nonempty, specifies the toolchain to use. If empty, this will match
61 // all toolchains. This is independent of the match type.
66 // Used when type_ == PRIVATE and PRIVATE_RECURSIVE. This specifies the
67 // directory that to which the pattern is private to.
70 // Empty name means match everything. Otherwise the name must match
75 #endif // TOOLS_GN_LABEL_PATTERN_H_