Move project config to data/ and configure-clangd.ps1 to scripts/
This commit is contained in:
parent
be62950bcb
commit
eb5456e7c1
7 changed files with 22 additions and 11 deletions
59
scripts/configure-clangd.ps1
Normal file
59
scripts/configure-clangd.ps1
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$root = $repoRoot.Replace('\', '/')
|
||||
$project = Get-Content -LiteralPath "$repoRoot/data/decomp.json" -Raw | ConvertFrom-Json
|
||||
$compile = Get-Content -LiteralPath "$repoRoot/$($project.compileCommands)" -Raw | ConvertFrom-Json
|
||||
$workspace = Get-Content -LiteralPath "$repoRoot/.td/config.json" -Raw | ConvertFrom-Json
|
||||
$runner = $workspace.runners.PSObject.Properties[$project.toolchain].Value
|
||||
|
||||
if (-not $runner -or $runner.type -ne 'native' -or -not $runner.toolchainRoot) {
|
||||
throw "clangd configuration requires this workspace's native Windows toolchain."
|
||||
}
|
||||
|
||||
$toolchain = $runner.toolchainRoot.Replace('\', '/')
|
||||
$compiler = $compile.compiler.Replace('${TC}', $toolchain).Replace('${SRC}', $root)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $compiler -PathType Leaf)) {
|
||||
throw "Configured compiler not found: $compiler"
|
||||
}
|
||||
|
||||
$systemIncludes = @($compile.env.INCLUDE.Replace('${TC}', $toolchain).Replace('${SRC}', $root).Split(';') | Where-Object { $_ })
|
||||
|
||||
foreach ($include in $systemIncludes) {
|
||||
if (-not (Test-Path -LiteralPath $include -PathType Container)) {
|
||||
throw "Configured include directory not found: $include"
|
||||
}
|
||||
}
|
||||
|
||||
$commands = @(
|
||||
foreach ($unit in $compile.units.PSObject.Properties) {
|
||||
$file = "$root/$($unit.Name)"
|
||||
|
||||
if (-not (Test-Path -LiteralPath $file -PathType Leaf)) {
|
||||
throw "Configured source file not found: $file"
|
||||
}
|
||||
|
||||
$arguments = @($compiler)
|
||||
$arguments += @($compile.shapes[[int]$unit.Value] | ForEach-Object {
|
||||
$_.Replace('${TC}', $toolchain).Replace('${SRC}', $root)
|
||||
})
|
||||
$arguments += @($systemIncludes | ForEach-Object { "/imsvc$_" })
|
||||
$arguments += $file
|
||||
|
||||
[ordered]@{
|
||||
directory = $root
|
||||
file = $file
|
||||
arguments = $arguments
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
$outputDirectory = Join-Path $repoRoot 'build/editor-x86'
|
||||
[void](New-Item -ItemType Directory -Path $outputDirectory -Force)
|
||||
$output = Join-Path $outputDirectory 'compile_commands.json'
|
||||
$json = ConvertTo-Json -InputObject $commands -Depth 6
|
||||
[System.IO.File]::WriteAllText($output, $json + "`n", [System.Text.UTF8Encoding]::new($false))
|
||||
Write-Output "Generated $($commands.Count) clangd compilation commands: $output"
|
||||
Loading…
Add table
Add a link
Reference in a new issue