From: paulober <44974737+paulober@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:58:51 +0000 (+0100) Subject: Improved home var usage in settings X-Git-Url: https://repo.jachan.dev/pico-vscode.git/commitdiff_plain/5fb9d73e766aa0890748217a10efb5828bf26f14 Improved home var usage in settings Signed-off-by: paulober <44974737+paulober@users.noreply.github.com> --- diff --git a/scripts/pico_project.py b/scripts/pico_project.py index 4395e8d..4cc05a1 100644 --- a/scripts/pico_project.py +++ b/scripts/pico_project.py @@ -1178,6 +1178,10 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger, #cPath = f"${{env:PICO_TOOLCHAIN_PATH_{envSuffix}}}" + os.path.sep + os.path.basename(str(compilerPath).replace('\\', '\\\\' )) cPath = compilerPath.as_posix() + # if this is a path in the .pico-sdk homedir tell the settings to use the homevar + user_home = os.path.expanduser("~").replace("\\\\", "/") + use_home_var = f"{user_home}/.pico-sdk" in ninjaPath + for p in projects : if p == 'vscode': launch = f'''{{ @@ -1281,8 +1285,8 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger, "cmake.generator": "Ninja", "cmake.cmakePath": "{cmakePath}", "raspberry-pi-pico.cmakeAutoConfigure": true, - "raspberry-pi-pico.cmakePath": "{cmakePath}", - "raspberry-pi-pico.ninjaPath": "{ninjaPath}" + "raspberry-pi-pico.cmakePath": "{cmakePath.replace(user_home, "${HOME}") if use_home_var else cmakePath}", + "raspberry-pi-pico.ninjaPath": "{ninjaPath.replace(user_home, "${HOME}") if use_home_var else ninjaPath}" }} ''' @@ -1303,7 +1307,7 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger, {{ "label": "Compile Project", "type": "shell", - "command": "{ninjaPath}", + "command": "{ninjaPath.replace(user_home, "${userHome}") if use_home_var else ninjaPath}", "args": ["-C", "${{workspaceFolder}}/build"], "group": "build", "presentation": {{ diff --git a/src/utils/download.mts b/src/utils/download.mts index e3e90c4..35a9321 100644 --- a/src/utils/download.mts +++ b/src/utils/download.mts @@ -168,8 +168,9 @@ export async function downloadAndInstallSDK( settings: Settings ): Promise { const gitExecutable = - settings.getString(SettingsKey.gitPath)?.replace(HOME_VAR, homedir()) || - "git"; + settings + .getString(SettingsKey.gitPath) + ?.replace(HOME_VAR, homedir().replaceAll("\\", "/")) || "git"; const requirementsCheck = await checkForInstallationRequirements( settings, @@ -213,7 +214,8 @@ export async function downloadAndInstallSDK( const python3Exe: string = settings .getString(SettingsKey.python3Path) - ?.replace(HOME_VAR, homedir()) || process.platform === "win32" + ?.replace(HOME_VAR, homedir().replaceAll("\\", "/")) || + process.platform === "win32" ? "python" : "python3"; const python3: string | null = await which(python3Exe, { nothrow: true }); @@ -794,7 +796,9 @@ export async function downloadGit(): Promise { if (existsSync(targetDirectory)) { Logger.log(`Git is already installed.`); - return `${settingsTargetDirectory}/git` + `/${GIT_MACOS_VERSION}/bin/git`; + return process.platform === "win32" + ? `${settingsTargetDirectory}/cmd/git.exe` + : `${settingsTargetDirectory}/bin/git`; } // Ensure the target directory exists @@ -844,10 +848,7 @@ export async function downloadGit(): Promise { .then(success => { unlinkSync(archiveFilePath); resolve( - success - ? `${settingsTargetDirectory}/git` + - `/${GIT_MACOS_VERSION}/bin/git` - : undefined + success ? `${settingsTargetDirectory}/bin/git` : undefined ); }) .catch(() => {