1919 */
2020
2121import { MakeFile as MAKEFILE , TSConfigFile , PrerequisiteFile , FormatFile , RotationFile , Tool } from "mcmanifest" ;
22+ import { FILE } from "tool" ;
2223
2324var formatStrings = {
2425 gray16 : "Gray16" ,
@@ -42,6 +43,11 @@ var formatValues = {
4243 x : 0 ,
4344} ;
4445
46+ function replaceBackSlashes ( value ) {
47+ value = value . replace ( / \\ / g, "/" ) ;
48+ return value ;
49+ }
50+
4551class MakeFile extends MAKEFILE {
4652 constructor ( path ) {
4753 super ( path )
@@ -269,10 +275,10 @@ class ZephyrMakeFile extends MAKEFILE {
269275 source = result . source ;
270276 sourceParts = tool . splitPath ( result . source ) ;
271277
278+ this . line ( `cmake_path(CONVERT "${ source } " TO_NATIVE_PATH_LIST the_source)` ) ;
272279 this . line ( "add_custom_command(" ) ;
273280 this . line ( " OUTPUT ${TMP_DIR}" , tool . slash , sourceParts . name , sourceParts . extension , ".xsi\n" ) ;
274- // this.line(" COMMAND xsid ", source, " -o ${TMP_DIR}", tool.slash, sourceParts.name, sourceParts.extension, ".xsi");
275- this . line ( " COMMAND xsid " , source , " -o ${TMP_DIR}" ) ;
281+ this . line ( " COMMAND xsid ${the_source} -o ${NATIVE_TMP_DIR}" ) ;
276282 this . line ( " DEPENDS " , source ) ;
277283 this . line ( " VERBATIM)" ) ;
278284 this . line ( ) ;
@@ -281,10 +287,10 @@ class ZephyrMakeFile extends MAKEFILE {
281287 source = result ;
282288 sourceParts = tool . splitPath ( source ) ;
283289
290+ this . line ( `cmake_path(CONVERT "${ source } " TO_NATIVE_PATH_LIST the_source)` ) ;
284291 this . line ( "add_custom_command(" ) ;
285292 this . line ( " OUTPUT ${TMP_DIR}" , tool . slash , sourceParts . name , sourceParts . extension , ".xsi" ) ;
286- // this.line(" COMMAND xsid ", source, " -o ${TMP_DIR}", tool.slash, sourceParts.name, sourceParts.extension, ".xsi");
287- this . line ( " COMMAND xsid " , source , " -o ${TMP_DIR}" ) ;
293+ this . line ( " COMMAND xsid ${the_source} -o ${NATIVE_TMP_DIR}" ) ;
288294 this . line ( " DEPENDS " , source ) ;
289295 this . line ( " VERBATIM)" ) ;
290296 this . line ( ) ;
@@ -1240,13 +1246,22 @@ export default class extends Tool {
12401246 else
12411247 temp = "0483:374b" ; // STMicroelectronics dev boards
12421248 }
1249+ else if ( this . currentPlatform === "win" )
1250+ temp = "COM3" ;
12431251 else
12441252 temp = "/dev/ttyACM0" ;
12451253 this . setenv ( "UPLOAD_PORT" , temp ) ;
12461254 trace ( `$UPLOAD_PORT not set. Using "${ temp } ".\n` ) ;
12471255 }
12481256 this . environment . UPLOAD_PORT = temp ;
12491257
1258+ temp = this . environment . DEBUGGER_PORT ?? this . getenv ( "DEBUGGER_PORT" ) ;
1259+ if ( ! temp )
1260+ temp = this . environment . UPLOAD_PORT ;
1261+ this . environment . DEBUGGER_PORT = temp ;
1262+ this . setenv ( "DEBUGGER_PORT" , temp ) ;
1263+ trace ( `$DEBUGGER_PORT set to "${ temp } ".\n` ) ;
1264+
12501265 temp = this . environment . DEBUGGER_SPEED ?? this . getenv ( "DEBUGGER_SPEED" ) ;
12511266 if ( ! temp )
12521267 temp = "115200" ;
@@ -1362,7 +1377,7 @@ export default class extends Tool {
13621377 if ( this . platform == "zephyr" ) {
13631378 this . jsFiles . push ( { source : this . tmpPath + this . slash + "mc.devicetree.js" , target : folder + this . slash + "devicetree.xsb" } ) ;
13641379 if ( this . preloads . length )
1365- this . preloads . push ( "mc" + this . slash + " devicetree.xsb" ) ;
1380+ this . preloads . push ( `mc ${ this . slash } devicetree.xsb` ) ;
13661381 }
13671382
13681383 file = new ConfigFile ( source , this ) ;
@@ -1404,6 +1419,8 @@ export default class extends Tool {
14041419 file = new esp32NMakeFile ( path ) ;
14051420 else if ( this . platform == "nrf52" )
14061421 file = new nrf52NMakeFile ( path ) ;
1422+ else if ( this . platform == "zephyr" )
1423+ file = new ZephyrMakeFile ( path ) ;
14071424 else
14081425 file = new NMakeFile ( path ) ;
14091426 }
@@ -1419,6 +1436,28 @@ export default class extends Tool {
14191436 }
14201437 file . generate ( this ) ;
14211438
1439+ if ( this . platform == "zephyr" ) {
1440+ let infile = this . readFileString ( path ) ;
1441+ if ( this . windows )
1442+ infile = replaceBackSlashes ( infile ) ;
1443+ const outfile = new FILE ( path , "w" ) ;
1444+ outfile . line ( `##### Generated file: ${ ( new Date ( Date . now ( ) ) . toString ( ) ) } ` ) ;
1445+ for ( var result of this . preloads ) {
1446+ outfile . write ( "list(APPEND preloadsNATIVE -p " ) ;
1447+ outfile . write ( result . replaceAll ( '#' , this . escapedHash ) . replaceAll ( '\\' , "\\\\" ) ) ;
1448+ outfile . line ( ")" ) ;
1449+ }
1450+ outfile . line ( `set(NATIVE_RESOURCES_DIR ${ this . resourcesPath . replaceAll ( '\\' , "\\\\" ) } )` ) ;
1451+ outfile . line ( `set(NATIVE_MODDABLE_DIR ${ this . moddablePath . replaceAll ( '\\' , "\\\\" ) } )` ) ;
1452+ outfile . line ( `set(NATIVE_MODULES_DIR ${ this . modulesPath . replaceAll ( '\\' , "\\\\" ) } )` ) ;
1453+ outfile . line ( `set(NATIVE_TMP_DIR ${ this . tmpPath . replaceAll ( '\\' , "\\\\" ) } )` ) ;
1454+ outfile . line ( "#####" ) ;
1455+ outfile . line ( ) ;
1456+
1457+ outfile . write ( infile ) ;
1458+ outfile . close ( ) ;
1459+ }
1460+
14221461 if ( this . tsFiles . length ) {
14231462 file = new TSConfigFile ( this . modulesPath + this . slash + "tsconfig.json" ) ;
14241463 file . generate ( this , true , false ) ;
@@ -1439,9 +1478,13 @@ export default class extends Tool {
14391478 overlay += "\"" ;
14401479 }
14411480 let command = `cd ${ this . moddablePath } && ` ;
1442- path = `${ this . moddablePath } /build/devices/zephyr/app` ;
1443- if ( this . buildTarget == "clean" )
1444- command += `rm -rf build/bin/zephyr/${ this . subplatform } build/tmp/zephyr/${ this . subplatform } ${ this . environment . ZEPHYR_BASE } ${ this . slash } build` ;
1481+ path = `${ this . moddablePath } ${ this . slash } build${ this . slash } devices${ this . slash } zephyr${ this . slash } app` ;
1482+ if ( this . buildTarget == "clean" ) {
1483+ if ( this . windows )
1484+ command += `del /s/q/f build\\bin\\zephyr\\${ this . subplatform } \\*.* build\\tmp\\zephyr\\${ this . subplatform } \\*.* ${ this . environment . ZEPHYR_BASE } \\build\\*.*` ;
1485+ else
1486+ command += `rm -rf build/bin/zephyr/${ this . subplatform } build/tmp/zephyr/${ this . subplatform } ${ this . environment . ZEPHYR_BASE } ${ this . slash } build` ;
1487+ }
14451488 else if ( this . buildTarget == "deploy" )
14461489 command += `west flash -d ${ this . tmpPath } ${ this . slash } build` ;
14471490 else if ( this . buildTarget == "debug" )
@@ -1455,7 +1498,7 @@ export default class extends Tool {
14551498 if ( this . buildTarget == "build" )
14561499 secondary = `${ path } -d ${ this . tmpPath } ${ this . slash } build -- -DEXTRA_CONF_FILE=${ this . tmpPath } ${ this . slash } zephyr.conf -DMODDABLE_BUILD_DIR=${ this . tmpPath } ${ overlay } `
14571500 else if ( this . buildTarget == "all" || undefined === this . buildTarget ) /* all */
1458- secondary = `${ path } -d ${ this . tmpPath } ${ this . slash } build -- -DEXTRA_CONF_FILE=${ this . tmpPath } ${ this . slash } zephyr.conf -DMODDABLE_BUILD_DIR=${ this . tmpPath } ${ overlay } && west -z ${ this . environment . ZEPHYR_BASE } flash -d ${ this . tmpPath } ${ this . slash } build && serial2xsbug ${ this . environment . UPLOAD_PORT } ${ this . environment . DEBUGGER_SPEED } 8N1` ;
1501+ secondary = `${ path } -d ${ this . tmpPath } ${ this . slash } build -- -DEXTRA_CONF_FILE=${ this . tmpPath } ${ this . slash } zephyr.conf -DMODDABLE_BUILD_DIR=${ this . tmpPath } ${ overlay } && west -z ${ this . environment . ZEPHYR_BASE } flash -d ${ this . tmpPath } ${ this . slash } build && serial2xsbug ${ this . environment . DEBUGGER_PORT } ${ this . environment . DEBUGGER_SPEED } 8N1` ;
14591502 else
14601503 throw new Error ( "unknown target: " + this . buildTarget ) ;
14611504
@@ -1468,8 +1511,18 @@ export default class extends Tool {
14681511
14691512 command += ` ${ secondary } ` ;
14701513 }
1471- // trace(`*** command: ${command}\n`);
1472- cmd = [ "bash" , "-c" , command ] ;
1514+ if ( this . windows ) {
1515+ const buildCmdPath = this . tmpPath + "\\doBuild.bat" ;
1516+ const buildCmdFile = new FILE ( buildCmdPath , "w" ) ;
1517+ buildCmdFile . line ( `@echo on` ) ;
1518+ buildCmdFile . line ( 'tasklist /nh /fi "imagename eq xsbug.exe" | find /i "xsbug.exe" > nul || (start xsbug)' ) ;
1519+ buildCmdFile . line ( `bash -c "${ replaceBackSlashes ( command ) } "` ) ;
1520+ buildCmdFile . line ( `echo Build done` ) ;
1521+ buildCmdFile . close ( ) ;
1522+ cmd = [ "cmd" , "/C" , buildCmdPath ] ;
1523+ }
1524+ else
1525+ cmd = [ "bash" , "-c" , command ] ;
14731526 }
14741527 else {
14751528 if ( this . buildTarget ) {
0 commit comments