1 // Copyright 2016 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_BUNDLE_FILE_RULE_H_
6 #define TOOLS_GN_BUNDLE_FILE_RULE_H_
7 
8 #include <vector>
9 
10 #include "tools/gn/source_file.h"
11 #include "tools/gn/substitution_pattern.h"
12 
13 class BundleData;
14 class Settings;
15 class SourceFile;
16 class Target;
17 class OutputFile;
18 
19 // BundleFileRule contains the information found in a "bundle_data" target.
20 class BundleFileRule {
21  public:
22   BundleFileRule(const Target* bundle_data_target,
23                  const std::vector<SourceFile> sources,
24                  const SubstitutionPattern& pattern);
25   BundleFileRule(const BundleFileRule& other);
26   ~BundleFileRule();
27 
28   // Applies the substitution pattern to a source file, returning the result
29   // as either a SourceFile or an OutputFile.
30   bool ApplyPatternToSource(const Settings* settings,
31                             const Target* target,
32                             const BundleData& bundle_data,
33                             const SourceFile& source_file,
34                             SourceFile* expanded_source_file,
35                             Err* err) const;
36   bool ApplyPatternToSourceAsOutputFile(const Settings* settings,
37                                         const Target* target,
38                                         const BundleData& bundle_data,
39                                         const SourceFile& source_file,
40                                         OutputFile* expanded_output_file,
41                                         Err* err) const;
42 
43   // Returns the associated target (of type Target::BUNDLE_DATA). May be
44   // null during testing.
target()45   const Target* target() const { return target_; }
46 
47   // Returns the list of SourceFiles.
sources()48   const std::vector<SourceFile>& sources() const { return sources_; }
49 
50  private:
51   const Target* target_;
52   std::vector<SourceFile> sources_;
53   SubstitutionPattern pattern_;
54 };
55 
56 #endif  // TOOLS_GN_BUNDLE_FILE_RULE_H_
57