Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / tools / gn / label_pattern.h
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.
4
5 #ifndef TOOLS_GN_LABEL_PATTERN_H_
6 #define TOOLS_GN_LABEL_PATTERN_H_
7
8 #include "base/strings/string_piece.h"
9 #include "tools/gn/label.h"
10 #include "tools/gn/source_dir.h"
11
12 class Err;
13 class Value;
14
15 extern const char kLabelPattern_Help[];
16
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).
27   };
28
29   LabelPattern();
30   LabelPattern(Type type,
31                const SourceDir& dir,
32                const base::StringPiece& name,
33                const Label& toolchain_label);
34   ~LabelPattern();
35
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);
41
42   // Returns true if this pattern matches the given label.
43   bool Matches(const Label& label) const;
44
45   // Returns a string representation of this pattern.
46   std::string Describe() const;
47
48   Type type() const { return type_; }
49
50   const SourceDir& dir() const { return dir_; }
51   const std::string& name() const { return name_; }
52
53   const Label& toolchain() const { return toolchain_; }
54   void set_toolchain(const Label& tc) { toolchain_ = tc; }
55
56  private:
57   // If nonempty, specifies the toolchain to use. If empty, this will match
58   // all toolchains. This is independent of the match type.
59   Label toolchain_;
60
61   Type type_;
62
63   // Used when type_ == PRIVATE and PRIVATE_RECURSIVE. This specifies the
64   // directory that to which the pattern is private to.
65   SourceDir dir_;
66
67   // Empty name means match everything. Otherwise the name must match
68   // exactly.
69   std::string name_;
70 };
71
72 #endif  // TOOLS_GN_LABEL_PATTERN_H_