Skip to content

Commit

Permalink
Fix CMake args for esp-idf lower than 4.4 (#1266)
Browse files Browse the repository at this point in the history
* Fix CMake args for esp-idf lower than 4.4

* Fix for arguments -B and -S

* Fix cmake compiler args inside package.json
  • Loading branch information
radurentea authored Aug 6, 2024
1 parent b84b268 commit dd2ed6d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,7 @@
},
"idf.cmakeCompilerArgs": {
"type": "array",
"default": [
"-G=Ninja",
"-DPYTHON_DEPS_CHECKED=1",
"-DESP_PLATFORM=1"
],
"default": [],
"description": "%param.cmakeCompilerArgs%",
"scope": "resource"
},
Expand Down
60 changes: 49 additions & 11 deletions src/build/buildTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<string>) || [
"-G=Ninja",
"-DPYTHON_DEPS_CHECKED=1",
"-DESP_PLATFORM=1",
];
) as Array<string>;

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 =
Expand Down

0 comments on commit dd2ed6d

Please sign in to comment.