mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Revert "ModuleLoader: refactor computePrebuiltModulePath to facilitate dependencies scanner's invocation, NFC"
This commit is contained in:
@@ -445,12 +445,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
Optional<StringRef>
|
||||
computePrebuiltModulePath(ASTContext &ctx,
|
||||
StringRef interfacePath,
|
||||
StringRef prebuiltCacheDir,
|
||||
StringRef moduleName,
|
||||
llvm::SmallString<256> &scratch);
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
#endif
|
||||
|
||||
@@ -508,6 +508,82 @@ class ModuleInterfaceLoaderImpl {
|
||||
return true;
|
||||
}
|
||||
|
||||
Optional<StringRef>
|
||||
computePrebuiltModulePath(llvm::SmallString<256> &scratch) {
|
||||
namespace path = llvm::sys::path;
|
||||
StringRef sdkPath = ctx.SearchPathOpts.SDKPath;
|
||||
|
||||
// Check if the interface file comes from the SDK
|
||||
if (sdkPath.empty() || !hasPrefix(path::begin(interfacePath),
|
||||
path::end(interfacePath),
|
||||
path::begin(sdkPath),
|
||||
path::end(sdkPath)))
|
||||
return None;
|
||||
|
||||
// Assemble the expected path: $PREBUILT_CACHE/Foo.swiftmodule or
|
||||
// $PREBUILT_CACHE/Foo.swiftmodule/arch.swiftmodule. Note that there's no
|
||||
// cache key here.
|
||||
scratch = prebuiltCacheDir;
|
||||
|
||||
// FIXME: Would it be possible to only have architecture-specific names
|
||||
// here? Then we could skip this check.
|
||||
StringRef inParentDirName =
|
||||
path::filename(path::parent_path(interfacePath));
|
||||
if (path::extension(inParentDirName) == ".swiftmodule") {
|
||||
assert(path::stem(inParentDirName) == moduleName);
|
||||
path::append(scratch, inParentDirName);
|
||||
}
|
||||
path::append(scratch, path::filename(modulePath));
|
||||
|
||||
// If there isn't a file at this location, skip returning a path.
|
||||
if (!fs.exists(scratch))
|
||||
return None;
|
||||
|
||||
return scratch.str();
|
||||
}
|
||||
|
||||
/// Hack to deal with build systems (including the Swift standard library, at
|
||||
/// the time of this comment) that aren't yet using target-specific names for
|
||||
/// multi-target swiftmodules, in case the prebuilt cache is.
|
||||
Optional<StringRef>
|
||||
computeFallbackPrebuiltModulePath(llvm::SmallString<256> &scratch) {
|
||||
namespace path = llvm::sys::path;
|
||||
StringRef sdkPath = ctx.SearchPathOpts.SDKPath;
|
||||
|
||||
// Check if the interface file comes from the SDK
|
||||
if (sdkPath.empty() || !hasPrefix(path::begin(interfacePath),
|
||||
path::end(interfacePath),
|
||||
path::begin(sdkPath),
|
||||
path::end(sdkPath)))
|
||||
return None;
|
||||
|
||||
// If the module isn't target-specific, there's no fallback path.
|
||||
StringRef inParentDirName =
|
||||
path::filename(path::parent_path(interfacePath));
|
||||
if (path::extension(inParentDirName) != ".swiftmodule")
|
||||
return None;
|
||||
|
||||
// If the interface is already using the target-specific name, there's
|
||||
// nothing else to try.
|
||||
auto normalizedTarget = getTargetSpecificModuleTriple(ctx.LangOpts.Target);
|
||||
if (path::stem(modulePath) == normalizedTarget.str())
|
||||
return None;
|
||||
|
||||
// Assemble the expected path:
|
||||
// $PREBUILT_CACHE/Foo.swiftmodule/target.swiftmodule. Note that there's no
|
||||
// cache key here.
|
||||
scratch = prebuiltCacheDir;
|
||||
path::append(scratch, inParentDirName);
|
||||
path::append(scratch, normalizedTarget.str());
|
||||
scratch += ".swiftmodule";
|
||||
|
||||
// If there isn't a file at this location, skip returning a path.
|
||||
if (!fs.exists(scratch))
|
||||
return None;
|
||||
|
||||
return scratch.str();
|
||||
}
|
||||
|
||||
bool isInResourceDir(StringRef path) {
|
||||
StringRef resourceDir = ctx.SearchPathOpts.RuntimeResourcePath;
|
||||
if (resourceDir.empty()) return false;
|
||||
@@ -639,12 +715,12 @@ class ModuleInterfaceLoaderImpl {
|
||||
if (!prebuiltCacheDir.empty()) {
|
||||
llvm::SmallString<256> scratch;
|
||||
std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
|
||||
Optional<StringRef> path = computePrebuiltModulePath(ctx,
|
||||
interfacePath,
|
||||
prebuiltCacheDir,
|
||||
moduleName,
|
||||
scratch);
|
||||
|
||||
Optional<StringRef> path = computePrebuiltModulePath(scratch);
|
||||
if (!path) {
|
||||
// Hack: deal with prebuilds of modules that still use the target-based
|
||||
// names.
|
||||
path = computeFallbackPrebuiltModulePath(scratch);
|
||||
}
|
||||
if (path) {
|
||||
if (swiftModuleIsUpToDate(*path, deps, moduleBuffer)) {
|
||||
LLVM_DEBUG(llvm::dbgs() << "Found up-to-date prebuilt module at "
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/Basic/Platform.h"
|
||||
#include "swift/Serialization/SerializedModuleLoader.h"
|
||||
#include "swift/AST/ASTContext.h"
|
||||
#include "swift/AST/DiagnosticSuppression.h"
|
||||
@@ -22,92 +21,6 @@ using namespace swift;
|
||||
using llvm::ErrorOr;
|
||||
|
||||
namespace {
|
||||
static Optional<StringRef>
|
||||
computePrebuiltModulePathDefault(ASTContext &ctx,
|
||||
StringRef interfacePath,
|
||||
StringRef prebuiltCacheDir,
|
||||
StringRef moduleName,
|
||||
StringRef modulePath,
|
||||
llvm::SmallString<256> &scratch) {
|
||||
namespace path = llvm::sys::path;
|
||||
StringRef sdkPath = ctx.SearchPathOpts.SDKPath;
|
||||
auto &fs = *ctx.SourceMgr.getFileSystem();
|
||||
// Check if the interface file comes from the SDK
|
||||
if (sdkPath.empty() || !hasPrefix(path::begin(interfacePath),
|
||||
path::end(interfacePath),
|
||||
path::begin(sdkPath),
|
||||
path::end(sdkPath)))
|
||||
return None;
|
||||
|
||||
// Assemble the expected path: $PREBUILT_CACHE/Foo.swiftmodule or
|
||||
// $PREBUILT_CACHE/Foo.swiftmodule/arch.swiftmodule. Note that there's no
|
||||
// cache key here.
|
||||
scratch = prebuiltCacheDir;
|
||||
|
||||
// FIXME: Would it be possible to only have architecture-specific names
|
||||
// here? Then we could skip this check.
|
||||
StringRef inParentDirName =
|
||||
path::filename(path::parent_path(interfacePath));
|
||||
if (path::extension(inParentDirName) == ".swiftmodule") {
|
||||
assert(path::stem(inParentDirName) == moduleName);
|
||||
path::append(scratch, inParentDirName);
|
||||
}
|
||||
path::append(scratch, path::filename(modulePath));
|
||||
|
||||
// If there isn't a file at this location, skip returning a path.
|
||||
if (!fs.exists(scratch))
|
||||
return None;
|
||||
|
||||
return scratch.str();
|
||||
}
|
||||
|
||||
/// Hack to deal with build systems (including the Swift standard library, at
|
||||
/// the time of this comment) that aren't yet using target-specific names for
|
||||
/// multi-target swiftmodules, in case the prebuilt cache is.
|
||||
static Optional<StringRef>
|
||||
computeFallbackPrebuiltModulePath(ASTContext &ctx,
|
||||
StringRef interfacePath,
|
||||
StringRef prebuiltCacheDir,
|
||||
StringRef moduleName,
|
||||
StringRef modulePath,
|
||||
llvm::SmallString<256> &scratch) {
|
||||
namespace path = llvm::sys::path;
|
||||
StringRef sdkPath = ctx.SearchPathOpts.SDKPath;
|
||||
auto &fs = *ctx.SourceMgr.getFileSystem();
|
||||
|
||||
// Check if the interface file comes from the SDK
|
||||
if (sdkPath.empty() || !hasPrefix(path::begin(interfacePath),
|
||||
path::end(interfacePath),
|
||||
path::begin(sdkPath),
|
||||
path::end(sdkPath)))
|
||||
return None;
|
||||
|
||||
// If the module isn't target-specific, there's no fallback path.
|
||||
StringRef inParentDirName =
|
||||
path::filename(path::parent_path(interfacePath));
|
||||
if (path::extension(inParentDirName) != ".swiftmodule")
|
||||
return None;
|
||||
|
||||
// If the interface is already using the target-specific name, there's
|
||||
// nothing else to try.
|
||||
auto normalizedTarget = getTargetSpecificModuleTriple(ctx.LangOpts.Target);
|
||||
if (path::stem(modulePath) == normalizedTarget.str())
|
||||
return None;
|
||||
|
||||
// Assemble the expected path:
|
||||
// $PREBUILT_CACHE/Foo.swiftmodule/target.swiftmodule. Note that there's no
|
||||
// cache key here.
|
||||
scratch = prebuiltCacheDir;
|
||||
path::append(scratch, inParentDirName);
|
||||
path::append(scratch, normalizedTarget.str());
|
||||
scratch += ".swiftmodule";
|
||||
|
||||
// If there isn't a file at this location, skip returning a path.
|
||||
if (!fs.exists(scratch))
|
||||
return None;
|
||||
|
||||
return scratch.str();
|
||||
}
|
||||
|
||||
/// A module "loader" that looks for .swiftinterface and .swiftmodule files
|
||||
/// for the purpose of determining dependencies, but does not attempt to
|
||||
@@ -181,28 +94,6 @@ public:
|
||||
};
|
||||
}
|
||||
|
||||
Optional<StringRef>
|
||||
swift::computePrebuiltModulePath(ASTContext &ctx,
|
||||
StringRef interfacePath,
|
||||
StringRef prebuiltCacheDir,
|
||||
StringRef moduleName,
|
||||
llvm::SmallString<256> &scratch) {
|
||||
llvm::SmallString<64> modulePath = llvm::sys::path::filename(interfacePath);
|
||||
llvm::sys::path::replace_extension(modulePath,
|
||||
file_types::getExtension(file_types::TY_SwiftModuleFile));
|
||||
auto defaultPath =
|
||||
computePrebuiltModulePathDefault(ctx, interfacePath, prebuiltCacheDir,
|
||||
moduleName, modulePath, scratch);
|
||||
if (defaultPath.hasValue())
|
||||
return defaultPath;
|
||||
else
|
||||
return computeFallbackPrebuiltModulePath(ctx, interfacePath,
|
||||
prebuiltCacheDir,
|
||||
moduleName,
|
||||
modulePath,
|
||||
scratch);
|
||||
}
|
||||
|
||||
ErrorOr<ModuleDependencies> ModuleDependencyScanner::scanInterfaceFile(
|
||||
Twine moduleInterfacePath) {
|
||||
// Create a module filename.
|
||||
|
||||
Reference in New Issue
Block a user