@@ -4,6 +4,7 @@ import { commands, window, workspace } from "vscode";
44import { join } from "path" ;
55import Settings , { SettingsKey } from "../settings.mjs" ;
66import { cmakeToolsForcePicoKit } from "../utils/cmakeToolsUtil.mjs" ;
7+ import { rimraf } from "rimraf" ;
78
89export default class LaunchTargetPathCommand extends CommandWithResult < string > {
910 constructor ( ) {
@@ -63,6 +64,30 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
6364 }
6465
6566 const settings = Settings . getInstance ( ) ;
67+ const fsPathFolder = workspace . workspaceFolders [ 0 ] . uri . fsPath ;
68+
69+ const cmakeListsPath = join ( fsPathFolder , "CMakeLists.txt" ) ;
70+ const fileContent = readFileSync ( cmakeListsPath , "utf-8" ) ;
71+ if ( fileContent . includes ( "set(PICO_CXX_ENABLE_EXCEPTIONS 1)" ) ) {
72+ // TODO: figure out why this workaround is needed
73+ if (
74+ settings !== undefined &&
75+ settings . getBoolean ( SettingsKey . useCmakeTools )
76+ ) {
77+ try {
78+ // delete build dir if present
79+ const buildDir = join ( fsPathFolder , "build" ) ;
80+ await rimraf ( buildDir , { maxRetries : 2 } ) ;
81+ } catch {
82+ throw new Error (
83+ "Failed to clean build directory."
84+ ) ;
85+ }
86+ } else {
87+ await commands . executeCommand ( "raspberry-pi-pico.cleanCmake" ) ;
88+ }
89+ }
90+
6691 if (
6792 settings !== undefined &&
6893 settings . getBoolean ( SettingsKey . useCmakeTools )
@@ -79,10 +104,8 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
79104 }
80105 }
81106
82- const fsPathFolder = workspace . workspaceFolders [ 0 ] . uri . fsPath ;
83-
84107 const projectName = await this . readProjectNameFromCMakeLists (
85- join ( fsPathFolder , "CMakeLists.txt" )
108+ cmakeListsPath
86109 ) ;
87110
88111 if ( projectName === null ) {
0 commit comments