Skip to content

Commit 7e9a159

Browse files
stinosdpgeorge
authored andcommitted
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.
1 parent e145318 commit 7e9a159

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

mpy-cross/main.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ STATIC void pre_process_options(int argc, char **argv) {
182182
}
183183
}
184184

185+
STATIC char *backslash_to_forwardslash(char *path) {
186+
for (char *p = path; p != NULL && *p != '\0'; ++p) {
187+
if (*p == '\\') {
188+
*p = '/';
189+
}
190+
}
191+
return path;
192+
}
193+
185194
MP_NOINLINE int main_(int argc, char **argv) {
186195
mp_stack_set_limit(40000 * (sizeof(void *) / 4));
187196

@@ -242,7 +251,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
242251
exit(usage(argv));
243252
}
244253
a += 1;
245-
source_file = argv[a];
254+
source_file = backslash_to_forwardslash(argv[a]);
246255
} else if (strncmp(argv[a], "-msmall-int-bits=", sizeof("-msmall-int-bits=") - 1) == 0) {
247256
char *end;
248257
mp_dynamic_compiler.small_int_bits =
@@ -308,7 +317,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
308317
mp_printf(&mp_stderr_print, "multiple input files\n");
309318
exit(1);
310319
}
311-
input_file = argv[a];
320+
input_file = backslash_to_forwardslash(argv[a]);
312321
}
313322
}
314323

0 commit comments

Comments
 (0)