Skip to content

Commit 235549a

Browse files
committed
fix idf size task
1 parent 8a9f52d commit 235549a

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

src/espIdf/size/idfSizeTask.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
* Project: ESP-IDF VSCode Extension
33
* File Created: Wednesday, 3rd November 2021 4:56:23 pm
44
* Copyright 2021 Espressif Systems (Shanghai) CO LTD
5-
* 
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
9-
* 
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
* 
11+
*
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,18 +20,15 @@ import { ensureDir } from "fs-extra";
2020
import { join } from "path";
2121
import {
2222
TaskPanelKind,
23-
ProcessExecutionOptions,
2423
TaskPresentationOptions,
2524
TaskRevealKind,
2625
TaskScope,
2726
Uri,
2827
workspace,
29-
ProcessExecution,
3028
} from "vscode";
3129
import { NotificationMode, readParameter } from "../../idfConfiguration";
3230
import { TaskManager } from "../../taskManager";
33-
import { appendIdfAndToolsToPath } from "../../utils";
34-
import { getProjectName } from "../../workspaceConfig";
31+
import { appendIdfAndToolsToPath, readProjectCMakeLists } from "../../utils";
3532
import { getVirtualEnvPythonPath } from "../../pythonManager";
3633
import { OutputCapturingExecution } from "../../taskManager/customExecution";
3734

@@ -47,15 +44,15 @@ export class IdfSizeTask {
4744
this.buildDirPath = readParameter("idf.buildPath", workspaceUri) as string;
4845
}
4946

50-
private async mapFilePath() {
51-
const projectName = await getProjectName(this.buildDirPath);
47+
private mapFilePath() {
48+
const projectName = readProjectCMakeLists(this.currentWorkspace.fsPath);
5249
return join(this.buildDirPath, `${projectName}.map`);
5350
}
5451

5552
public async getSizeInfo() {
5653
await ensureDir(this.buildDirPath);
5754
const pythonCommand = await getVirtualEnvPythonPath(this.currentWorkspace);
58-
const mapFilePath = await this.mapFilePath();
55+
const mapFilePath = this.mapFilePath();
5956
const args = [this.idfSizePath, mapFilePath];
6057

6158
const modifiedEnv = await appendIdfAndToolsToPath(this.currentWorkspace);

src/test/project.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ suite("Project tests", () => {
117117
const newProjectName = readProjectCMakeLists(projectPath);
118118
assert.notEqual(currProjectName, undefined);
119119
assert.notEqual(newProjectName, undefined);
120-
assert.equal(currProjectName[0], `project(${prevName})`);
121-
assert.equal(newProjectName[0], `project(${newName})`);
120+
assert.equal(currProjectName, `${prevName}`);
121+
assert.equal(newProjectName, `${newName}`);
122122
});
123123

124124
test("get templates projects", async () => {

src/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export function spawn(
185185
sendToTelemetry: true,
186186
}
187187
): Promise<Buffer> {
188-
let buff = Buffer.alloc(0);
188+
let buff: Buffer = Buffer.alloc(0);
189189
const sendToOutputChannel = (data: any) => {
190190
buff = Buffer.concat([buff, data]);
191191
options.outputString += buff.toString();
@@ -803,9 +803,9 @@ export function readProjectCMakeLists(dirPath: string) {
803803
const cmakeListFile = path.join(dirPath, "CMakeLists.txt");
804804
if (fileExists(cmakeListFile)) {
805805
const content = fs.readFileSync(cmakeListFile, "utf-8");
806-
const projectMatches = content.match(/(project\(.*?\))/g);
807-
if (projectMatches && projectMatches.length > 0) {
808-
return projectMatches;
806+
const projectMatches = content.match(/project\(([^)\s]+)/i);
807+
if (projectMatches && projectMatches[1]) {
808+
return projectMatches[1];
809809
}
810810
}
811811
}

0 commit comments

Comments
 (0)