diff --git a/include/swift/Basic/FileTypes.def b/include/swift/Basic/FileTypes.def index 1955f0af169..b8373557261 100644 --- a/include/swift/Basic/FileTypes.def +++ b/include/swift/Basic/FileTypes.def @@ -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", "") diff --git a/include/swift/Basic/SupplementaryOutputPaths.def b/include/swift/Basic/SupplementaryOutputPaths.def index 56b376bc052..629c299f5e5 100644 --- a/include/swift/Basic/SupplementaryOutputPaths.def +++ b/include/swift/Basic/SupplementaryOutputPaths.def @@ -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. /// diff --git a/include/swift/Frontend/InputFile.h b/include/swift/Frontend/InputFile.h index 8d8e8be8d4e..3a8b9b0f6a5 100644 --- a/include/swift/Frontend/InputFile.h +++ b/include/swift/Frontend/InputFile.h @@ -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; diff --git a/lib/Basic/FileTypes.cpp b/lib/Basic/FileTypes.cpp index 479958a4392..7f6e4739e0f 100644 --- a/lib/Basic/FileTypes.cpp +++ b/lib/Basic/FileTypes.cpp @@ -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: diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 5f9fdf9bfee..d24ae69d483 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1691,6 +1691,7 @@ void Driver::buildActions(SmallVectorImpl &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: diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 4ee71949b37..caeb1455334 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -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: diff --git a/lib/Frontend/ArgsToFrontendOutputsConverter.cpp b/lib/Frontend/ArgsToFrontendOutputsConverter.cpp index 8f03512de13..17ba58b1ebe 100644 --- a/lib/Frontend/ArgsToFrontendOutputsConverter.cpp +++ b/lib/Frontend/ArgsToFrontendOutputsConverter.cpp @@ -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; diff --git a/lib/FrontendTool/LoadedModuleTrace.cpp b/lib/FrontendTool/LoadedModuleTrace.cpp index 5cf2be304e4..bad6a28eb90 100644 --- a/lib/FrontendTool/LoadedModuleTrace.cpp +++ b/lib/FrontendTool/LoadedModuleTrace.cpp @@ -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();