ModuleObjCTrace/CAS: compute objc trace file paths via the canoical supplementary output paths computation

CAS support in compiler relies on supplementary paths to decide the mapping between input and output files. Therefore, we
have to compute the paths of the module ObjC trace files in this canonical place to have CAS support for
this newly added ObjC message trace files.
This commit is contained in:
Xi Ge
2024-11-20 08:49:04 -08:00
parent fc1dac7e77
commit 51a68ecdd1
8 changed files with 32 additions and 10 deletions

View File

@@ -73,6 +73,7 @@ TYPE("tbd", TBD, "tbd", "")
// engineers can see more details on the "Swift module traces" page in the
// Swift section of the internal wiki.
TYPE("module-trace", ModuleTrace, "trace.json", "")
TYPE("module-objc-trace", ModuleObjCTrace, "", "")
// Complete dependency information for the given Swift files as JSON.
TYPE("json-dependencies", JSONDependencies, "dependencies.json", "")

View File

@@ -106,6 +106,7 @@ OUTPUT(FixItsOutputPath, TY_SwiftFixIt)
/// to each .swiftmodule that was loaded while building module NAME for target
/// TARGET. This format is subject to arbitrary change, however.
OUTPUT(LoadedModuleTracePath, TY_ModuleTrace)
OUTPUT(ModuleObjCTracePath, TY_ModuleObjCTrace)
/// The path to which we should output a TBD file.
///

View File

