Skip to content

Commit

Permalink
catch cmakelists txt error sdkconfig file access (#909)
Browse files Browse the repository at this point in the history
* catch cmakelists txt error sdkconfig file access

* fix c cpp properties test

* add platform fallback
  • Loading branch information
brianignacio5 authored Apr 4, 2023
1 parent 3233414 commit 368827b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
11 changes: 11 additions & 0 deletions src/PlatformInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ export class PlatformInformation {
}
}

public get fallbackPlatform(): string {
switch (this.platform) {
case "darwin":
return "macos";
case "win32":
return this.architecture === "x86" ? "win32" : "win64";
default:
return "linux-amd64";
}
}

public static GetUnknownArchitecture(): string {
return "Unknown";
}
Expand Down
18 changes: 17 additions & 1 deletion src/idfToolsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export class IdfToolsManager {
return (
platOverride.platforms.indexOf(
this.platformInfo.platformToUse
) !== -1 ||
platOverride.platforms.indexOf(
this.platformInfo.fallbackPlatform
) !== -1
);
}
Expand Down Expand Up @@ -140,6 +143,9 @@ export class IdfToolsManager {
(Object.getOwnPropertyNames(value).indexOf(
this.platformInfo.platformToUse
) > -1 ||
Object.getOwnPropertyNames(value).indexOf(
this.platformInfo.fallbackPlatform
) > -1 ||
Object.getOwnPropertyNames(value).indexOf("any") > -1)
);
});
Expand All @@ -151,7 +157,11 @@ export class IdfToolsManager {
const linkInfo =
Object.getOwnPropertyNames(versions[0]).indexOf("any") > -1
? (versions[0]["any"] as IFileInfo)
: (versions[0][this.platformInfo.platformToUse] as IFileInfo);
: Object.getOwnPropertyNames(versions[0]).indexOf(
this.platformInfo.platformToUse
) > -1
? (versions[0][this.platformInfo.platformToUse] as IFileInfo)
: (versions[0][this.platformInfo.fallbackPlatform] as IFileInfo);
return linkInfo;
}

Expand All @@ -171,6 +181,9 @@ export class IdfToolsManager {
(Object.getOwnPropertyNames(value).indexOf(
this.platformInfo.platformToUse
) > -1 ||
Object.getOwnPropertyNames(value).indexOf(
this.platformInfo.fallbackPlatform
) > -1 ||
Object.getOwnPropertyNames(value).indexOf("any") > -1)
);
});
Expand Down Expand Up @@ -314,6 +327,9 @@ export class IdfToolsManager {
return (
Object.getOwnPropertyNames(version).indexOf(
this.platformInfo.platformToUse
) > -1 ||
Object.getOwnPropertyNames(version).indexOf(
this.platformInfo.fallbackPlatform
) > -1
);
});
Expand Down
1 change: 1 addition & 0 deletions src/test/suite/idfToolsManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ suite("IDF Tools Manager Tests", async () => {
architecture: "x86_64",
platform: "darwin",
platformToUse: "macos",
fallbackPlatform: "macos",
};
const output = OutputChannel.init();
const idfToolsManager = new IdfToolsManager(
Expand Down
27 changes: 17 additions & 10 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,16 @@ export async function setCCppPropertiesJsonCompilerPath(

export function getToolchainToolName(idfTarget: string, tool: string = "gcc") {
switch (idfTarget) {
case "esp32c2":
case "esp32c3":
case "esp32c6":
case "esp32h2":
return `riscv32-esp-elf-${tool}`;
case "esp32":
case "esp32s2":
case "esp32s3":
return `xtensa-${idfTarget}-elf-${tool}`;
case "esp32c2":
case "esp32c3":
case "esp32c6":
case "esp32h2":
default:
return undefined;
return `riscv32-esp-elf-${tool}`;
}
}

Expand Down Expand Up @@ -321,10 +320,18 @@ export function getVariableFromCMakeLists(workspacePath: string, key: string) {
}

export function getSDKConfigFilePath(workspacePath: vscode.Uri) {
let sdkconfigFilePath = getVariableFromCMakeLists(
workspacePath.fsPath,
"SDKCONFIG"
);
let sdkconfigFilePath = "";
try {
sdkconfigFilePath = getVariableFromCMakeLists(
workspacePath.fsPath,
"SDKCONFIG"
);
} catch (error) {
const errMsg = error.message
? error.message
: `CMakeLists.txt file doesn't exists or can't be read`;
Logger.info(errMsg, error);
}
if (
sdkconfigFilePath &&
sdkconfigFilePath.indexOf("${CMAKE_BINARY_DIR}") !== -1
Expand Down
2 changes: 0 additions & 2 deletions templates/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{
"name": "ESP-IDF",
"compilerPath": "${default}",
"cStandard": "c11",
"cppStandard": "c++17",
"includePath": [
"${config:idf.espIdfPath}/components/**",
"${config:idf.espIdfPathWin}/components/**",
Expand Down
2 changes: 0 additions & 2 deletions testFiles/testWorkspace/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{
"name": "ESP-IDF",
"compilerPath": "${default}",
"cStandard": "c11",
"cppStandard": "c++17",
"includePath": [
"${config:idf.espIdfPath}/components/**",
"${config:idf.espIdfPathWin}/components/**",
Expand Down

0 comments on commit 368827b

Please sign in to comment.