From dd2ed6d14dfd03c7504b0d4ef51220527f4da7aa Mon Sep 17 00:00:00 2001 From: Radu Date: Tue, 6 Aug 2024 12:45:55 +0300 Subject: [PATCH] Fix CMake args for esp-idf lower than 4.4 (#1266) * Fix CMake args for esp-idf lower than 4.4 * Fix for arguments -B and -S * Fix cmake compiler args inside package.json --- package.json | 6 +---- src/build/buildTask.ts | 60 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index a05c181f0..f9b4a14a2 100644 --- a/package.json +++ b/package.json @@ -575,11 +575,7 @@ }, "idf.cmakeCompilerArgs": { "type": "array", - "default": [ - "-G=Ninja", - "-DPYTHON_DEPS_CHECKED=1", - "-DESP_PLATFORM=1" - ], + "default": [], "description": "%param.cmakeCompilerArgs%", "scope": "resource" }, diff --git a/src/build/buildTask.ts b/src/build/buildTask.ts index d514d1f4c..46bb62d80 100644 --- a/src/build/buildTask.ts +++ b/src/build/buildTask.ts @@ -21,7 +21,12 @@ import { join } from "path"; import { Logger } from "../logger/logger"; import * as vscode from "vscode"; import * as idfConf from "../idfConfiguration"; -import { appendIdfAndToolsToPath, isBinInPath } from "../utils"; +import { + appendIdfAndToolsToPath, + isBinInPath, + getEspIdfFromCMake, + compareVersion, +} from "../utils"; import { TaskManager } from "../taskManager"; import { selectedDFUAdapterId } from "../flash/dfu"; @@ -121,22 +126,55 @@ export class BuildTask { : vscode.TaskRevealKind.Silent; if (!cmakeCacheExists) { - let compilerArgs = (idfConf.readParameter( + const espIdfVersion = await getEspIdfFromCMake(this.idfPathDir); + let defaultCompilerArgs; + const useEqualSign = compareVersion(espIdfVersion, "4.4") >= 0; + if (espIdfVersion === "x.x") { + Logger.warn( + "Could not determine ESP-IDF version. Using default compiler arguments for the latest known version." + ); + defaultCompilerArgs = [ + "-G=Ninja", + "-DPYTHON_DEPS_CHECKED=1", + "-DESP_PLATFORM=1", + ]; + } else if (useEqualSign) { + defaultCompilerArgs = [ + "-G=Ninja", + "-DPYTHON_DEPS_CHECKED=1", + "-DESP_PLATFORM=1", + ]; + } else { + defaultCompilerArgs = [ + "-G", + "Ninja", + "-DPYTHON_DEPS_CHECKED=1", + "-DESP_PLATFORM=1", + ]; + } + let compilerArgs = idfConf.readParameter( "idf.cmakeCompilerArgs", this.currentWorkspace - ) as Array) || [ - "-G=Ninja", - "-DPYTHON_DEPS_CHECKED=1", - "-DESP_PLATFORM=1", - ]; + ) as Array; + + if (!compilerArgs || compilerArgs.length === 0) { + compilerArgs = defaultCompilerArgs; + } let buildPathArgsIndex = compilerArgs.indexOf("-B"); if (buildPathArgsIndex !== -1) { - compilerArgs.splice(buildPathArgsIndex, 2); + compilerArgs.splice(buildPathArgsIndex, useEqualSign ? 1 : 2); + } + if (useEqualSign) { + compilerArgs.push(`-B=${this.buildDirPath}`); + } else { + compilerArgs.push("-B", this.buildDirPath); } - compilerArgs.push(`-B=${this.buildDirPath}`); - if (compilerArgs.indexOf("-S") === -1) { - compilerArgs.push(`-S=${this.currentWorkspace.fsPath}`); + if (useEqualSign) { + compilerArgs.push(`-S=${this.currentWorkspace.fsPath}`); + } else { + compilerArgs.push("-S", this.currentWorkspace.fsPath); + } } const sdkconfigDefaults =