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.
This commit is contained in:
stijn 2023-01-30 15:38:16 +01:00 committed by Damien George
parent e145318a81
commit 7e9a15966a

View File

@ -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_NOINLINE int main_(int argc, char **argv) {
mp_stack_set_limit(40000 * (sizeof(void *) / 4)); mp_stack_set_limit(40000 * (sizeof(void *) / 4));
@ -242,7 +251,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
exit(usage(argv)); exit(usage(argv));
} }
a += 1; 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) { } else if (strncmp(argv[a], "-msmall-int-bits=", sizeof("-msmall-int-bits=") - 1) == 0) {
char *end; char *end;
mp_dynamic_compiler.small_int_bits = 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"); mp_printf(&mp_stderr_print, "multiple input files\n");
exit(1); exit(1);
} }
input_file = argv[a]; input_file = backslash_to_forwardslash(argv[a]);
} }
} }