Skip to content

Commit cea8197

Browse files
committed
zephyr: windows build
1 parent 3f5c2de commit cea8197

File tree

4 files changed

+232
-116
lines changed

4 files changed

+232
-116
lines changed

build/devices/zephyr/config/CMakeLists.txt.suffix

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ if (stripsLen GREATER 0)
55
set(STRIPS -s ${mSTRIPS})
66
endif()
77

8+
foreach(the_module ${mMODULES})
9+
cmake_path(CONVERT ${the_module} TO_NATIVE_PATH_LIST temp)
10+
LIST(APPEND the_modules ${temp})
11+
endforeach()
12+
cmake_path(CONVERT ${MODULES_DIR} TO_NATIVE_PATH_LIST b_dir)
13+
cmake_path(CONVERT ${TMP_DIR} TO_NATIVE_PATH_LIST t_dir)
14+
815
add_custom_command (
916
OUTPUT ${TMP_DIR}/mc.xs.c ${TMP_DIR}/mc.xs.h
1017
DEPENDS ${mMODULES} ${mRESOURCES}
11-
COMMAND xsl -b ${MODULES_DIR} -o ${TMP_DIR} ${mPRELOADS} ${STRIPS} ${mCREATION} ${mMODULES}
18+
COMMAND xsl -b ${b_dir} -o ${t_dir} ${preloadsNATIVE} ${STRIPS} ${mCREATION} ${the_modules}
1219
VERBATIM
1320
)
1421

@@ -89,20 +96,22 @@ add_custom_command(
8996
# typescript files
9097
#
9198

99+
cmake_path(CONVERT "${MODULES_DIR}/tsconfig.json" TO_NATIVE_PATH_LIST ts_config_path)
92100
if (TYPESCRIPT_CONVERTED_FILES)
93101
add_custom_command(
94102
OUTPUT ${TYPESCRIPT_CONVERTED_FILES}
95-
COMMAND tsc -p ${MODULES_DIR}/tsconfig.json
103+
COMMAND tsc -p ${ts_config_path}
96104
DEPENDS ${MODULES_DIR}/tsconfig.json ${TMP_DIR}/mc.devicetree.d.ts ${TYPESCRIPT_SOURCE_FILES}
97105
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
98106
VERBATIM
99107
)
100108
endif()
101109

102110
if (JAVASCRIPT_SOURCE_FILES)
111+
cmake_path(CONVERT "${MODULES_DIR}/tsconfig-js.json" TO_NATIVE_PATH_LIST ts_config_path)
103112
add_custom_command(
104113
OUTPUT ${TYPECHECK_FILE}
105-
COMMAND tsc -p ${MODULES_DIR}/tsconfig-js.json
114+
COMMAND tsc -p ${ts_config_path}
106115
DEPENDS ${MODULES_DIR}/tsconfig-js.json ${TMP_DIR}/mc.devicetree.d.ts ${JAVASCRIPT_SOURCE_FILES}
107116
COMMAND ${CMAKE_COMMAND} -E touch ${TYPECHECK_FILE}
108117
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}

build/makefiles/win/tools.mak

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ MODULES = \
135135
$(MOD_DIR)\mcmanifest.xsb \
136136
$(MOD_DIR)\mcpack.xsb \
137137
$(MOD_DIR)\mcrez.xsb \
138+
$(MOD_DIR)\mcdevicetree.xsb \
138139
$(MOD_DIR)\nodered2mcu.xsb \
139140
$(MOD_DIR)\png2bmp.xsb \
140141
$(MOD_DIR)\resampler.xsb \
@@ -222,6 +223,7 @@ COMMANDS = \
222223
$(BIN_DIR)\mclocal.bat \
223224
$(BIN_DIR)\mcpack.bat \
224225
$(BIN_DIR)\mcrez.bat \
226+
$(BIN_DIR)\mcdevicetree.bat \
225227
$(BIN_DIR)\nodered2mcu.bat \
226228
$(BIN_DIR)\png2bmp.bat \
227229
$(BIN_DIR)\rle4encode.bat \
@@ -451,6 +453,9 @@ $(BIN_DIR)\mcpack.bat :
451453
$(BIN_DIR)\mcrez.bat :
452454
@echo # mcrez.bat
453455
echo @%~dp0\tools mcrez %%* 1> $(BIN_DIR)\mcrez.bat
456+
$(BIN_DIR)\mcdevicetree.bat :
457+
@echo # mcdevicetree.bat
458+
echo @%~dp0\tools mcdevicetree %%* 1> $(BIN_DIR)\mcdevicetree.bat
454459
$(BIN_DIR)\mcrun.bat :
455460
@echo # mcrun.bat
456461
echo @%~dp0\tools mcrun %%* 1> $(BIN_DIR)\mcrun.bat

tools/mcconfig.js

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
import { MakeFile as MAKEFILE, TSConfigFile, PrerequisiteFile, FormatFile, RotationFile, Tool } from "mcmanifest";
22+
import { FILE } from "tool";
2223

2324
var 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+
4551
class 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

Comments
 (0)