Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions include/swift-c/DependencyScan/DependencyScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_swift_textual_detail_get_module_cache_key(
swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_swift_textual_detail_get_user_module_version(
swiftscan_module_details_t details);

//=== Swift Binary Module Details query APIs ------------------------------===//

SWIFTSCAN_PUBLIC swiftscan_string_ref_t
Expand Down
15 changes: 11 additions & 4 deletions include/swift/AST/ModuleDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,25 @@ class SwiftInterfaceModuleDependenciesStorage
/// Details common to Swift textual (interface or source) modules
CommonSwiftTextualModuleDependencyDetails textualModuleDetails;

/// The user module version of this textual module interface.
const std::string userModuleVersion;

SwiftInterfaceModuleDependenciesStorage(
StringRef moduleOutputPath, StringRef swiftInterfaceFile,
ArrayRef<StringRef> compiledModuleCandidates,
ArrayRef<StringRef> buildCommandLine, ArrayRef<LinkLibrary> linkLibraries,
ArrayRef<StringRef> extraPCMArgs, StringRef contextHash, bool isFramework,
bool isStatic, StringRef RootID, StringRef moduleCacheKey)
bool isStatic, StringRef RootID, StringRef moduleCacheKey,
StringRef userModuleVersion)
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftInterface,
linkLibraries, moduleCacheKey),
moduleOutputPath(moduleOutputPath),
swiftInterfaceFile(swiftInterfaceFile),
compiledModuleCandidates(compiledModuleCandidates.begin(),
compiledModuleCandidates.end()),
contextHash(contextHash), isFramework(isFramework), isStatic(isStatic),
textualModuleDetails(extraPCMArgs, buildCommandLine, RootID) {}
textualModuleDetails(extraPCMArgs, buildCommandLine, RootID),
userModuleVersion(userModuleVersion) {}

ModuleDependencyInfoStorageBase *clone() const override {
return new SwiftInterfaceModuleDependenciesStorage(*this);
Expand Down Expand Up @@ -592,12 +597,14 @@ class ModuleDependencyInfo {
ArrayRef<StringRef> compiledCandidates, ArrayRef<StringRef> buildCommands,
ArrayRef<LinkLibrary> linkLibraries, ArrayRef<StringRef> extraPCMArgs,
StringRef contextHash, bool isFramework, bool isStatic,
StringRef CASFileSystemRootID, StringRef moduleCacheKey) {
StringRef CASFileSystemRootID, StringRef moduleCacheKey,
StringRef userModuleVersion) {
return ModuleDependencyInfo(
std::make_unique<SwiftInterfaceModuleDependenciesStorage>(
moduleOutputPath, swiftInterfaceFile, compiledCandidates,
buildCommands, linkLibraries, extraPCMArgs, contextHash,
isFramework, isStatic, CASFileSystemRootID, moduleCacheKey));
isFramework, isStatic, CASFileSystemRootID, moduleCacheKey,
userModuleVersion));
}

