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

Conversation

pofat
Copy link
Contributor

@pofat pofat commented Jan 5, 2022

This PR adds a new flag -file-compilation-dir, which does the same thing as -ffile-compilation-dir in Clang.

swiftc -g -ffile-compilation-dir=. path/to/foo.swift gives us identical debug info paths regardless of what location we compiled the file from. It's useful to debug correctly using object files built on different machines in different locations.
There's also a long-existed TODO comment.

Resolves SR-5694

@pofat pofat force-pushed the support_debug_compilation_dir branch 2 times, most recently from e5e911a to ce7377e Compare January 5, 2022 18:30
@kastiglione
Copy link
Contributor

@swift-ci test

Copy link
Contributor

@kastiglione kastiglione left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems proper to me

test/DebugInfo/debug_compilation_dir.swift Outdated Show resolved Hide resolved
test/DebugInfo/debug_compilation_dir.swift Outdated Show resolved Hide resolved
@keith
Copy link
Collaborator

keith commented Jan 5, 2022

Clang has quite a few flags here that imply different things, both for mappings like the $PWD=. style and ones like this. Right now swiftc has -debug-prefix-map and -coverage-prefix-map.

IMO it is worth considering introducing the equivalent of -ffile-prefix-dir . instead of the debug info only specific variant. But I'm just thinking that because we could potentially avoid the large number of related flags down the line.

@swift-ci
Copy link
Collaborator

swift-ci commented Jan 5, 2022

Build failed
Swift Test Linux Platform
Git Sha - ce7377ec6b5d36d54ae6430c001f4fe2e0a6a612

Copy link
Member

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a nice improvement! Some comments inline.

lib/Frontend/CompilerInvocation.cpp Outdated Show resolved Hide resolved
test/DebugInfo/debug_compilation_dir.swift Outdated Show resolved Hide resolved
@@ -334,6 +334,8 @@ 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");

inputArgs.AddAllArgs(arguments, options::OPT_debug_compilation_dir);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this code need to be added to the Swift implementation of the driver, too? (I haven't looked at the Swift driver code recently so I'm not sure)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so. My plan is to address this in the follow up PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be preferable to do both at once, to keep the implementations in sync at all times.

Copy link
Contributor Author

@pofat pofat Jan 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a PR for Swift-implemented driver.

@compnerd
Copy link
Collaborator

compnerd commented Jan 7, 2022

Could you please add a test to ensure that the Windows path separator is handled properly? (\ vs /)

@rmaz
Copy link
Collaborator

rmaz commented Jan 7, 2022

Could you please add a test to ensure that the Windows path separator is handled properly? (\ vs /)

The existing CHECK-ABS test should handle Windows correctly. Would you like to see more tested beyond this?

@compnerd
Copy link
Collaborator

compnerd commented Jan 7, 2022

The existing CHECK-ABS test should handle Windows correctly. Would you like to see more tested beyond this?

Yes, I would. If you note the CHECK-ABS string is looking at a Unix style separator. I would like to see a test that explicitly tests for Windows style paths e.g. S:\SourceCache\swift\stdlib\public\core\Array.swift.

@pofat
Copy link
Contributor Author

pofat commented Jan 7, 2022

Yes, I would. If you note the CHECK-ABS string is looking at a Unix style separator. I would like to see a test that explicitly tests for Windows style paths e.g. S:\SourceCache\swift\stdlib\public\core\Array.swift.

Do you suggest one test for unix and another one for Windows style paths? eg:

// RUN: %target-swiftc_driver -g \
// RUN:   -c -debug-compilation-dir /path/to \
// RUN:   %s -o - -emit-ir | %FileCheck --check-prefix=CHECK-ABS-%target-os %s
// RUN: %empty-directory(%t)

func foo() {}

// CHECK-ABS-ios:       !DIFile(filename: "{{.*}}/debug_compilation_dir.swift", directory: "/path/to")
// CHECK-ABS-macosx:    !DIFile(filename: "{{.*}}/debug_compilation_dir.swift", directory: "/path/to")
// CHECK-ABS-watchos:   !DIFile(filename: "{{.*}}/debug_compilation_dir.swift", directory: "/path/to")
// CHECK-ABS-darwin:    !DIFile(filename: "{{.*}}/debug_compilation_dir.swift", directory: "/path/to")
// CHECK-ABS-objc-linux-gnu:   !DIFile(filename: "{{.*}}/debug_compilation_dir.swift", directory: "/path/to")
// CHECK-ABS-native-linux-gnu: !DIFile(filename: "{{.*}}/debug_compilation_dir.swift", directory: "/path/to")
// CHECK-ABS-objc-windows:     !DIFile(filename: "{{[a-zA-Z]:\\(?:[\\\S|*\S]+[\\\/])}}debug_compilation_dir.swift", directory: "/path/to")
// CHECK-ABS-native-windows:   !DIFile(filename: "{{[a-zA-Z]:\\(?:[\\\S|*\S]+[\\\/])}}debug_compilation_dir.swift", directory: "/path/to")

@pofat pofat force-pushed the support_debug_compilation_dir branch 2 times, most recently from e303397 to e8d2e7e Compare January 10, 2022 19:30
@pofat
Copy link
Contributor Author

pofat commented Jan 10, 2022

hi @compnerd , the test for windows path is added. Would you trigger the tests? Thank you.

