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 for ad-hoc diagnostic and fixits #25

Open
jerrymarino opened this issue Feb 4, 2021 · 4 comments
Open

Support for ad-hoc diagnostic and fixits #25

jerrymarino opened this issue Feb 4, 2021 · 4 comments

Comments

@jerrymarino
Copy link
Owner

jerrymarino commented Feb 4, 2021

Consider adding a way to emit ad-hoc diagnostics and fixits for swift and clang. There's a different codepath for these in Xcode's UI with xcbuild. It's likely possible to add this support in just a SWIFT_EXEC stub, however it might interface nicely inside of this build system.

Prototype

FunnyLookingSwiftOutput

Prototype impl

I've created a prototype of this by stubbing out SWIFT_EXEC, and attached a demo project with the relevant details

# Example of stubbing out `SWIFT_EXEC` with a program that can transmit arbitrary diags
def _main():
    # type: () -> None
    if sys.argv[1:] == ["-v"]:
        os.system("swiftc -v")
        return

    _touch_deps_files(sys.argv)
    _touch_swiftmodule_files(sys.argv)


    os.system("mkdir -p  /Users/jmarino/Library/Developer/Xcode/DerivedData/Some-hettvdxoaohocfempirmoljvflkq/Build/Intermediates.noindex/Some.build/Debug/Some.build/Objects-normal/x86_64/")

    # During xcbuild, the build system seems to read in a dia. This is a
    # contrived diagnostic file, but xcbuild reads it in once swiftc emits it.
    # /tmp/main.dia resides in-tree at TMP_main.dia
    os.system("cp /tmp/main.dia /Users/jmarino/Library/Developer/Xcode/DerivedData/Some-hettvdxoaohocfempirmoljvflkq/Build/Intermediates.noindex/Some.build/Debug/Some.build/Objects-normal/x86_64/main.dia")

    os.system("echo xxxxx > /Users/jmarino/Library/Developer/Xcode/DerivedData/Some-hettvdxoaohocfempirmoljvflkq/Build/Intermediates.noindex/Some.build/Debug/Some.build/Objects-normal/x86_64/main.o")

    # Under the xcbuild, it runs the swift compiler with -parseable output. XCBuild
    # parses this is and dumps message pack material over the stdout file descriptor 
    # which Xcode further processes.
    # NOTE: for swift compilation, the .dias must be on the file system in this file.
    # /tmp/out resides in-tree at TMP_out
    os.system("cat /tmp/out >&2")

I have attached an example of the swiftc stub working - DiagReversingExample.zip

@thiagohmcruz
Copy link
Collaborator

Nice! Thx for sharing an example project, will definitely play around with it

@jerrymarino
Copy link
Owner Author

You've got it! This was original in the context of swift, but I'd imagine that it can pickup the .dia from clang, perhaps w/o having to mess around with -parseable-output

@jerrymarino
Copy link
Owner Author

That is, there's a code path for clang we might be able to leverage that's significantly easier.

@jerrymarino
Copy link
Owner Author

I'm wondering if we can just write out BUILD_DIAGNOSTIC_EMITTED. It looks like that message is implemented

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

No branches or pull requests

2 participants