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 this pattern matches the given label.
43 bool Matches(const Label
& label
) const;
45 // Returns a string representation of this pattern.
46 std::string
Describe() const;
48 Type
type() const { return type_
; }
50 const SourceDir
& dir() const { return dir_
; }
51 const std::string
& name() const { return name_
; }
53 const Label
& toolchain() const { return toolchain_
; }
54 void set_toolchain(const Label
& tc
) { toolchain_
= tc
; }
57 // If nonempty, specifies the toolchain to use. If empty, this will match
58 // all toolchains. This is independent of the match type.
63 // Used when type_ == PRIVATE and PRIVATE_RECURSIVE. This specifies the
64 // directory that to which the pattern is private to.
67 // Empty name means match everything. Otherwise the name must match
72 #endif // TOOLS_GN_LABEL_PATTERN_H_