Main entry point.
()
| 1155 | |
| 1156 | |
| 1157 | def main() -> int: |
| 1158 | """Main entry point.""" |
| 1159 | args = parse_args() |
| 1160 | |
| 1161 | build_dir = args.project_dir.resolve() |
| 1162 | |
| 1163 | # Verify platformio.ini exists |
| 1164 | if not (build_dir / "platformio.ini").exists(): |
| 1165 | print(f"❌ Error: platformio.ini not found in {build_dir}") |
| 1166 | print(" Make sure you're running this from a PlatformIO project directory") |
| 1167 | return 1 |
| 1168 | |
| 1169 | if args.environment is None: |
| 1170 | from ci.util.pio_package_daemon import get_default_environment |
| 1171 | |
| 1172 | default_environment = get_default_environment(str(build_dir)) |
| 1173 | if default_environment is None: |
| 1174 | print("Error: fbuild requires an environment.") |
| 1175 | print(" Set default_envs in platformio.ini or pass --env <environment>.") |
| 1176 | return 1 |
| 1177 | args.environment = default_environment |
| 1178 | |
| 1179 | # Handle sketch argument and set PLATFORMIO_SRC_DIR environment variable |
| 1180 | if args.sketch: |
| 1181 | try: |
| 1182 | resolved_sketch = resolve_sketch_path(args.sketch, build_dir) |
| 1183 | |
| 1184 | # Detect if user is trying to run AutoResearch sketch directly (only with --check-usage) |
| 1185 | sketch_name = Path(resolved_sketch).name |
| 1186 | if args.check_usage and sketch_name.lower() == "autoresearch": |
| 1187 | # Display red banner error |
| 1188 | print() |
| 1189 | print(f"{Fore.RED}{'=' * 60}") |
| 1190 | print(f"{Fore.RED}⚠️ ERROR: DO NOT USE 'bash debug AutoResearch'") |
| 1191 | print(f"{Fore.RED}{'=' * 60}") |
| 1192 | print( |
| 1193 | f"{Fore.RED}The AutoResearch sketch requires specific --expect and --fail-on" |
| 1194 | ) |
| 1195 | print( |
| 1196 | f"{Fore.RED}patterns to work correctly. Use the dedicated wrapper instead:" |
| 1197 | ) |
| 1198 | print() |
| 1199 | print(f"{Fore.YELLOW} bash autoresearch{Style.RESET_ALL}") |
| 1200 | print() |
| 1201 | print( |
| 1202 | f"{Fore.RED}This ensures proper pattern matching and prevents false positives." |
| 1203 | ) |
| 1204 | print(f"{Fore.RED}{'=' * 60}{Style.RESET_ALL}") |
| 1205 | print() |
| 1206 | return 1 |
| 1207 | |
| 1208 | # Use absolute path for PLATFORMIO_SRC_DIR (matches autoresearch.py behavior) |
| 1209 | absolute_sketch_path = str(build_dir / resolved_sketch) |
| 1210 | os.environ["PLATFORMIO_SRC_DIR"] = absolute_sketch_path |
| 1211 | print(f"📁 Sketch: {resolved_sketch}") |
| 1212 | except SystemExit: |
| 1213 | # resolve_sketch_path already printed error message |
| 1214 | return 1 |
no test coverage detected