Skip to content

Commit ec9cf33

Browse files
committed
Driver: expose -emit-module-source-info-path as a driver option
1 parent 5759fe6 commit ec9cf33

File tree

6 files changed

+31
-7
lines changed

6 files changed

+31
-7
lines changed

cmake/modules/SwiftSource.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,12 @@ function(_compile_swift_files
311311
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
312312
set(specific_module_dir "${module_base}.swiftmodule")
313313
set(specific_module_private_dir "${specific_module_dir}/Private")
314+
set(source_info_file "${specific_module_private_dir}/${SWIFTFILE_ARCHITECTURE}.swiftsourceinfo")
314315
set(module_base "${module_base}.swiftmodule/${SWIFTFILE_ARCHITECTURE}")
315316
else()
316317
set(specific_module_dir)
317318
set(specific_module_private_dir)
319+
set(source_info_file "${module_base}.swiftsourceinfo")
318320
endif()
319321
set(module_file "${module_base}.swiftmodule")
320322
set(module_doc_file "${module_base}.swiftdoc")
@@ -324,6 +326,8 @@ function(_compile_swift_files
324326
set(sib_file "${module_base}.Onone.sib")
325327
set(sibopt_file "${module_base}.O.sib")
326328
set(sibgen_file "${module_base}.sibgen")
329+
list(APPEND swift_module_flags
330+
"-emit-module-source-info-path" "${source_info_file}")
327331

328332
if(SWIFT_ENABLE_MODULE_INTERFACES)
329333
set(interface_file "${module_base}.swiftinterface")

include/swift/Driver/Driver.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/Basic/OutputFileMap.h"
2525
#include "swift/Basic/Sanitizers.h"
2626
#include "swift/Driver/Util.h"
27+
#include "swift/Option/Options.h"
2728
#include "llvm/ADT/DenseMap.h"
2829
#include "llvm/ADT/StringMap.h"
2930
#include "llvm/ADT/StringRef.h"
@@ -358,7 +359,8 @@ class Driver {
358359
const TypeToPathMap *OutputMap,
359360
StringRef workingDirectory,
360361
CommandOutput *Output,
361-
file_types::ID fileID) const;
362+
file_types::ID fileID,
363+
Optional<options::ID> DriverOptForPath = llvm::None) const;
362364

363365
void chooseModuleInterfacePath(Compilation &C, const JobAction *JA,
364366
StringRef workingDirectory,

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ def emit_module_doc_path
4040

4141
def emit_module_source_info : Flag<["-"], "emit-module-source-info">,
4242
HelpText<"Output module source info file">;
43-
def emit_module_source_info_path : Separate<["-"], "emit-module-source-info-path">,
44-
HelpText<"Output module source info file to <path>">;
4543

4644
def merge_modules
4745
: Flag<["-"], "merge-modules">, ModeOpt,

include/swift/Option/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ def emit_module_interface_path :
364364
ArgumentIsPath]>,
365365
MetaVarName<"<path>">, HelpText<"Output module interface file to <path>">;
366366

367+
def emit_module_source_info_path :
368+
Separate<["-"], "emit-module-source-info-path">,
369+
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
370+
ArgumentIsPath]>,
371+
MetaVarName<"<path>">, HelpText<"Output module source info file to <path>">;
372+
367373
def emit_parseable_module_interface :
368374
Flag<["-"], "emit-parseable-module-interface">,
369375
Alias<emit_module_interface>,

lib/Driver/Driver.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,8 @@ Job *Driver::buildJobsForAction(Compilation &C, const JobAction *JA,
25452545
(isa<CompileJobAction>(JA) || isa<MergeModuleJobAction>(JA))) {
25462546
chooseSwiftModuleDocOutputPath(C, OutputMap, workingDirectory, Output.get());
25472547
choosePrivateOutputFilePath(C, OutputMap, workingDirectory, Output.get(),
2548-
file_types::TY_SwiftSourceInfoFile);
2548+
file_types::TY_SwiftSourceInfoFile,
2549+
options::OPT_emit_module_source_info_path);
25492550
}
25502551

25512552
if (C.getArgs().hasArg(options::OPT_emit_module_interface,
@@ -2793,9 +2794,17 @@ void Driver::choosePrivateOutputFilePath(Compilation &C,
27932794
const TypeToPathMap *OutputMap,
27942795
StringRef workingDirectory,
27952796
CommandOutput *Output,
2796-
file_types::ID fileID) const {
2797+
file_types::ID fileID,
2798+
Optional<options::ID> optId) const {
27972799
if (hasExistingAdditionalOutput(*Output, fileID))
27982800
return;
2801+
// Honor driver option for this path if it's given
2802+
if (optId.hasValue()) {
2803+
if (const Arg *A = C.getArgs().getLastArg(*optId)) {
2804+
Output->setAdditionalOutputForType(fileID, StringRef(A->getValue()));
2805+
return;
2806+
}
2807+
}
27992808

28002809
StringRef OFMOutputPath;
28012810
if (OutputMap) {

test/Driver/sourceinfo_file.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
// RUN: mkdir -p %t/build/Private
33
// RUN: %swiftc_driver -driver-print-jobs -emit-module %s -emit-module-path %t/build/sourceinfo_file.swiftmodule -module-name sourceinfo_file | %FileCheck %s -check-prefix CHECK-PRIVATE
44

5-
// CHECK-PRIVATE: Private/sourceinfo_file.swiftsourceinfo
5+
// CHECK-PRIVATE: build/Private/sourceinfo_file.swiftsourceinfo
66

77
// RUN: %empty-directory(%t/build)
88
// RUN: %swiftc_driver -driver-print-jobs -emit-module %s -emit-module-path %t/build/sourceinfo_file.swiftmodule -module-name sourceinfo_file | %FileCheck %s -check-prefix CHECK-NOPRIVATE
99

1010
// CHECK-NOPRIVATE-NOT: Private/sourceinfo_file.swiftsourceinfo
11-
// CHECK-NOPRIVATE: sourceinfo_file.swiftsourceinfo
11+
// CHECK-NOPRIVATE: build/sourceinfo_file.swiftsourceinfo
12+
13+
// RUN: %empty-directory(%t/build)
14+
// RUN: %swiftc_driver -driver-print-jobs -emit-module %s -emit-module-path %t/build/sourceinfo_file.swiftmodule -module-name sourceinfo_file -emit-module-source-info-path %t/build/DriverPath.swiftsourceinfo | %FileCheck %s -check-prefix CHECK-DRIVER-OPT
15+
16+
// CHECK-DRIVER-OPT: build/DriverPath.swiftsourceinfo

0 commit comments

Comments
 (0)