Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new 'module-alias' attribute handling in llbuild #758

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/BuildSystem/BuildSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2323,6 +2323,12 @@ class SwiftCompilerShellCommand : public ExternalCommand {
/// The name of the module.
std::string moduleName;

/// Module aliases used to build this module. For example, if
/// `-module-alias Foo=Bar` was passed, and source files in
/// this module references `Foo`, e.g. `import Foo`, the `Bar`
/// module will loaded and used to compile this module.
std::vector<std::string> moduleAliases;

/// The path of the output module.
std::string moduleOutputPath;

Expand Down Expand Up @@ -2356,6 +2362,7 @@ class SwiftCompilerShellCommand : public ExternalCommand {
return ExternalCommand::getSignature()
.combine(executable)
.combine(moduleName)
.combine(moduleAliases)
.combine(moduleOutputPath)
.combine(sourcesList)
.combine(objectsList)
Expand All @@ -2376,6 +2383,13 @@ class SwiftCompilerShellCommand : public ExternalCommand {
result.push_back(executable);
result.push_back("-module-name");
result.push_back(moduleName);

for (const auto& nameAndAlias: moduleAliases) {
// E.g. `-module-alias Foo=Bar`
result.push_back("-module-alias");
result.push_back(nameAndAlias);
}

result.push_back("-incremental");
result.push_back("-emit-dependencies");
if (!moduleOutputPath.empty()) {
Expand Down Expand Up @@ -2522,7 +2536,17 @@ class SwiftCompilerShellCommand : public ExternalCommand {
virtual bool configureAttribute(
const ConfigureContext& ctx, StringRef name,
ArrayRef<std::pair<StringRef, StringRef>> values) override {
return ExternalCommand::configureAttribute(ctx, name, values);
if (name == "module-alias") {
// Format the values for the module alias attribute to
// be passed to the driver, e.g. `-module-alias Foo=Bar`
for (auto pair: values) {
auto formatted = pair.first + "=" + pair.second;
moduleAliases.push_back(formatted.str());
}
return !moduleAliases.empty();
} else {
return ExternalCommand::configureAttribute(ctx, name, values);
}
}

bool writeOutputFileMap(TaskInterface ti,
Expand Down