diff --git a/OutOfProcessExtractor.cs b/OutOfProcessExtractor.cs index 91f2432..3c15a80 100644 --- a/OutOfProcessExtractor.cs +++ b/OutOfProcessExtractor.cs @@ -1120,6 +1120,7 @@ public static List ExtractCompileCommandsFromSolution( string msbuildPath, string solutionPath, string configuration = "Debug", string platform = "x64", bool enableLogger = false, string? vcToolsInstallDir = null, string? vcTargetsPath = null, + string? clPath = null, IReadOnlyDictionary? msbuildProperties = null, IReadOnlyDictionary? msbuildEnv = null, MsBuildLauncher launcher = MsBuildLauncher.Auto, @@ -1138,6 +1139,7 @@ public static List ExtractCompileCommandsFromSolution( var extractor = new OutOfProcessExtractor( msbuildPath, project.Path, configuration, platform, enableLogger, solutionDir, vcToolsInstallDir, vcTargetsPath, + clPath, msbuildProperties: msbuildProperties, msbuildEnv: msbuildEnv, launcher: launcher, @@ -1158,9 +1160,9 @@ public static List ExtractCompileCommandsFromSolution( public static void WriteCompileCommandsJsonFromSolution( string msbuildPath, string solutionPath, string configuration = "Debug", string platform = "x64", bool enableLogger = false, string? outputPath = null, - string? vcToolsInstallDir = null, string? vcTargetsPath = null) + string? vcToolsInstallDir = null, string? vcTargetsPath = null, string? clPath = null) { - var commands = ExtractCompileCommandsFromSolution(msbuildPath, solutionPath, configuration, platform, enableLogger, vcToolsInstallDir, vcTargetsPath); + var commands = ExtractCompileCommandsFromSolution(msbuildPath, solutionPath, configuration, platform, enableLogger, vcToolsInstallDir, vcTargetsPath, clPath); outputPath ??= Path.Combine(Path.GetDirectoryName(Path.GetFullPath(solutionPath))!, "compile_commands.json"); var json = JsonSerializer.Serialize(commands, new JsonSerializerOptions diff --git a/Program.cs b/Program.cs index b7a3ebb..5f9567d 100644 --- a/Program.cs +++ b/Program.cs @@ -329,6 +329,7 @@ static List ExtractOutOfProcess(CommandLineOptions options) return OutOfProcessExtractor.ExtractCompileCommandsFromSolution( options.MsBuildPath!, options.Solution, options.Configuration, options.Platform, options.EnableLogger, options.VcToolsInstallDir, options.VcTargetsPath, + clPath: options.ClPath, emitDefaults: options.EmitDefaults, mergeDefaults: options.MergeDefaults); } else @@ -362,6 +363,7 @@ static List ExtractMultipleInputs(CommandLineOptions options) commands = OutOfProcessExtractor.ExtractCompileCommandsFromSolution( options.MsBuildPath!, sln, options.Configuration, options.Platform, options.EnableLogger, options.VcToolsInstallDir, options.VcTargetsPath, + clPath: options.ClPath, msbuildProperties: options.MsBuildProperties, msbuildEnv: options.MsBuildEnv, launcher: ParseLauncher(options.MsBuildLauncher), diff --git a/README.md b/README.md index 14b84d6..817e238 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,20 @@ msbuild-extractor-sample --solution myapp.sln --format rich -o compile_database. msbuild-extractor-sample --solution myapp.sln --msbuild-path "C:\VS\MSBuild\Current\Bin\MSBuild.exe" -c Debug -a x64 ``` +### Pin a specific toolchain (custom MSBuild, VC targets, and cl.exe) + +Useful when the build uses a non-Visual-Studio toolchain (e.g. a package-based +MSBuild/MSVC) and you want `compile_commands.json` to reference that exact compiler +instead of an auto-detected Visual Studio install. `--cl-path` is honored for both +`--project` and `--solution` inputs. + +```bash +msbuild-extractor-sample --solution myapp.sln -c Debug -a x64 \ + --msbuild-path "C:\path\to\MSBuild\Current\Bin\amd64\MSBuild.exe" \ + --vc-targets-path "C:\path\to\MSBuild\Extensions\Microsoft\VC\v170\" \ + --cl-path "C:\path\to\VisualCppTools\lib\native\bin\cl.exe" +``` + ## Features - **Zero-config extraction** - auto-detects Visual Studio via `vswhere.exe`, resolves `VCTargetsPath`, `VCToolsInstallDir`, and real `cl.exe` path automatically @@ -129,6 +143,7 @@ Options: --list-instances List all Visual Studio installations and exit --vc-targets-path VC targets directory (auto-detected) --vc-tools-install-dir VCToolsInstallDir property (auto-detected) + --cl-path cl.exe path (overrides the resolved compiler; honored for --project and --solution) --msbuild-path MSBuild.exe path (enables out-of-process mode) --use-dev-env Read Developer Command Prompt environment variables --c-cpp-properties Emit .vscode/c_cpp_properties.json alongside the output