summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstijn <stijn@ignitron.net>2023-01-30 15:38:16 +0100
committerDamien George <damien@micropython.org>2023-02-01 13:10:00 +1100
commit7e9a15966acf80ff50fdf5c52553dd56de164bb3 (patch)
tree784c259e036c64a1fc87abb1d3a748fbde14bb3e
parente145318a814c65658aaad80a2f9792077638c0a6 (diff)
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.
-rw-r--r--mpy-cross/main.c13
1 files 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]);
}
}