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

Function copy_example_source

ci/compiler/source_manager.py:180–293  ·  view source on GitHub ↗

Copy example source to the build directory with sketch subdirectory structure. Args: project_root: FastLED project root directory build_dir: Build directory for the target example: Name of the example to copy, or path to example directory Returns: True if su

(project_root: Path, build_dir: Path, example: str)

Source from the content-addressed store, hash-verified

178
179
180def copy_example_source(project_root: Path, build_dir: Path, example: str) -> bool:
181 """Copy example source to the build directory with sketch subdirectory structure.
182
183 Args:
184 project_root: FastLED project root directory
185 build_dir: Build directory for the target
186 example: Name of the example to copy, or path to example directory
187
188 Returns:
189 True if successful, False if example not found
190 """
191 # Configure example source - handle both names and paths
192 example_path = Path(example)
193
194 if example_path.is_absolute():
195 # Absolute path - use as-is
196 if not example_path.exists():
197 return False
198 else:
199 # Relative path (including nested paths like Fx/FxWave2d) - resolve to examples directory
200 example_path = project_root / "examples" / example
201 if not example_path.exists():
202 return False
203
204 # Create src and sketch directories (PlatformIO requirement with sketch subdirectory)
205 src_dir = build_dir / "src"
206 sketch_dir = src_dir / "sketch"
207
208 # Create directories if they don't exist, but don't remove existing src_dir
209 src_dir.mkdir(exist_ok=True)
210
211 # Clean and recreate sketch subdirectory for fresh .ino files
212 if sketch_dir.exists():
213 shutil.rmtree(sketch_dir)
214 sketch_dir.mkdir(parents=True, exist_ok=True)
215
216 # Copy all files and subdirectories from example directory to sketch subdirectory
217 ino_files: list[str] = []
218 for file_path in example_path.iterdir():
219 if "fastled_js" in str(file_path):
220 # skip fastled_js output folder.
221 continue
222
223 if file_path.is_file():
224 # Skip .ino.cpp artifacts (preprocessed .ino files that would cause
225 # duplicate symbols when PlatformIO also compiles the .ino via main.cpp)
226 if file_path.name.endswith(".ino.cpp"):
227 continue
228 shutil.copy2(file_path, sketch_dir)
229 # Calculate relative paths for cleaner output
230 try:
231 rel_source = file_path.relative_to(Path.cwd())
232 rel_dest = sketch_dir.relative_to(Path.cwd())
233 print(f"Copied {rel_source} to {rel_dest}")
234 except ValueError:
235 # Fallback to absolute paths if relative calculation fails
236 print(f"Copied {file_path} to {sketch_dir}")
237 if file_path.suffix == ".ino":

Callers 3

_init_platformio_buildFunction · 0.90
_build_fbuild_syncMethod · 0.90
_build_internalMethod · 0.90

Calls 5

_scandir_syncFunction · 0.85
generate_main_cppFunction · 0.85
printFunction · 0.50
appendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected