Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add build sdkconfig support #870

Merged
merged 3 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add build sdkconfig support
  • Loading branch information
brianignacio5 committed Jan 9, 2023
commit 0c9ac560a24281dd3ba5d63e066fdcd686b3700f
14 changes: 7 additions & 7 deletions src/coverage/configureProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@ import { getDocsLocaleLang, getDocsVersion } from "../espIdf/documentation/getDo
export async function configureProjectWithGcov(workspacePath: Uri) {
const appTraceDestTrax = getConfigValueFromSDKConfig(
"CONFIG_APPTRACE_DEST_TRAX",
workspacePath.fsPath
workspacePath
);
const appTraceEnable = getConfigValueFromSDKConfig(
"CONFIG_APPTRACE_ENABLE",
workspacePath.fsPath
workspacePath
);
const appTraceLockEnable = getConfigValueFromSDKConfig(
"CONFIG_APPTRACE_LOCK_ENABLE",
workspacePath.fsPath
workspacePath
);
const onPanicHostFlushTmo = getConfigValueFromSDKConfig(
"CONFIG_APPTRACE_ONPANIC_HOST_FLUSH_TMO",
workspacePath.fsPath
workspacePath
);
const postmortemFlushThresh = getConfigValueFromSDKConfig(
"CONFIG_APPTRACE_POSTMORTEM_FLUSH_THRESH",
workspacePath.fsPath
workspacePath
);
const appTracePendingDataSizeMax = getConfigValueFromSDKConfig(
"CONFIG_APPTRACE_PENDING_DATA_SIZE_MAX",
workspacePath.fsPath
workspacePath
);
const appTraceGcovEnable = getConfigValueFromSDKConfig(
"CONFIG_APPTRACE_GCOV_ENABLE",
workspacePath.fsPath
workspacePath
);

const isGcovEnabled =
Expand Down
3 changes: 2 additions & 1 deletion src/espIdf/menuconfig/confServerProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { OutputChannel } from "../../logger/outputChannel";
import {
appendIdfAndToolsToPath,
delConfigFile,
getSDKConfigFilePath,
isStringNotEmpty,
} from "../../utils";
import { KconfigMenuLoader } from "./kconfigMenuLoader";
Expand Down Expand Up @@ -260,7 +261,7 @@ export class ConfserverProcess {
idfConf.readParameter("idf.espIdfPath", workspaceFolder).toString() ||
process.env.IDF_PATH;
const pythonBinPath = idfConf.readParameter("idf.pythonBinPath", workspaceFolder) as string;
this.configFile = path.join(workspaceFolder.fsPath, "sdkconfig");
this.configFile = getSDKConfigFilePath(workspaceFolder);

process.env.IDF_TARGET = "esp32";
process.env.PYTHONUNBUFFERED = "0";
Expand Down
2 changes: 1 addition & 1 deletion src/espIdf/monitor/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function createNewIdfMonitor(
);
}
let sdkMonitorBaudRate: string = utils.getMonitorBaudRate(
workspaceFolder.fsPath
workspaceFolder
);
const pythonBinPath = readParameter(
"idf.pythonBinPath",
Expand Down
2 changes: 1 addition & 1 deletion src/espIdf/partition-table/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class PartitionTreeDataProvider
if (partitionTableOffsetOption.target.indexOf("sdkconfig") !== -1) {
partitionTableOffset = getConfigValueFromSDKConfig(
"CONFIG_PARTITION_TABLE_OFFSET",
workspace.fsPath
workspace
);
} else if (partitionTableOffsetOption.target.indexOf("custom") !== -1) {
partitionTableOffset = await window.showInputBox({
Expand Down
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2361,7 +2361,7 @@ export async function activate(context: vscode.ExtensionContext) {
);
}
let sdkMonitorBaudRate: string = utils.getMonitorBaudRate(
workspaceRoot.fsPath
workspaceRoot
);
const pythonBinPath = idfConf.readParameter(
"idf.pythonBinPath",
Expand Down Expand Up @@ -2552,7 +2552,7 @@ export async function activate(context: vscode.ExtensionContext) {
try {
const isCustomPartitionTableEnabled = utils.getConfigValueFromSDKConfig(
"CONFIG_PARTITION_TABLE_CUSTOM",
workspaceRoot.fsPath
workspaceRoot
);
if (isCustomPartitionTableEnabled !== "y") {
throw new Error(
Expand All @@ -2562,7 +2562,7 @@ export async function activate(context: vscode.ExtensionContext) {

let partitionTableFilePath = utils.getConfigValueFromSDKConfig(
"CONFIG_PARTITION_TABLE_CUSTOM_FILENAME",
workspaceRoot.fsPath
workspaceRoot
);
partitionTableFilePath = partitionTableFilePath.replace(/\"/g, "");
if (!utils.isStringNotEmpty(partitionTableFilePath)) {
Expand Down
45 changes: 40 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,47 @@ export async function copyFromSrcProject(
await copy(srcDirPath, destinationDir.fsPath);
}

export function getVariableFromCMakeLists(workspacePath: string, key: string) {
const cmakeListsFilePath = path.join(workspacePath, "CMakeLists.txt");
if (!canAccessFile(cmakeListsFilePath, fs.constants.R_OK)) {
throw new Error("CMakeLists.txt file doesn't exists or can't be read");
}
const cmakeListsContent = readFileSync(cmakeListsFilePath);
const regexExp = new RegExp(`(?:set|SET)\\(${key} (.*)\\)`);
const match = cmakeListsContent.match(regexExp);
return match ? match[1] : "";
}

export function getSDKConfigFilePath(workspacePath: vscode.Uri) {
let sdkconfigFilePath = getVariableFromCMakeLists(
workspacePath.fsPath,
"SDKCONFIG"
);
if (sdkconfigFilePath && sdkconfigFilePath.indexOf("${CMAKE_BINARY_DIR}") !== -1) {
const buildDirPath = idfConf.readParameter(
"idf.buildPath",
workspacePath
) as string;
sdkconfigFilePath = sdkconfigFilePath.replace("${CMAKE_BINARY_DIR}", buildDirPath).replace(/"/g, "");
}
if (!sdkconfigFilePath) {
const modifiedEnv = appendIdfAndToolsToPath(workspacePath);
sdkconfigFilePath = modifiedEnv.SDKCONFIG;
}
if (!sdkconfigFilePath) {
sdkconfigFilePath = path.join(workspacePath.fsPath, "sdkconfig");
}
if (!sdkconfigFilePath) {
sdkconfigFilePath = path.join(workspacePath.fsPath, "sdkconfig.defaults");
}
return sdkconfigFilePath;
}

export function getConfigValueFromSDKConfig(
key: string,
workspacePath: string,
sdkconfigFileName: string = "sdkconfig"
workspacePath: vscode.Uri
): string {
const sdkconfigFilePath = path.join(workspacePath, sdkconfigFileName);
const sdkconfigFilePath = getSDKConfigFilePath(workspacePath);
if (!canAccessFile(sdkconfigFilePath, fs.constants.R_OK)) {
throw new Error("sdkconfig file doesn't exists or can't be read");
}
Expand All @@ -323,7 +358,7 @@ export function getConfigValueFromSDKConfig(
return match ? match[1] : "";
}

export function getMonitorBaudRate(workspacePath: string) {
export function getMonitorBaudRate(workspacePath: vscode.Uri) {
let sdkMonitorBaudRate: string = "";
try {
sdkMonitorBaudRate = getConfigValueFromSDKConfig(
Expand All @@ -340,7 +375,7 @@ export function getMonitorBaudRate(workspacePath: string) {
}

export function delConfigFile(workspaceRoot: vscode.Uri) {
const sdkconfigFile = path.join(workspaceRoot.fsPath, "sdkconfig");
const sdkconfigFile = getSDKConfigFilePath(workspaceRoot);
fs.unlinkSync(sdkconfigFile);
}

Expand Down
46 changes: 16 additions & 30 deletions src/workspaceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { IdfTreeDataProvider } from "./idfComponentsDataProvider";
import { writeParameter } from "./idfConfiguration";
import { Logger } from "./logger/logger";
import * as utils from "./utils";
import { getSDKConfigFilePath } from "./utils";

export function initSelectedWorkspace(status: vscode.StatusBarItem) {
const workspaceRoot = vscode.workspace.workspaceFolders[0].uri;
Expand Down Expand Up @@ -80,37 +81,22 @@ export async function getIdfTargetFromSdkconfig(
workspacePath: vscode.Uri,
statusItem: vscode.StatusBarItem
) {
const doesSdkconfigExists = await pathExists(
path.join(workspacePath.fsPath, "sdkconfig")
);
const doesSdkconfigDefaultExists = await pathExists(
path.join(workspacePath.fsPath, "sdkconfig.defaults")
);
if (!doesSdkconfigExists && !doesSdkconfigDefaultExists) {
let sdkConfigPath = getSDKConfigFilePath(workspacePath);
const doesSdkconfigExists = await pathExists(sdkConfigPath);
if (!doesSdkconfigExists) {
return;
}
let sdkconfigToUse: string = doesSdkconfigExists
? "sdkconfig"
: doesSdkconfigDefaultExists
? "sdkconfig.defaults"
: "";
if (sdkconfigToUse) {
const idfTarget = utils
.getConfigValueFromSDKConfig(
"CONFIG_IDF_TARGET",
workspacePath.fsPath,
sdkconfigToUse
)
.replace(/\"/g, "");
if (!idfTarget) {
return;
}
await writeParameter(
"idf.adapterTargetName",
idfTarget,
vscode.ConfigurationTarget.WorkspaceFolder,
workspacePath
);
statusItem.text = "$(circuit-board) " + idfTarget;
const idfTarget = utils
.getConfigValueFromSDKConfig("CONFIG_IDF_TARGET", workspacePath)
.replace(/\"/g, "");
if (!idfTarget) {
return;
}
await writeParameter(
"idf.adapterTargetName",
idfTarget,
vscode.ConfigurationTarget.WorkspaceFolder,
workspacePath
);
statusItem.text = "$(circuit-board) " + idfTarget;
}