@@ -133,6 +133,9 @@ public:
StringRef getLoadedModuleTracePath() const {
return getPrimarySpecificPaths().SupplementaryOutputs.LoadedModuleTracePath;
}
StringRef getModuleObjCTracePath() const {
return getPrimarySpecificPaths().SupplementaryOutputs.ModuleObjCTracePath;
}
StringRef getSerializedDiagnosticsPath() const {
return getPrimarySpecificPaths().SupplementaryOutputs
.SerializedDiagnosticsPath;

View File

@@ -105,6 +105,7 @@ bool file_types::isTextual(ID Id) {
case file_types::TY_ImportedModules:
case file_types::TY_TBD:
case file_types::TY_ModuleTrace:
case file_types::TY_ModuleObjCTrace:
case file_types::TY_YAMLOptRecord:
case file_types::TY_SwiftModuleInterfaceFile:
case file_types::TY_PrivateSwiftModuleInterfaceFile:
@@ -186,6 +187,7 @@ bool file_types::isAfterLLVM(ID Id) {
case file_types::TY_Remapping:
case file_types::TY_IndexData:
case file_types::TY_ModuleTrace:
case file_types::TY_ModuleObjCTrace:
case file_types::TY_YAMLOptRecord:
case file_types::TY_BitstreamOptRecord:
case file_types::TY_SwiftModuleInterfaceFile:
@@ -249,6 +251,7 @@ bool file_types::isPartOfSwiftCompilation(ID Id) {
case file_types::TY_Remapping:
case file_types::TY_IndexData:
case file_types::TY_ModuleTrace:
case file_types::TY_ModuleObjCTrace:
case file_types::TY_YAMLOptRecord:
case file_types::TY_BitstreamOptRecord:
case file_types::TY_JSONDependencies:
@@ -311,6 +314,7 @@ bool file_types::isProducedFromDiagnostics(ID Id) {
case file_types::TY_Remapping:
case file_types::TY_IndexData:
case file_types::TY_ModuleTrace:
case file_types::TY_ModuleObjCTrace:
case file_types::TY_YAMLOptRecord:
case file_types::TY_BitstreamOptRecord:
case file_types::TY_JSONDependencies:

View File

@@ -1691,6 +1691,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
case file_types::TY_PCH:
case file_types::TY_ImportedModules:
case file_types::TY_ModuleTrace:
case file_types::TY_ModuleObjCTrace:
case file_types::TY_YAMLOptRecord:
case file_types::TY_BitstreamOptRecord:
case file_types::TY_SwiftModuleInterfaceFile:

View File

@@ -763,6 +763,7 @@ const char *ToolChain::JobContext::computeFrontendModeForCompile() const {
case file_types::TY_SwiftDeps:
case file_types::TY_ExternalSwiftDeps:
case file_types::TY_ModuleTrace:
case file_types::TY_ModuleObjCTrace:
case file_types::TY_TBD:
case file_types::TY_YAMLOptRecord:
case file_types::TY_BitstreamOptRecord:
@@ -1038,6 +1039,7 @@ ToolChain::constructInvocation(const BackendJobAction &job,
case file_types::TY_ExternalSwiftDeps:
case file_types::TY_Remapping:
case file_types::TY_ModuleTrace:
case file_types::TY_ModuleObjCTrace:
case file_types::TY_YAMLOptRecord:
case file_types::TY_BitstreamOptRecord:
case file_types::TY_SwiftModuleInterfaceFile:

View File

@@ -455,6 +455,23 @@ SupplementaryOutputPathsComputer::computeOutputPathsForOneInput(
file_types::TY_ModuleTrace, "",
defaultSupplementaryOutputPathExcludingExtension);
// We piggy-back on the loadedModuleTracePath to decide (1) whether
// to emit the ObjC Trace file, and (2) where to emit the objc trace file if
// the path isn't explicitly given by SWIFT_COMPILER_OBJC_MESSAGE_TRACE_PATH.
// FIXME: we probably need to move this to a frontend argument.
llvm::SmallString<128> ModuleObjCTracePath;
if (!loadedModuleTracePath.empty()) {
if (const char *P = ::getenv("SWIFT_COMPILER_OBJC_MESSAGE_TRACE_PATH")) {
StringRef FilePath = P;
llvm::sys::path::append(ModuleObjCTracePath, FilePath);
} else {
llvm::sys::path::append(ModuleObjCTracePath, loadedModuleTracePath);
llvm::sys::path::remove_filename(ModuleObjCTracePath);
llvm::sys::path::append(ModuleObjCTracePath,
".SWIFT_FINE_DEPENDENCY_TRACE.json");
}
}
auto tbdPath = determineSupplementaryOutputFilename(
OPT_emit_tbd, pathsFromArguments.TBDPath, file_types::TY_TBD, "",
defaultSupplementaryOutputPathExcludingExtension);
@@ -520,6 +537,7 @@ SupplementaryOutputPathsComputer::computeOutputPathsForOneInput(
sop.SerializedDiagnosticsPath = serializedDiagnosticsPath;
sop.FixItsOutputPath = fixItsOutputPath;
sop.LoadedModuleTracePath = loadedModuleTracePath;
sop.ModuleObjCTracePath = ModuleObjCTracePath.str().str();
sop.TBDPath = tbdPath;
sop.ModuleInterfaceOutputPath = ModuleInterfaceOutputPath;
sop.PrivateModuleInterfaceOutputPath = PrivateModuleInterfaceOutputPath;

View File

@@ -854,7 +854,8 @@ public:
};
static void createObjCMessageTraceFile(const InputFile &input, ModuleDecl *MD) {
if (input.getLoadedModuleTracePath().empty()) {
StringRef tracePath = input.getModuleObjCTracePath();
if (tracePath.empty()) {
// we basically rely on the passing down of module trace file path
// as an indicator that this job needs to emit an ObjC message trace file.
// FIXME: add a separate swift-frontend flag for ObjC message trace path
@@ -882,15 +883,6 @@ static void createObjCMessageTraceFile(const InputFile &input, ModuleDecl *MD) {
if (filesToWalk.empty()) {
return;
}
llvm::SmallString<128> tracePath;
if (const char *P = ::getenv("SWIFT_COMPILER_OBJC_MESSAGE_TRACE_PATH")) {
StringRef FilePath = P;
llvm::sys::path::append(tracePath, FilePath);
} else {
llvm::sys::path::append(tracePath, input.getLoadedModuleTracePath());
llvm::sys::path::remove_filename(tracePath);
llvm::sys::path::append(tracePath, ".SWIFT_FINE_DEPENDENCY_TRACE.json");
}
// Write output via atomic append.
llvm::vfs::OutputConfig config;
config.setAppend().setAtomicWrite();