diff options
| author | Saikari <[email protected]> | 2026-01-30 20:42:57 +0300 |
|---|---|---|
| committer | Saikari <[email protected]> | 2026-01-30 20:42:57 +0300 |
| commit | b006af493bff65fcffd198db70ec2c8046f6575e (patch) | |
| tree | 6e40e74d2a966cc40160c713f3947f5edb5d2620 | |
| parent | 51a68ee33918b95811420beb6a56673a83abe6cc (diff) | |
enhance compile_commands support and add test cases
| -rw-r--r-- | tests/projects/policy/compile_commands/src/disabled.c | 3 | ||||
| -rw-r--r-- | tests/projects/policy/compile_commands/src/main.c | 3 | ||||
| -rw-r--r-- | tests/projects/policy/compile_commands/xmake.lua | 10 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 5 | ||||
| -rw-r--r-- | xmake/core/project/policy.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/project/clang/compile_commands.lua | 5 |
6 files changed, 27 insertions, 1 deletions
diff --git a/tests/projects/policy/compile_commands/src/disabled.c b/tests/projects/policy/compile_commands/src/disabled.c new file mode 100644 index 000000000..9b130982d --- /dev/null +++ b/tests/projects/policy/compile_commands/src/disabled.c @@ -0,0 +1,3 @@ +int main(int argc, char** argv) { + return 0; +} diff --git a/tests/projects/policy/compile_commands/src/main.c b/tests/projects/policy/compile_commands/src/main.c new file mode 100644 index 000000000..9b130982d --- /dev/null +++ b/tests/projects/policy/compile_commands/src/main.c @@ -0,0 +1,3 @@ +int main(int argc, char** argv) { + return 0; +} diff --git a/tests/projects/policy/compile_commands/xmake.lua b/tests/projects/policy/compile_commands/xmake.lua new file mode 100644 index 000000000..03f8a788d --- /dev/null +++ b/tests/projects/policy/compile_commands/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.debug", "mode.release") + +target("enabled") + set_kind("binary") + add_files("src/main.c") + +target("disabled") + set_kind("binary") + add_files("src/main.c") + set_policy("build.compile_commands", false) diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 12bc30c1d..9332f2c61 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -1187,7 +1187,10 @@ function os.isexec(filepath) end end elseif os.isfile(filepath) then - return os._access(filepath, "x") + if os._access then + return os._access(filepath, "x") + end + return true end return false end diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 1cecfd01a..51631e408 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -98,6 +98,8 @@ function policy.policies() -- Force C++ modules fallback dependency scanner for msvc ["build.c++.modules.msvc.fallbackscanner"] = {description = "Force msvc fallback module dependency scanner.", default = false, type = "boolean"}, ["build.c++.msvc.fallbackscanner"] = {description = "Force msvc fallback module dependency scanner. (deprecated)", default = false, type = "boolean"}, + -- Enable compile_commands + ["build.compile_commands"] = {description = "Enable compile_commands.", default = true, type = "boolean"}, -- Force C++ modules fallback dependency scanner for gcc ["build.c++.modules.gcc.fallbackscanner"] = {description = "Force gcc fallback module dependency scanner.", default = false, type = "boolean"}, ["build.c++.gcc.fallbackscanner"] = {description = "Force gcc fallback module dependency scanner. (deprecated)", default = false, type = "boolean"}, diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index 4f01354fa..28f4a876b 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -266,6 +266,11 @@ function _add_target(jsonfile, target) -- https://github.com/xmake-io/xmake/issues/2337 target:data_set("plugin.project.kind", "compile_commands") + -- disable compile_commands? + if target:policy("build.compile_commands") == false then + return + end + -- enter package environments local oldenvs = os.addenvs(target:pkgenvs()) |
