MCPcopy Create free account
hub / github.com/FastLED/FastLED / compile_for_board_and_example

Function compile_for_board_and_example

ci/compiler/compile_for_board.py:38–225  ·  view source on GitHub ↗

Compile the given example for the given board.

(
    board: Board,
    example: Path,
    build_dir: Optional[str],
    verbose_on_failure: bool,
    libs: Optional[list[str]],
)

Source from the content-addressed store, hash-verified

36
37
38def compile_for_board_and_example(
39 board: Board,
40 example: Path,
41 build_dir: Optional[str],
42 verbose_on_failure: bool,
43 libs: Optional[list[str]],
44) -> tuple[bool, str]:
45 """Compile the given example for the given board."""
46 global ERROR_HAPPENED # pylint: disable=global-statement
47 if board.board_name == "web":
48 locked_print(f"Skipping web target for example {example}")
49 return True, ""
50 board_name = board.board_name
51 use_pio_run = board.use_pio_run
52 real_board_name = board.get_real_board_name()
53 libs = libs or []
54 builddir = (
55 Path(build_dir) / board_name if build_dir else Path(".build") / board_name
56 )
57 builddir.mkdir(parents=True, exist_ok=True)
58 srcdir = builddir / "src"
59 # Remove the previous *.ino file if it exists, everything else is recycled
60 # to speed up the next build.
61 if srcdir.exists():
62 shutil.rmtree(srcdir, ignore_errors=False)
63 locked_print(f"*** Building example {example} for board {board_name} ***")
64 cwd: Optional[str] = None
65 shell: bool = False
66 # Copy all files from the example directory to the "src" directory
67 for src_file in example.rglob("*"):
68 if src_file.is_file():
69 if _fastled_js_is_parent_directory(src_file):
70 # Skip the fastled_js folder, it's not needed for the build.
71 continue
72 src_dir = src_file.parent
73 path = src_dir.relative_to(example)
74 dst_dir = srcdir / path
75 os.makedirs(dst_dir, exist_ok=True)
76 locked_print(f"Copying {src_file} to {dst_dir / src_file.name}")
77 os.makedirs(srcdir, exist_ok=True)
78 shutil.copy(src_file, dst_dir / src_file.name)
79 # libs = ["src", "ci"]
80 if use_pio_run:
81 # we have to copy a few folders of pio ci in order to get this to work.
82 for lib in libs:
83 project_libdir = Path(lib)
84 assert project_libdir.exists()
85 build_lib = builddir / "lib" / lib
86 shutil.rmtree(build_lib, ignore_errors=True)
87 shutil.copytree(project_libdir, build_lib)
88
89 cwd = str(builddir)
90 cmd_list = [
91 "pio",
92 "run",
93 ]
94 # in this case we need to manually copy the example to the src directory
95 # because platformio doesn't support building a single file.

Callers 1

compile_examplesFunction · 0.85

Calls 8

locked_printFunction · 0.90
libfastled_build_lockFunction · 0.90
get_real_board_nameMethod · 0.80
timeMethod · 0.80
copyMethod · 0.45
appendMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected