xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.91k stars 777 forks source link

Xmake generates invalid compilation database #3159

Closed poscat0x04 closed 1 year ago

poscat0x04 commented 1 year ago

Xmake Version

v2.7.3+202211090100

Operating System Version and Architecture

macOS Monterey

Describe Bug

When being used to compile 墨干 on macOS, xmake generates invalid compilation database files:

[
{
  "directory": "/Users/poscat/Projects/mogan",
  "arguments": ["/usr/bin/xcrun -sdk macosx clang", "-c", "-Qunused-arguments", "-target", "arm64-apple-macos12.6", "-isysroot", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk", "-g", "-O0", "-std=c++17", "-Itests/Base", "-I/Users/poscat/Projects/mogan/build/.gens/url_test/macosx/arm64/debug/rules/qt/ui", "-Isrc/Data/Convert", "-Isrc/Data/Document", "-Isrc/Data/Drd", "-Isrc/Data/History", "-Isrc/Data/Observers", "-Isrc/Data/Parser", "-Isrc/Data/String", "-Isrc/Data/Tree", "-Isrc/Edit", "-Isrc/Edit/Editor", "-Isrc/Edit/Interface", "-Isrc/Edit/Modify", "-Isrc/Edit/Process", "-Isrc/Edit/Replace", "-Isrc/Graphics/Bitmap_fonts", "-Isrc/Graphics/Colors", "-Isrc/Graphics/Fonts", "-Isrc/Graphics/Gui", "-Isrc/Graphics/Handwriting", "-Isrc/Graphics/Mathematics", "-Isrc/Graphics/Pictures", "-Isrc/Graphics/Renderer", "-Isrc/Graphics/Spacial", "-Isrc/Graphics/Types", "-Isrc/Kernel/Abstractions", "-Isrc/Kernel/Containers", "-Isrc/Kernel/Types", "-Isrc/Plugins", "-Isrc/Plugins/Pdf", "-Isrc/Plugins/Pdf/PDFWriter", "-Isrc/Plugins/Pdf/LibAesgm", "-Isrc/Plugins/Qt", "-Isrc/Plugins/UniversalStacktrace", "-Isrc/Scheme", "-Isrc/Scheme/S7", "-Isrc/Scheme/Scheme", "-Isrc/Style/Environment", "-Isrc/Style/Evaluate", "-Isrc/Style/Memorizer", "-Isrc/System", "-Isrc/System/Memory", "-Isrc/System/IO", "-Isrc/System/Boot", "-Isrc/System/Classes", "-Isrc/System/Files", "-Isrc/System/Language", "-Isrc/System/Link", "-Isrc/System/Misc", "-Isrc/Texmacs", "-Isrc/Texmacs/Data", "-Isrc/Typeset", "-Isrc/Typeset/Bridge", "-Isrc/Typeset/Concat", "-Isrc/Typeset/Page", "-ITeXmacs/include", "-Isrc/Plugins/MacOS", "-DQTTEXMACS", "-DQTPIPES", "-DUSE_QT_PRINTER", "-DQT_QML_DEBUG", "-DQT_DEPRECATED_WARNINGS", "-DQT_GUI_LIB", "-DQT_WIDGETS_LIB", "-DQT_PRINTSUPPORT_LIB", "-DQT_SVG_LIB", "-DQT_TEST_LIB", "-DQT_CORE_LIB", "-F/opt/homebrew/Cellar/qt@5/5.15.7/lib", "-framework", "QtTest", "-framework", "DiskArbitration", "-framework", "IOKit", "-framework", "CoreGraphics", "-framework", "OpenGL", "-framework", "Carbon", "-framework", "AppKit", "-framework", "QtGui", "-framework", "QtWidgets", "-framework", "QtPrintSupport", "-framework", "QtSvg", "-framework", "QtMacExtras", "-framework", "QtCore", "-framework", "CoreFoundation", "-framework", "Foundation", "-framework", "Security", "-framework", "SystemConfiguration", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtGui.framework/Headers", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtGui.framework/Headers/5.15.7", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtGui.framework/Headers/5.15.7/QtGui", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtWidgets.framework/Headers", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtWidgets.framework/Headers/5.15.7", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtWidgets.framework/Headers/5.15.7/QtWidgets", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtPrintSupport.framework/Headers", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtPrintSupport.framework/Headers/5.15.7", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtPrintSupport.framework/Headers/5.15.7/QtPrintSupport", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtSvg.framework/Headers", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtSvg.framework/Headers/5.15.7", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtSvg.framework/Headers/5.15.7/QtSvg", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtTest.framework/Headers", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtTest.framework/Headers/5.15.7", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtTest.framework/Headers/5.15.7/QtTest", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtCore.framework/Headers", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtCore.framework/Headers/5.15.7", "-I", "/opt/homebrew/Cellar/qt@5/5.15.7/lib/QtCore.framework/Headers/5.15.7/QtCore", "-fPIC", "-o", "build/.objs/url_test/macosx/arm64/debug/tests/Base/base.cpp.o", "tests/Base/base.cpp"],
  "file": "tests/Base/base.cpp"
},
... (omitted)

(full file)

As you can see, the first argument, "/usr/bin/xcrun -sdk macosx clang" is invalid as it does not point to an executable and should be broken up into four arguments instead.

Expected Behavior

The generated compilation database file should be valid

Project Configuration

No response

Additional Information and Error Logs

To reproduce, just clone mogan and run xmake project -k compile_commands

waruqi commented 1 year ago

As you can see, the first argument, "/usr/bin/xcrun -sdk macosx clang" is invalid as it does not point to an executable and should be broken up into four arguments instead.

no, it's valid and it works for me. It has been around for a long time and no other user has ever reported an error because of it.

poscat0x04 commented 1 year ago

According to the spec of compilation database, the first argument should be the executable name. This is also how CLion interprets it, which leads to errors when using CLion.

waruqi commented 1 year ago

which leads to errors when using CLion.

which errors? it works for vscode on my machine and I cannot get any errors in CLion.

poscat0x04 commented 1 year ago

CLion complains about not being able to find "/usr/bin/xcrun -sdk macosx clang" in path (which I think is 100% justified)

waruqi commented 1 year ago

I can't reproduce the problem at the moment, so you can verify that it works by manually changing it to something like the following.

  "arguments": ["/usr/bin/xcrun", "-sdk", "macosx", "clang", "-c", "-Qunused-arguments", "-target", "arm64-apple-macos12.6", ...

If this works, I will try to improve it.

poscat0x04 commented 1 year ago

Yes, breaking up the first argument does work.

waruqi commented 1 year ago

try it again, xmake update -s dev

waruqi commented 1 year ago

but clangd does not support ["/usr/bin/xcrun", "-sdk", "macosx", "clang"

https://github.com/xmake-io/xmake/issues/3286

waruqi commented 1 year ago

I improved it again, it will convert to "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"

xmake update -s dev