Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
55491031
Commit
55491031
authored
May 14, 2017
by
Paul Sokolovsky
Browse files
tools/mpy_cross_all.py: Helper tool to run mpy-cross on the entire project.
parent
0c57979c
Changes
1
Hide whitespace changes
Inline
Side-by-side
tools/mpy_cross_all.py
0 → 100755
View file @
55491031
#!/usr/bin/env python3
import
argparse
import
os
import
os.path
argparser
=
argparse
.
ArgumentParser
(
description
=
"Compile all .py files to .mpy recursively"
)
argparser
.
add_argument
(
"-o"
,
"--out"
,
help
=
"output directory (default: input dir)"
)
argparser
.
add_argument
(
"--target"
,
help
=
"select MicroPython target config"
)
argparser
.
add_argument
(
"-mcache-lookup-bc"
,
action
=
"store_true"
,
help
=
"cache map lookups in the bytecode"
)
argparser
.
add_argument
(
"dir"
,
help
=
"input directory"
)
args
=
argparser
.
parse_args
()
TARGET_OPTS
=
{
"unix"
:
"-mcache-lookup-bc"
,
"baremetal"
:
""
,
}
args
.
dir
=
args
.
dir
.
rstrip
(
"/"
)
if
not
args
.
out
:
args
.
out
=
args
.
dir
path_prefix_len
=
len
(
args
.
dir
)
+
1
for
path
,
subdirs
,
files
in
os
.
walk
(
args
.
dir
):
for
f
in
files
:
if
f
.
endswith
(
".py"
):
fpath
=
path
+
"/"
+
f
#print(fpath)
out_fpath
=
args
.
out
+
"/"
+
fpath
[
path_prefix_len
:
-
3
]
+
".mpy"
out_dir
=
os
.
path
.
dirname
(
out_fpath
)
if
not
os
.
path
.
isdir
(
out_dir
):
os
.
makedirs
(
out_dir
)
cmd
=
"mpy-cross -v -v %s -s %s %s -o %s"
%
(
TARGET_OPTS
.
get
(
args
.
target
,
""
),
fpath
[
path_prefix_len
:],
fpath
,
out_fpath
)
#print(cmd)
res
=
os
.
system
(
cmd
)
assert
res
==
0
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment