mirror of
https://github.com/xenia-project/premake-export-compile-commands.git
synced 2026-01-31 01:25:21 +01:00
Remove options and generate one json per config/platform
This commit is contained in:
18
README.md
18
README.md
@@ -24,13 +24,21 @@ After the above steps, the "export-compile-commands" action will be available
|
||||
for your projects:
|
||||
|
||||
```
|
||||
premake5 export-compile-commands --export-compile-commands-config=Debug --export-compile-commands-platform=x86
|
||||
premake5 export-compile-commands
|
||||
```
|
||||
|
||||
By default, the above command creates a `compile_commands.json` file near your
|
||||
other generated project files, but you can override with the
|
||||
--export-compile-commands-output option:
|
||||
The `export-compile-commands` action will generate one json file per
|
||||
config/platform combination in each workspace, all under the `compile_commands`
|
||||
subdirectory. For example, say you have defined `debug` and `release`
|
||||
configurations with `x32` and `x64` platforms, the output will be something
|
||||
like:
|
||||
|
||||
```
|
||||
premake5 export-compile-commands --export-compile-commands-output=release_compile_commands.json --export-compile-commands-config=Release
|
||||
Generated WORKSPACE_BUILD_DIR/compile_commands/debug_x32.json...
|
||||
Generated WORKSPACE_BUILD_DIR/compile_commands/debug_x64.json...
|
||||
Generated WORKSPACE_BUILD_DIR/compile_commands/release_x32.json...
|
||||
Generated WORKSPACE_BUILD_DIR/compile_commands/release_x64.json...
|
||||
```
|
||||
|
||||
where each file contain the compilation commands for the corresponding
|
||||
config/platform combo.
|
||||
|
||||
@@ -72,19 +72,8 @@ function m.getConfig(prj)
|
||||
end
|
||||
end
|
||||
|
||||
function m.getProjectCommands(prj)
|
||||
function m.getProjectCommands(prj, cfg)
|
||||
local tr = project.getsourcetree(prj)
|
||||
local cfg = m.getConfig(prj)
|
||||
if not cfg then
|
||||
local cfg, plat = _OPTIONS['export-compile-commands-config'],
|
||||
_OPTIONS['export-compile-commands-platform']
|
||||
if plat then
|
||||
p.warn('No configuration %s/%s for project %s', cfg, plat, prj.name)
|
||||
else
|
||||
p.warn('No configuration %s for project %s', cfg, prj.name)
|
||||
end
|
||||
return
|
||||
end
|
||||
local cmds = {}
|
||||
p.tree.traverse(tr, {
|
||||
onleaf = function(node, depth)
|
||||
@@ -99,30 +88,37 @@ end
|
||||
|
||||
local function execute()
|
||||
for wks in p.global.eachWorkspace() do
|
||||
local wksCmds = {}
|
||||
local cfgCmds = {}
|
||||
for prj in workspace.eachproject(wks) do
|
||||
wksCmds = table.join(wksCmds, m.getProjectCommands(prj))
|
||||
end
|
||||
local outfile =
|
||||
_OPTIONS['export-compile-commands-output'] or 'compile_commands.json'
|
||||
p.generate(wks, outfile, function(wks)
|
||||
local jsonCmds = {}
|
||||
for i = 1, #wksCmds do
|
||||
local item = wksCmds[i]
|
||||
table.insert(jsonCmds, string.format([[
|
||||
{
|
||||
"directory": "%s",
|
||||
"file": "%s",
|
||||
"command": "%s"
|
||||
}]],
|
||||
item.directory,
|
||||
item.file,
|
||||
item.command:gsub('\\', '\\\\'):gsub('"', '\\"')))
|
||||
for cfg in project.eachconfig(prj) do
|
||||
local cfgKey = string.format('%s', cfg.shortname)
|
||||
if not cfgCmds[cfgKey] then
|
||||
cfgCmds[cfgKey] = {}
|
||||
end
|
||||
cfgCmds[cfgKey] = table.join(cfgCmds[cfgKey], m.getProjectCommands(prj, cfg))
|
||||
end
|
||||
p.w('[')
|
||||
p.w(table.concat(jsonCmds, ',\n'))
|
||||
p.w(']')
|
||||
end)
|
||||
end
|
||||
for cfgKey,cmds in pairs(cfgCmds) do
|
||||
local outfile = string.format('compile_commands/%s.json', cfgKey)
|
||||
p.generate(wks, outfile, function(wks)
|
||||
local jsonCmds = {}
|
||||
for i = 1, #cmds do
|
||||
local item = cmds[i]
|
||||
table.insert(jsonCmds, string.format([[
|
||||
{
|
||||
"directory": "%s",
|
||||
"file": "%s",
|
||||
"command": "%s"
|
||||
}]],
|
||||
item.directory,
|
||||
item.file,
|
||||
item.command:gsub('\\', '\\\\'):gsub('"', '\\"')))
|
||||
end
|
||||
p.w('[')
|
||||
p.w(table.concat(jsonCmds, ',\n'))
|
||||
p.w(']')
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -132,21 +128,4 @@ newaction {
|
||||
execute = execute
|
||||
}
|
||||
|
||||
newoption {
|
||||
trigger = 'export-compile-commands-config',
|
||||
value = nil,
|
||||
description = 'Configuration to use for compile_commands.json'
|
||||
}
|
||||
|
||||
newoption {
|
||||
trigger = 'export-compile-commands-platform',
|
||||
value = nil,
|
||||
description = 'Platform to use for compile_commands.json'
|
||||
}
|
||||
|
||||
newoption {
|
||||
trigger = 'export-compile-commands-output',
|
||||
description = 'Output file to use instead of compile_commands.json'
|
||||
}
|
||||
|
||||
return m
|
||||
|
||||
Reference in New Issue
Block a user