Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support -file-compilation-dir #40735

Merged
merged 8 commits into from Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/Option/Options.td
Expand Up @@ -840,6 +840,10 @@ def coverage_prefix_map : Separate<["-"], "coverage-prefix-map">,
Flags<[FrontendOption]>,
HelpText<"Remap source paths in coverage info">, MetaVarName<"<prefix=replacement>">;

def file_compilation_dir : Separate<["-"], "file-compilation-dir">,
Flags<[FrontendOption]>, MetaVarName<"<path>">,
HelpText<"The compilation directory to embed in the debug info. Coverage mapping is not supported yet.">;

def debug_info_format : Joined<["-"], "debug-info-format=">,
Flags<[FrontendOption]>,
HelpText<"Specify the debug info format type to either 'dwarf' or 'codeview'">;
Expand Down
3 changes: 3 additions & 0 deletions lib/Driver/ToolChains.cpp
Expand Up @@ -334,6 +334,9 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
auto OptArg = inputArgs.getLastArgNoClaim(options::OPT_O_Group);
if (!OptArg || OptArg->getOption().matches(options::OPT_Onone))
arguments.push_back("-enable-anonymous-context-mangled-names");

// TODO: Should we support -fcoverage-compilation-dir?
inputArgs.AddAllArgs(arguments, options::OPT_file_compilation_dir);
}

// Pass through any subsystem flags.
Expand Down
12 changes: 8 additions & 4 deletions lib/Frontend/CompilerInvocation.cpp
Expand Up @@ -1822,10 +1822,14 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
RenderedArgs, SDKPath,
ResourceDir);
}
// TODO: Should we support -fdebug-compilation-dir?
llvm::SmallString<256> cwd;
llvm::sys::fs::current_path(cwd);
Opts.DebugCompilationDir = std::string(cwd.str());

if (const Arg *A = Args.getLastArg(OPT_file_compilation_dir))
Opts.DebugCompilationDir = A->getValue();
else {
llvm::SmallString<256> cwd;
llvm::sys::fs::current_path(cwd);
Opts.DebugCompilationDir = std::string(cwd.str());
}
}

if (const Arg *A = Args.getLastArg(options::OPT_debug_info_format)) {
Expand Down
20 changes: 20 additions & 0 deletions test/DebugInfo/file_compilation_dir.swift
@@ -0,0 +1,20 @@
// UNSUPPORTED: OS=windows-msvc
// RUN: %target-swiftc_driver -g \
// RUN: -c -file-compilation-dir /path/to \
// RUN: %s -o - -emit-ir | %FileCheck --check-prefix=CHECK-ABS %s
// RUN: %empty-directory(%t)
// RUN: mkdir -p %t
// RUN: cd %t
// RUN: cp %s .
// RUN: %target-swiftc_driver -g \
// RUN: -c -file-compilation-dir /path/to \
// RUN: file_compilation_dir.swift -o - -emit-ir | %FileCheck --check-prefix=CHECK-REL %s
// RUN: %target-swiftc_driver -g \
// RUN: -c -file-compilation-dir . \
// RUN: file_compilation_dir.swift -o - -emit-ir | %FileCheck --check-prefix=CHECK-REL-CWD %s

func foo() {}

// CHECK-ABS: !DIFile(filename: "{{.*}}/file_compilation_dir.swift", directory: "/path/to")
// CHECK-REL: !DIFile(filename: "file_compilation_dir.swift", directory: "/path/to")
// CHECK-REL-CWD: !DIFile(filename: "file_compilation_dir.swift", directory: ".")
20 changes: 20 additions & 0 deletions test/DebugInfo/file_compilation_dir_windows.swift
@@ -0,0 +1,20 @@
// REQUIRES: OS=windows-msvc
// RUN: %target-swiftc_driver -g \
// RUN: -c -file-compilation-dir Z:\path\to \
// RUN: %s -o - -emit-ir | %FileCheck --check-prefix=CHECK-ABS %s
// RUN: %empty-directory(%t)
// RUN: mkdir -p %t
// RUN: cd %t
// RUN: cp %s .
// RUN: %target-swiftc_driver -g \
// RUN: -c -file-compilation-dir Z:\path\to \
// RUN: file_compilation_dir.swift -o - -emit-ir | %FileCheck --check-prefix=CHECK-REL %s
// RUN: %target-swiftc_driver -g \
// RUN: -c -file-compilation-dir . \
// RUN: file_compilation_dir.swift -o - -emit-ir | %FileCheck --check-prefix=CHECK-REL-CWD %s

func foo() {}

// CHECK-ABS: !DIFile(filename: "{{[a-zA-Z]:\\\\.*\\\\}}file_compilation_dir.swift", directory: "Z:\\path\\to")
// CHECK-REL: !DIFile(filename: "file_compilation_dir.swift", directory: "Z:\\path\\to")
// CHECK-REL-CWD: !DIFile(filename: "file_compilation_dir.swift", directory: ".")