• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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_SWIFT_TARGET_VALUES_H_
6 #define TOOLS_GN_SWIFT_TARGET_VALUES_H_
7 
8 #include <string>
9 
10 #include "gn/output_file.h"
11 #include "gn/source_dir.h"
12 #include "gn/source_file.h"
13 #include "gn/unique_vector.h"
14 
15 class Err;
16 class Target;
17 
18 // Holds values specific to target that compile .swift files.
19 class SwiftValues {
20  public:
21   SwiftValues();
22   ~SwiftValues();
23 
24   SwiftValues(const SwiftValues&) = delete;
25   SwiftValues& operator=(const SwiftValues&) = delete;
26 
27   // Called when the target is resolved. This may update target->swift_values().
28   static bool OnTargetResolved(Target* target, Err* err);
29 
30   // Path of the bridging header.
bridge_header()31   SourceFile& bridge_header() { return bridge_header_; }
bridge_header()32   const SourceFile& bridge_header() const { return bridge_header_; }
33 
34   // Name of the module.
module_name()35   std::string& module_name() { return module_name_; }
module_name()36   const std::string module_name() const { return module_name_; }
37 
38   // Name of the generated .swiftmodule file. Computed when the target
39   // is resolved.
module_output_file()40   const OutputFile& module_output_file() const { return module_output_file_; }
41 
42   // Path of the directory containing the generated .swiftmodule file.
43   // Computed when the target is resolved.
module_output_dir()44   const SourceDir& module_output_dir() const { return module_output_dir_; }
45 
46   // List of dependent target that generate a .swiftmodule. The current target
47   // is assumed to depend on those modules, and will add them to the module
48   // search path.
modules()49   const UniqueVector<const Target*>& modules() const { return modules_; }
50 
51   // List of dependent target that generate a .swiftmodule that are publicly
52   // exported by the current target. This will include the current target if
53   // it generates a .swiftmodule.
public_modules()54   const UniqueVector<const Target*>& public_modules() const {
55     return public_modules_;
56   }
57 
58  private:
59   // Fill informations about .swiftmodule generated by this target.
60   static bool FillModuleOutputFile(Target* target, Err* err);
61 
62   // Fill dependencies information on other target generating .swiftmodules.
63   static void FillModuleDependencies(Target* target);
64 
65   // Name of the optional bridge header used to import Objective-C classes.
66   // Filled from the target, may be empty even if the target include .swift
67   // source files.
68   SourceFile bridge_header_;
69 
70   // Name of the generate module for use by substitution.
71   std::string module_name_;
72 
73   // Path to the .swiftmodule generated by this target. Will be empty if the
74   // target does not include .swift sources.
75   OutputFile module_output_file_;
76 
77   // Path of the directory containing the .swiftmodule generated by this
78   // target. Will be null if the target does not include .swift sources.
79   SourceDir module_output_dir_;
80 
81   // For modules() and public_modules() function. Will be filled when the
82   // target is resolved (can be non-empty even if the target does not build
83   // .swift sources due to transitive dependencies).
84   UniqueVector<const Target*> modules_;
85   UniqueVector<const Target*> public_modules_;
86 };
87 
88 #endif  // TOOLS_GN_SWIFT_TARGET_VALUES_H_
89