/// Describe the module dependencies for a serialized or parsed Swift module.
Expand Down
3 changes: 2 additions & 1 deletion include/swift/AST/ModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ struct InterfaceSubContextDelegate {
SourceLoc diagLoc,
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
ArrayRef<StringRef>,
ArrayRef<StringRef>, StringRef)> action) = 0;
ArrayRef<StringRef>, StringRef,
StringRef)> action) = 0;
virtual std::error_code runInSubCompilerInstance(StringRef moduleName,
StringRef interfacePath,
StringRef sdkPath,
Expand Down
3 changes: 3 additions & 0 deletions include/swift/DependencyScan/DependencyScanImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ typedef struct {

/// Macro dependecies.
swiftscan_macro_dependency_set_t *macro_dependencies;

/// User module version
swiftscan_string_ref_t user_module_version;
} swiftscan_swift_textual_details_t;

/// Swift modules with only a binary module file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ using SwiftInterfaceModuleDetailsLayout =
DependencyIDArrayIDField, // swiftOverlayDependencies
IdentifierIDField, // CASFileSystemRootID
IdentifierIDField, // bridgingHeaderIncludeTree
IdentifierIDField // moduleCacheKey
IdentifierIDField, // moduleCacheKey
IdentifierIDField // UserModuleVersion
>;

using SwiftSourceModuleDetailsLayout =
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Frontend/ModuleInterfaceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
SourceLoc diagLoc,
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*,
ArrayRef<StringRef>, ArrayRef<StringRef>,
StringRef)> action) override;
StringRef, StringRef)> action) override;
std::error_code runInSubCompilerInstance(StringRef moduleName,
StringRef interfacePath,
StringRef sdkPath,
Expand Down
3 changes: 3 additions & 0 deletions lib/DependencyScan/DependencyScanJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ void writeJSON(llvm::raw_ostream &out,
swiftTextualDeps->module_cache_key, 5,
/*trailingComma=*/true);
}
writeJSONSingleField(out, "userModuleVersion",
swiftTextualDeps->user_module_version, 5,
/*trailingComma=*/true);
writeMacroDependencies(out, swiftTextualDeps->macro_dependencies, 5,
/*trailingComma=*/true);
writeJSONSingleField(out, "isFramework", swiftTextualDeps->is_framework,
Expand Down
14 changes: 10 additions & 4 deletions lib/DependencyScan/ModuleDependencyCacheSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,15 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
extraPCMArgsArrayID, contextHashID, isFramework, isStatic, bridgingHeaderFileID,
sourceFilesArrayID, bridgingSourceFilesArrayID,
bridgingModuleDependenciesArrayID, overlayDependencyIDArrayID,
CASFileSystemRootID, bridgingHeaderIncludeTreeID, moduleCacheKeyID;
CASFileSystemRootID, bridgingHeaderIncludeTreeID, moduleCacheKeyID,
userModuleVersionID;
SwiftInterfaceModuleDetailsLayout::readRecord(
Scratch, outputPathFileID, interfaceFileID,
compiledModuleCandidatesArrayID, buildCommandLineArrayID,
extraPCMArgsArrayID, contextHashID, isFramework, isStatic, bridgingHeaderFileID,
sourceFilesArrayID, bridgingSourceFilesArrayID,
bridgingModuleDependenciesArrayID, overlayDependencyIDArrayID,
CASFileSystemRootID, bridgingHeaderIncludeTreeID, moduleCacheKeyID);
CASFileSystemRootID, bridgingHeaderIncludeTreeID, moduleCacheKeyID, userModuleVersionID);

auto outputModulePath = getIdentifier(outputPathFileID);
if (!outputModulePath)
Expand Down Expand Up @@ -304,13 +305,17 @@ bool ModuleDependenciesCacheDeserializer::readGraph(SwiftDependencyScanningServi
auto moduleCacheKey = getIdentifier(moduleCacheKeyID);
if (!moduleCacheKeyID)
llvm::report_fatal_error("Bad moduleCacheKey");
auto userModuleVersion = getIdentifier(userModuleVersionID);
if (!userModuleVersion)
llvm::report_fatal_error("Bad userModuleVersion");

// TODO: LinkLibraries, MacroDependencies
// Form the dependencies storage object
auto moduleDep = ModuleDependencyInfo::forSwiftInterfaceModule(
outputModulePath.value(), optionalSwiftInterfaceFile.value(),
compiledCandidatesRefs, buildCommandRefs, {}, extraPCMRefs,
*contextHash, isFramework, isStatic, *rootFileSystemID, *moduleCacheKey);
*contextHash, isFramework, isStatic, *rootFileSystemID, *moduleCacheKey,
*userModuleVersion);

