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

[VSC-1573] ensure build directories exist and resolve relative paths #1417

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 22 additions & 10 deletions src/project-conf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

import * as path from "path";
import { ExtensionContext, Uri } from "vscode";
import { ESP } from "../config";
import { pathExists, readJson, writeJson, ensureDir } from "fs-extra";
Expand Down Expand Up @@ -61,10 +62,20 @@ export async function getProjectConfigurationElements(workspaceFolder: Uri) {
await Promise.all(
Object.keys(projectConfJson).map(async (elem) => {
const buildConfig = projectConfJson[elem].build;
const buildDirPath = buildConfig?.buildDirectoryPath
? Uri.joinPath(workspaceFolder, buildConfig.buildDirectoryPath).fsPath
: buildConfig?.buildDirectoryPath;
let buildDirPath: string;

const userBuildDir = buildConfig?.buildDirectoryPath;
if (userBuildDir) {
// Check if the path is absolute
if (path.isAbsolute(userBuildDir)) {
buildDirPath = userBuildDir;
} else {
// Resolve relative path against workspace
buildDirPath = Uri.joinPath(workspaceFolder, userBuildDir).fsPath;
}
}

// Ensure directory is created for the resolved path
if (buildDirPath) {
await ensureDir(buildDirPath);
}
Expand All @@ -74,13 +85,14 @@ export async function getProjectConfigurationElements(workspaceFolder: Uri) {
compileArgs: buildConfig?.compileArgs,
ninjaArgs: buildConfig?.ninjaArgs,
buildDirectoryPath: buildDirPath,
sdkconfigDefaults: buildConfig?.sdkconfigDefaults?.map(
(path) => Uri.joinPath(workspaceFolder, path).fsPath
),
sdkconfigFilePath: buildConfig?.sdkconfigFilePath
? Uri.joinPath(workspaceFolder, buildConfig.sdkconfigFilePath)
.fsPath
: buildConfig?.sdkconfigFilePath,
sdkconfigDefaults: (await pathExists(buildConfig?.sdkconfigDefaults))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to consider that sdkconfigDefaults is an array of files so this part of code would fail.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just noticed this was the thing that was giving me headaches. Thank you!

? buildConfig?.sdkconfigDefaults
: Uri.joinPath(workspaceFolder, buildConfig?.sdkconfigDefaults)
.fsPath,
sdkconfigFilePath: (await pathExists(buildConfig?.sdkconfigFilePath))
? buildConfig?.sdkconfigFilePath
: Uri.joinPath(workspaceFolder, buildConfig.sdkconfigFilePath)
.fsPath,
},
env: projectConfJson[elem].env,
flashBaudRate: projectConfJson[elem].flashBaudRate,
Expand Down
43 changes: 33 additions & 10 deletions src/statusBar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

import * as path from "path";
import {
env,
StatusBarAlignment,
Expand All @@ -31,6 +32,7 @@ import { ESP } from "../config";
import { CommandItem } from "../cmdTreeView/cmdTreeDataProvider";
import { CommandKeys, createCommandDictionary } from "../cmdTreeView/cmdStore";
import { getIdfTargetFromSdkconfig } from "../workspaceConfig";
import { pathExists } from "fs-extra";

export const statusBarItems: { [key: string]: StatusBarItem } = {};

Expand Down Expand Up @@ -61,6 +63,12 @@ export async function createCmdsStatusBarItems(workspaceFolder: Uri) {
let projectConf = ESP.ProjectConfiguration.store.get<string>(
ESP.ProjectConfiguration.SELECTED_CONFIG
);
let projectConfPath = path.join(
workspaceFolder.fsPath,
ESP.ProjectConfiguration.PROJECT_CONFIGURATION_FILENAME
);
let projectConfExists = await pathExists(projectConfPath);

let currentIdfVersion = await getCurrentIdfSetup(workspaceFolder, false);

statusBarItems["workspace"] = createStatusBarItem(
Expand Down Expand Up @@ -101,16 +109,31 @@ export async function createCmdsStatusBarItems(workspaceFolder: Uri) {
);
}

if (projectConf) {
statusBarItems["projectConf"] = createStatusBarItem(
`$(${
commandDictionary[CommandKeys.SelectProjectConfiguration].iconId
}) ${projectConf}`,
commandDictionary[CommandKeys.SelectProjectConfiguration].tooltip,
CommandKeys.SelectProjectConfiguration,
99,
commandDictionary[CommandKeys.SelectProjectConfiguration].checkboxState
);
if (projectConfExists) {
if (!projectConf) {
let statusBarItemName = "Invalid Path";
let statusBarItemTooltip =
"Invalid configuration path. Click to modify project configuration";
statusBarItems["projectConf"] = createStatusBarItem(
`$(${
commandDictionary[CommandKeys.SelectProjectConfiguration].iconId
}) ${statusBarItemName}`,
statusBarItemTooltip,
"espIdf.projectConfigurationEditor",
99,
commandDictionary[CommandKeys.SelectProjectConfiguration].checkboxState
);
} else {
statusBarItems["projectConf"] = createStatusBarItem(
`$(${
commandDictionary[CommandKeys.SelectProjectConfiguration].iconId
}) ${projectConf}`,
commandDictionary[CommandKeys.SelectProjectConfiguration].tooltip,
CommandKeys.SelectProjectConfiguration,
99,
commandDictionary[CommandKeys.SelectProjectConfiguration].checkboxState
);
}
}

statusBarItems["target"] = createStatusBarItem(
Expand Down
Loading