From 7e9a15966acf80ff50fdf5c52553dd56de164bb3 Mon Sep 17 00:00:00 2001 From: stijn Date: Mon, 30 Jan 2023 15:38:16 +0100 Subject: [PATCH] mpy-cross: Force forward slashes in paths. Code in tools/mpy-tool.py and py/frozenmod.c relies on the source file path encoded in a .mpy file to have forward slashes (e.g. by searching for '/__init__.py'). Enforce that when creating these files, thereby fixing import of .mpy files and frozen modules not working before because they could have backslashes when built with the windows port. --- mpy-cross/main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mpy-cross/main.c b/mpy-cross/main.c index 4a21d7584..13bb17b13 100644 --- a/mpy-cross/main.c +++ b/mpy-cross/main.c @@ -182,6 +182,15 @@ STATIC void pre_process_options(int argc, char **argv) { } } +STATIC char *backslash_to_forwardslash(char *path) { + for (char *p = path; p != NULL && *p != '\0'; ++p) { + if (*p == '\\') { + *p = '/'; + } + } + return path; +} + MP_NOINLINE int main_(int argc, char **argv) { mp_stack_set_limit(40000 * (sizeof(void *) / 4)); @@ -242,7 +251,7 @@ MP_NOINLINE int main_(int argc, char **argv) { exit(usage(argv)); } a += 1; - source_file = argv[a]; + source_file = backslash_to_forwardslash(argv[a]); } else if (strncmp(argv[a], "-msmall-int-bits=", sizeof("-msmall-int-bits=") - 1) == 0) { char *end; mp_dynamic_compiler.small_int_bits = @@ -308,7 +317,7 @@ MP_NOINLINE int main_(int argc, char **argv) { mp_printf(&mp_stderr_print, "multiple input files\n"); exit(1); } - input_file = argv[a]; + input_file = backslash_to_forwardslash(argv[a]); } }