Skip to content

Commit

Permalink
fixup! speed up experiment for test build
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr committed Apr 26, 2020
1 parent 1a4e873 commit 1805d39
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions code/scripts/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
from shutil import copyfileobj
from espurna_utils.display import Color, clr, print_warning


def restore_source_tree(files):
os.remove("espurna/espurna.cpp")
cmd = ["git", "checkout", "-f", "--"]
cmd.extend(files)
subprocess.check_call(cmd)
Expand Down Expand Up @@ -59,17 +59,16 @@ def print_total_time():

def prepare_source_tree():
to_restore = []
result_path = "espurna/espurna.cpp"

with tempfile.TemporaryFile() as tmp:
tmp.write(b"#include \"espurna.h\"\n")
tmp.write(b'#include "espurna.h"\n')
for source in pathlib.Path("./espurna/").iterdir():
# emulate .ino concatenation to speed up compilation times
if source.suffix == ".cpp":
to_restore.append(str(source))
print("- copying {}".format(source))
with source.open(mode="rb") as source_file:
copyfileobj(source_file, tmp)
print(tmp.tell())

source.unlink()
# unlink main .ino file to avoid PIO converting it before the build
Expand All @@ -81,8 +80,11 @@ def prepare_source_tree():
continue

tmp.seek(0)
with open("espurna/espurna.cpp", "wb") as result:

print(clr(Color.BOLD, "> Creating {}".format(result_path)))
with open(result_path, "wb") as result:
copyfileobj(tmp, result)
atexit.register(try_remove, result_path)

atexit.register(restore_source_tree, to_restore)

Expand Down Expand Up @@ -139,7 +141,9 @@ def main(args):
raise SystemExit(
clr(
Color.YELLOW,
"{} already exists, please run this script in a git-worktree(1) or a separate directory".format(args.custom_h),
"{} already exists, please run this script in a git-worktree(1) or a separate directory".format(
args.custom_h
),
)
)

Expand Down Expand Up @@ -169,13 +173,16 @@ def main(args):
prepare_source_tree()
run_configurations(args, configurations)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-l", "--list", action="store_true", help="List selected configurations"
)
parser.add_argument(
"--custom-h", default="espurna/config/custom.h", help="Header that will be included in by the config/all.h"
"--custom-h",
default="espurna/config/custom.h",
help="Header that will be included in by the config/all.h",
)
parser.add_argument(
"-n",
Expand All @@ -196,9 +203,7 @@ def main(args):
help="(glob) default configuration headers",
)
parser.add_argument(
"--no-silent",
action="store_true",
help="Do not silence pio-run"
"--no-silent", action="store_true", help="Do not silence pio-run"
)

main(parser.parse_args())

0 comments on commit 1805d39

Please sign in to comment.