diff options
author | Brad King <brad.king@kitware.com> | 2019-05-20 14:55:11 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-05-20 14:55:27 (GMT) |
commit | a9fb9a8774a7b1dd411542d1d14fb537968e32f1 (patch) | |
tree | 2d74dc351b298a5317d05634170c91a8b43bc07e /Source/cmNinjaTargetGenerator.cxx | |
parent | 28ee31149030c75c32ebbf134502a9d020dbd54b (diff) | |
parent | a9180ccf9a9e845658ba455e2dbc2447b18d2654 (diff) | |
download | CMake-a9fb9a8774a7b1dd411542d1d14fb537968e32f1.zip CMake-a9fb9a8774a7b1dd411542d1d14fb537968e32f1.tar.gz CMake-a9fb9a8774a7b1dd411542d1d14fb537968e32f1.tar.bz2 |
Merge topic 'ninja-swift'
a9180ccf9a Tests: add a check for the Swift compiler
d745551fb6 Help: add some initial documentation for Swift support
9a182c9e5b Auxiliary: update vim syntax highlighting
e9b0063e8e Modules: add build rules for Swift Ninja support
b6412e3e38 Ninja: add placeholders to support Swift build
7d7f31161d Ninja: add support for Swift's output-file-map.json
d688c4c19d Swift: remove unnecessary unreleased Ninja infrastructure
0723582208 Swift: Detect compiler version
...
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3297
Diffstat (limited to 'Source/cmNinjaTargetGenerator.cxx')
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 125 |
1 files changed, 76 insertions, 49 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index e5f5bf2..9deaa13 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -19,7 +19,6 @@ #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalNinjaGenerator.h" -#include "cmListFileCache.h" // for BT #include "cmLocalGenerator.h" #include "cmLocalNinjaGenerator.h" #include "cmMakefile.h" @@ -455,13 +454,6 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) vars.TargetCompilePDB = "$TARGET_COMPILE_PDB"; vars.ObjectDir = "$OBJECT_DIR"; vars.ObjectFileDir = "$OBJECT_FILE_DIR"; - if (lang == "Swift") { - vars.SwiftAuxiliarySources = "$SWIFT_AUXILIARY_SOURCES"; - vars.SwiftModuleName = "$SWIFT_MODULE_NAME"; - vars.SwiftLibraryName = "$SWIFT_LIBRARY_NAME"; - vars.SwiftPartialModule = "$SWIFT_PARTIAL_MODULE"; - vars.SwiftPartialDoc = "$SWIFT_PARTIAL_DOC"; - } // For some cases we do an explicit preprocessor invocation. bool const explicitPP = this->NeedExplicitPreprocessing(lang); @@ -924,6 +916,28 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() } this->GetBuildFileStream() << "\n"; + + if (!this->SwiftOutputMap.empty()) { + std::string const mapFilePath = this->ConvertToNinjaPath( + this->GeneratorTarget->GetSupportDirectory() + "/output-file-map.json"); + std::string const targetSwiftDepsPath = [this]() -> std::string { + cmGeneratorTarget const* target = this->GeneratorTarget; + if (const char* name = target->GetProperty("Swift_DEPENDENCIES_FILE")) { + return name; + } + return this->ConvertToNinjaPath(target->GetSupportDirectory() + "/" + + target->GetName() + ".swiftdeps"); + }(); + + // build the global target dependencies + // https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps + Json::Value deps(Json::objectValue); + deps["swift-dependencies"] = targetSwiftDepsPath; + this->SwiftOutputMap[""] = deps; + + cmGeneratedFileStream output(mapFilePath); + output << this->SwiftOutputMap; + } } void cmNinjaTargetGenerator::WriteObjectBuildStatement( @@ -948,43 +962,6 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( vars["FLAGS"] = this->ComputeFlagsForObject(source, language); vars["DEFINES"] = this->ComputeDefines(source, language); vars["INCLUDES"] = this->ComputeIncludes(source, language); - if (language == "Swift") { - // The swift compiler needs all the sources besides the one being compiled - // in order to do the type checking. List all these "auxiliary" sources. - std::string aux_sources; - cmGeneratorTarget::KindedSources const& sources = - this->GeneratorTarget->GetKindedSources(this->GetConfigName()); - for (cmGeneratorTarget::SourceAndKind const& src : sources.Sources) { - if (src.Source.Value == source) { - continue; - } - aux_sources += " " + this->GetSourceFilePath(src.Source.Value); - } - vars["SWIFT_AUXILIARY_SOURCES"] = aux_sources; - - if (const char* name = - this->GeneratorTarget->GetProperty("SWIFT_MODULE_NAME")) { - vars["SWIFT_MODULE_NAME"] = name; - } else { - vars["SWIFT_MODULE_NAME"] = this->GeneratorTarget->GetName(); - } - - cmGeneratorTarget::Names targetNames = - this->GeneratorTarget->GetLibraryNames(this->GetConfigName()); - vars["SWIFT_LIBRARY_NAME"] = targetNames.Base; - - if (const char* partial = source->GetProperty("SWIFT_PARTIAL_MODULE")) { - vars["SWIFT_PARTIAL_MODULE"] = partial; - } else { - vars["SWIFT_PARTIAL_MODULE"] = objectFileName + ".swiftmodule"; - } - - if (const char* partial = source->GetProperty("SWIFT_PARTIAL_DOC")) { - vars["SWIFT_PARTIAL_DOC"] = partial; - } else { - vars["SWIFT_PARTIAL_DOC"] = objectFileName + ".swiftdoc"; - } - } if (!this->NeedDepTypeMSVC(language)) { bool replaceExt(false); @@ -1177,10 +1154,14 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( std::string const rspfile = objectFileName + ".rsp"; - this->GetGlobalGenerator()->WriteBuild( - this->GetBuildFileStream(), comment, rule, outputs, - /*implicitOuts=*/cmNinjaDeps(), explicitDeps, implicitDeps, orderOnlyDeps, - vars, rspfile, commandLineLengthLimit); + if (language == "Swift") { + this->EmitSwiftDependencyInfo(source); + } else { + this->GetGlobalGenerator()->WriteBuild( + this->GetBuildFileStream(), comment, rule, outputs, + /*implicitOuts=*/cmNinjaDeps(), explicitDeps, implicitDeps, + orderOnlyDeps, vars, rspfile, commandLineLengthLimit); + } if (const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) { std::vector<std::string> outputList; @@ -1239,6 +1220,52 @@ void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang) tdif << tdi; } +void cmNinjaTargetGenerator::EmitSwiftDependencyInfo( + cmSourceFile const* source) +{ + std::string const sourceFilePath = + this->ConvertToNinjaPath(this->GetSourceFilePath(source)); + std::string const objectFilePath = + this->ConvertToNinjaPath(this->GetObjectFilePath(source)); + std::string const swiftDepsPath = [source, objectFilePath]() -> std::string { + if (const char* name = source->GetProperty("Swift_DEPENDENCIES_FILE")) { + return name; + } + return objectFilePath + ".swiftdeps"; + }(); + std::string const swiftDiaPath = [source, objectFilePath]() -> std::string { + if (const char* name = source->GetProperty("Swift_DIAGNOSTICS_FILE")) { + return name; + } + return objectFilePath + ".dia"; + }(); + std::string const makeDepsPath = [this, source]() -> std::string { + cmLocalNinjaGenerator const* local = this->GetLocalGenerator(); + std::string const objectFileName = + this->ConvertToNinjaPath(this->GetObjectFilePath(source)); + std::string const objectFileDir = + cmSystemTools::GetFilenamePath(objectFileName); + + if (this->Makefile->IsOn("CMAKE_Swift_DEPFLE_EXTNSION_REPLACE")) { + std::string dependFileName = + cmSystemTools::GetFilenameWithoutLastExtension(objectFileName) + ".d"; + return local->ConvertToOutputFormat(objectFileDir + "/" + dependFileName, + cmOutputConverter::SHELL); + } + return local->ConvertToOutputFormat(objectFileName + ".d", + cmOutputConverter::SHELL); + }(); + + // build the source file mapping + // https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps + Json::Value entry = Json::Value(Json::objectValue); + entry["object"] = objectFilePath; + entry["dependencies"] = makeDepsPath; + entry["swift-dependencies"] = swiftDepsPath; + entry["diagnostics"] = swiftDiaPath; + SwiftOutputMap[sourceFilePath] = entry; +} + void cmNinjaTargetGenerator::ExportObjectCompileCommand( std::string const& language, std::string const& sourceFileName, std::string const& objectDir, std::string const& objectFileName, |