Ninja: add final placeholders to merge Swift partials

This adds the placeholders that are needed to merge the swift partial
modules.  It permits generating the rules necessary to actually merge
the partial modules emitted for a partial compilation.
This commit is contained in:
Saleem Abdulrasool
2019-02-18 14:17:20 -08:00
parent b76b83efd3
commit 001446126e
3 changed files with 51 additions and 0 deletions

View File

@@ -283,6 +283,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType());
vars.Language = this->TargetLinkLanguage.c_str();
if (this->TargetLinkLanguage == "Swift") {
vars.SwiftPartialModules = "$SWIFT_PARTIAL_MODULES";
vars.TargetSwiftModule = "$TARGET_SWIFT_MODULE";
vars.TargetSwiftDoc = "$TARGET_SWIFT_DOC";
}
std::string responseFlag;
if (!useResponseFile) {
@@ -787,6 +792,34 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
cmNinjaDeps outputs;
outputs.push_back(targetOutputReal);
if (this->TargetLinkLanguage == "Swift") {
if (const char* name = gt.GetProperty("SWIFT_MODULE_NAME")) {
vars["TARGET_SWIFT_DOC"] = std::string(name) + ".swiftdoc";
vars["TARGET_SWIFT_MODULE"] = std::string(name) + ".swiftmodule";
} else {
vars["TARGET_SWIFT_DOC"] = gt.GetName() + ".swiftdoc";
vars["TARGET_SWIFT_MODULE"] = gt.GetName() + ".swiftmodule";
}
outputs.push_back(vars["TARGET_SWIFT_DOC"]);
outputs.push_back(vars["TARGET_SWIFT_MODULE"]);
cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator();
std::string partials;
std::vector<cmSourceFile const*> sources;
gt.GetObjectSources(sources, this->GetConfigName());
for (cmSourceFile const* source : sources) {
partials += " ";
if (const char* partial = source->GetProperty("SWIFT_PARTIAL_MODULE")) {
partials += partial;
} else {
partials += localGen.GetTargetDirectory(&gt) + "/" +
gt.GetObjectName(source) + ".swiftmodule";
}
}
vars["SWIFT_PARTIAL_MODULES"] = partials;
}
// Compute specific libraries to link with.
cmNinjaDeps explicitDeps = this->GetObjects();
cmNinjaDeps implicitDeps = this->ComputeLinkDeps(this->TargetLinkLanguage);

View File

@@ -187,6 +187,21 @@ std::string cmRulePlaceholderExpander::ExpandRuleVariable(
return replaceValues.SwiftPartialModule;
}
}
if (replaceValues.SwiftPartialModules) {
if (variable == "SWIFT_PARTIAL_MODULES") {
return replaceValues.SwiftPartialModules;
}
}
if (replaceValues.TargetSwiftDoc) {
if (variable == "TARGET_SWIFT_DOC") {
return replaceValues.TargetSwiftDoc;
}
}
if (replaceValues.TargetSwiftModule) {
if (variable == "TARGET_SWIFT_MODULE") {
return replaceValues.TargetSwiftModule;
}
}
if (variable == "TARGET_SONAME" || variable == "SONAME_FLAG" ||
variable == "TARGET_INSTALLNAME_DIR") {
// All these variables depend on TargetSOName

View File

@@ -63,6 +63,9 @@ public:
const char* SwiftLibraryName;
const char* SwiftPartialModule;
const char* SwiftPartialDoc;
const char* TargetSwiftModule;
const char* TargetSwiftDoc;
const char* SwiftPartialModules;
};
// Expand rule variables in CMake of the type found in language rules