@kastiglione
Copy link
Contributor

kastiglione commented Jan 10, 2022

IMO it is worth considering introducing the equivalent of -ffile-prefix-dir . instead of the debug info only specific variant. But I'm just thinking that because we could potentially avoid the large number of related flags down the line.

bumping this. @pofat what do you think?

@kastiglione
Copy link
Contributor

@keith the page linked to for -ffile-prefix-dir doesn't mention that flag.

@rmaz
Copy link
Collaborator

rmaz commented Jan 10, 2022

IMO it is worth considering introducing the equivalent of -ffile-prefix-dir . instead of the debug info only specific variant. But I'm just thinking that because we could potentially avoid the large number of related flags down the line.

bumping this. @pofat what do you think?

Wouldn't we want both? Seems odd that clang would have multiple flags but Swift wouldn't.

@keith
Copy link
Collaborator

keith commented Jan 10, 2022

Sorry it's -ffile-compilation-dir=

Fair question for sure, I think clang's setup has gotten a bit complex related to this stuff, so it wasn't that they have many separate flags intentionally, but more because they can't ever remove any for backwards compatibility but that's just my take.

For reference clang has:

-ffile-compilation-dir=
-ffile-prefix-map=
-fcoverage-compilation-dir=
-fcoverage-prefix-map=
-fdebug-compilation-dir=
-fdebug-prefix-map=
-fmacro-prefix-map=

Where the ffile* flags imply all the others

@pofat
Copy link
Contributor Author

pofat commented Jan 11, 2022

Hi @kastiglione @keith, how about having both flags?
Based on the implantation in clang, -ffile-compilation-dir looks like a shorter syntax for both -fdebug-compilation-dir and -fcoverage-compilation-dir to me.

Personally, I would like to have this flag done in this PR, then do -coverage-compilation-dir and -ffile-compilation-dir in the follow-up PRs.

Not sure what's the best strategy to decide what flags should migrate to Swift. Probably just follow what Clang has, IMO.
What do you guys think?

@keith
Copy link
Collaborator

keith commented Jan 11, 2022

I will defer to the swift maintainers in general here, but my thought was just instead of doing a 1:1 copy from clang we could try to reduce the user facing complexity here, unless we can come up with compelling reasons for them to be separate.

@drodriguez
Copy link
Collaborator

@swift-ci please smoke test

2. Implement the logic: Configure DebugCompilationDir with the path specified by the flag, otherwise with current working directory.
3. Add test case
2. Use %target-swiftc_driver for test case instead
3. Add test case for absolute path
4. Code clean
2. Add a test case for path `.`
3. Use regular expression for file path separator
4. Remove std::string() constructor
5. Remove ArgumentIsPath flag
@pofat pofat force-pushed the support_debug_compilation_dir branch 2 times, most recently from 25fc8e5 to a76960e Compare January 13, 2022 15:55
@pofat
Copy link
Contributor Author

pofat commented Jan 13, 2022

  1. Update this PR to support coverage (given that -coverage-prefix-map exists, maybe it's not that much work, I haven't looked)
  2. Change the name of the flag to -file-compilation-dir, but don't add support for coverage yet, leaving it as a TODO/Issue
  3. Keep this PR as is, and add -debug-compilation-dir

Thanks for the clear explanation of all options! Took option 2 and updated this PR. Also fixed the failed windows test.

@pofat pofat force-pushed the support_debug_compilation_dir branch 2 times, most recently from 03e6a31 to 3ec1c0b Compare January 13, 2022 21:12
@pofat pofat force-pushed the support_debug_compilation_dir branch from 3ec1c0b to 70c4b38 Compare January 13, 2022 21:16
@kastiglione
Copy link
Contributor

@swift-ci test

@kastiglione
Copy link
Contributor

The tests and the PR still mention -debug-compilation-dir.

@pofat pofat changed the title Support -debug-compilation-dir Support -file-compilation-dir Jan 13, 2022
@pofat
Copy link
Contributor Author

pofat commented Jan 13, 2022

@kastiglione I am sorry, might undo some old code while pushing. All fixed.

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - 70c4b38

@kastiglione
Copy link
Contributor

@swift-ci test

@kastiglione
Copy link
Contributor

@swift-ci test Windows Platform

@kastiglione
Copy link
Contributor

can you update the flag for the swift-driver PR as well, in case that results in a separate set of eyes?

@pofat
Copy link
Contributor Author

pofat commented Jan 15, 2022

can you update the flag for the swift-driver PR as well, in case that results in a separate set of eyes?

Sure, I can. Working on it.

@pofat
Copy link
Contributor Author

pofat commented Jan 17, 2022

Done updating swift-driver

@kastiglione
Copy link
Contributor

@swift-ci test Windows Platform

@pofat
Copy link
Contributor Author

pofat commented Jan 19, 2022

@swift-ci test Windows Platform

Thanks! I am working on fix the failed windows test case. Will update once I fix it.

@drodriguez
Copy link
Collaborator

@swift-ci please smoke test

@pofat
Copy link
Contributor Author

pofat commented Jan 27, 2022

@kastiglione failed windows test is fixed. Would you like to review it?

@pofat
Copy link
Contributor Author

pofat commented Jan 27, 2022

@adrian-prantl @kastiglione can you help me merger this PR? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants