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 class Tool; 18 19 // Holds values specific to target that compile .swift files. 20 class SwiftValues { 21 public: 22 SwiftValues(); 23 ~SwiftValues(); 24 25 SwiftValues(const SwiftValues&) = delete; 26 SwiftValues& operator=(const SwiftValues&) = delete; 27 28 // Called when the target is resolved. This may update target->swift_values(). 29 static bool OnTargetResolved(Target* target, Err* err); 30 31 // Path of the bridging header. bridge_header()32 SourceFile& bridge_header() { return bridge_header_; } bridge_header()33 const SourceFile& bridge_header() const { return bridge_header_; } 34 35 // Name of the module. module_name()36 std::string& module_name() { return module_name_; } module_name()37 const std::string module_name() const { return module_name_; } 38 39 // Name of the generated .swiftmodule file. Computed when the target 40 // is resolved. module_output_file()41 const OutputFile& module_output_file() const { return module_output_file_; } 42 43 // Path of the directory containing the generated .swiftmodule file. 44 // Computed when the target is resolved. module_output_dir()45 const SourceDir& module_output_dir() const { return module_output_dir_; } 46 47 // Returns the tool used for target. 48 const Tool* GetTool(const Target* target) const; 49 50 // Expands the toolchain's outputs and partial outputs for the target. 51 void GetOutputs(const Target* target, std::vector<OutputFile>* result) const; 52 53 // Expands the toolchain's outputs and partial outputs for the target, 54 // returning the values as SourceFile list. 55 void GetOutputsAsSourceFiles(const Target* target, 56 std::vector<SourceFile>* result) const; 57 58 private: 59 // Fill informations about .swiftmodule generated by this target. 60 bool FillModuleOutputFile(Target* target, Err* err); 61 62 // Name of the optional bridge header used to import Objective-C classes. 63 // Filled from the target, may be empty even if the target include .swift 64 // source files. 65 SourceFile bridge_header_; 66 67 // Name of the generate module for use by substitution. 68 std::string module_name_; 69 70 // Path to the .swiftmodule generated by this target. Will be empty if the 71 // target does not include .swift sources. 72 OutputFile module_output_file_; 73 74 // Path of the directory containing the .swiftmodule generated by this 75 // target. Will be null if the target does not include .swift sources. 76 SourceDir module_output_dir_; 77 }; 78 79 #endif // TOOLS_GN_SWIFT_TARGET_VALUES_H_ 80