// Add imports of this module
for (const auto &moduleName : currentModuleImports)
Expand Down Expand Up @@ -1007,7 +1012,8 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
getIdentifier(swiftTextDeps->textualModuleDetails.CASFileSystemRootID),
getIdentifier(swiftTextDeps->textualModuleDetails
.CASBridgingHeaderIncludeTreeRootID),
getIdentifier(swiftTextDeps->moduleCacheKey));
getIdentifier(swiftTextDeps->moduleCacheKey),
getIdentifier(swiftTextDeps->userModuleVersion));
break;
}
case swift::ModuleDependencyKind::SwiftSource: {
Expand Down
3 changes: 2 additions & 1 deletion lib/DependencyScan/ScanDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ generateFullDependencyGraph(const CompilerInstance &instance,
.CASBridgingHeaderIncludeTreeRootID.c_str()),
create_clone(swiftTextualDeps->moduleCacheKey.c_str()),
createMacroDependencySet(
swiftTextualDeps->textualModuleDetails.macroDependencies)};
swiftTextualDeps->textualModuleDetails.macroDependencies),
create_clone(swiftTextualDeps->userModuleVersion.c_str())};
} else if (swiftSourceDeps) {
swiftscan_string_ref_t moduleInterfacePath = create_null();
swiftscan_string_ref_t bridgingHeaderPath =
Expand Down
7 changes: 5 additions & 2 deletions lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2135,15 +2135,18 @@ InterfaceSubContextDelegateImpl::runInSubContext(StringRef moduleName,
StringRef outputPath,
SourceLoc diagLoc,
llvm::function_ref<std::error_code(ASTContext&, ModuleDecl*, ArrayRef<StringRef>,
ArrayRef<StringRef>, StringRef)> action) {
ArrayRef<StringRef>, StringRef, StringRef)> action) {
return runInSubCompilerInstance(moduleName, interfacePath, sdkPath, outputPath,
diagLoc, /*silenceErrors=*/false,
[&](SubCompilerInstanceInfo &info){
std::string UserModuleVer = info.Instance->getInvocation().getFrontendOptions()
.UserModuleVersion.getAsString();
return action(info.Instance->getASTContext(),
info.Instance->getMainModule(),
info.BuildArguments,
info.ExtraPCMArgs,
info.Hash);
info.Hash,
UserModuleVer);
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Serialization/ScanningLoaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
realModuleName.str(), moduleInterfacePath.str(), sdkPath,
StringRef(), SourceLoc(),
[&](ASTContext &Ctx, ModuleDecl *mainMod, ArrayRef<StringRef> BaseArgs,
ArrayRef<StringRef> PCMArgs, StringRef Hash) {
ArrayRef<StringRef> PCMArgs, StringRef Hash, StringRef UserModVer) {
assert(mainMod);
std::string InPath = moduleInterfacePath.str();
auto compiledCandidates =
Expand Down Expand Up @@ -247,7 +247,7 @@ SwiftModuleScanner::scanInterfaceFile(Twine moduleInterfacePath,
Result = ModuleDependencyInfo::forSwiftInterfaceModule(
outputPathBase.str().str(), InPath, compiledCandidatesRefs,
ArgsRefs, linkLibraries, PCMArgs, Hash, isFramework, isStatic, {},
/*module-cache-key*/ "");
/*module-cache-key*/ "", UserModVer);

if (Ctx.CASOpts.EnableCaching) {
std::vector<std::string> clangDependencyFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// RUN: %empty-directory(%t/DependencyModules)

// Emit a textual module dependency
// RUN: %target-swift-frontend -emit-module -emit-module-interface-path %t/DependencyModules/TextualFoo.swiftinterface -module-cache-path %t/clang-module-cache -module-name TextualFoo %s -D TEXTUAL_FOO -user-module-version 12.3.4

// RUN: %target-swift-frontend -emit-module -emit-module-path %t/DependencyModules/Foo.swiftmodule -module-cache-path %t/clang-module-cache -module-name Foo %s -D FOO -user-module-version 42.3.3

// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %t/DependencyModules/ -module-name main
Expand All @@ -15,9 +17,14 @@

public func foo() {}

#elseif TEXTUAL_FOO


#else
import Foo
import TextualFoo

#endif

// CHECK: "userModuleVersion": "12.3.4"
// CHECK: "userModuleVersion": "42.3.3.0"
7 changes: 7 additions & 0 deletions tools/libSwiftScan/libSwiftScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ void swiftscan_dependency_info_details_dispose(
details_impl->swift_textual_details.module_cache_key);
swiftscan_macro_dependency_dispose(
details_impl->swift_textual_details.macro_dependencies);
swiftscan_string_dispose(
details_impl->swift_textual_details.user_module_version);
break;
case SWIFTSCAN_DEPENDENCY_INFO_SWIFT_BINARY:
swiftscan_string_dispose(
Expand Down Expand Up @@ -393,6 +395,11 @@ swiftscan_string_ref_t swiftscan_swift_textual_detail_get_module_cache_key(
return details->swift_textual_details.module_cache_key;
}

swiftscan_string_ref_t swiftscan_swift_textual_detail_get_user_module_version(
swiftscan_module_details_t details) {
return details->swift_textual_details.user_module_version;
}

//=== Swift Binary Module Details query APIs ------------------------------===//

swiftscan_string_ref_t swiftscan_swift_binary_detail_get_compiled_module_path(
Expand Down
1 change: 1 addition & 0 deletions tools/libSwiftScan/libSwiftScan.exports
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ swiftscan_swift_textual_detail_get_is_framework
swiftscan_swift_textual_detail_get_swift_overlay_dependencies
swiftscan_swift_textual_detail_get_cas_fs_root_id
swiftscan_swift_textual_detail_get_module_cache_key
swiftscan_swift_textual_detail_get_user_module_version
swiftscan_swift_binary_detail_get_compiled_module_path
swiftscan_swift_binary_detail_get_module_doc_path
swiftscan_swift_binary_detail_get_module_source_info_path
Expand Down