def _check_platform_version(self, options): if not self._version: cli_command = self._get_arduino_cli_cmd(options) self._version = self._get_platform_version(cli_command) if self._version < MIN_ARDUINO_CLI_VERSION: message = (f"Arduino CLI version too old: found {self._version}, " f"need at least {str(MIN_ARDUINO_CLI_VERSION)}.") if options.get("warning_as_error" ) is not None and options["warning_as_error"]: raise server.ServerError(message=message) _LOG.warning(message)
def generate_project(self, model_library_format_path, standalone_crt_dir, project_dir, options): # Check Arduino version version = self._get_platform_version(options["arduino_cli_cmd"]) if version != ARDUINO_CLI_VERSION: message = f"Arduino CLI version found is not supported: found {version}, expected {ARDUINO_CLI_VERSION}." if options.get("warning_as_error" ) is not None and options["warning_as_error"]: raise server.ServerError(message=message) _LOG.warning(message) # Reference key directories with pathlib project_dir = pathlib.Path(project_dir) project_dir.mkdir() source_dir = project_dir / "src" source_dir.mkdir() # Copies files from the template folder to project_dir shutil.copy2(API_SERVER_DIR / "microtvm_api_server.py", project_dir) shutil.copy2(BOARDS, project_dir / BOARDS.name) self._copy_project_files(API_SERVER_DIR, project_dir, options["project_type"]) # Copy standalone_crt into src folder self._copy_standalone_crt(source_dir, standalone_crt_dir) self._remove_unused_components(source_dir, options["project_type"]) # Populate crt-config.h crt_config_dir = project_dir / "src" / "standalone_crt" / "crt_config" crt_config_dir.mkdir() shutil.copy2(API_SERVER_DIR / "crt_config" / "crt_config.h", crt_config_dir / "crt_config.h") # Unpack the MLF and copy the relevant files metadata = self._disassemble_mlf(model_library_format_path, source_dir) shutil.copy2(model_library_format_path, project_dir / MODEL_LIBRARY_FORMAT_RELPATH) # For AOT, template model.h with metadata to minimize space usage if options["project_type"] == "example_project": self._template_model_header(source_dir, metadata) self._change_cpp_file_extensions(source_dir) # Recursively change includes self._convert_includes(project_dir, source_dir)
def generate_project(self, model_library_format_path, standalone_crt_dir, project_dir, options): # Check Zephyr version version = self._get_platform_version(get_zephyr_base(options)) if version != ZEPHYR_VERSION: message = f"Zephyr version found is not supported: found {version}, expected {ZEPHYR_VERSION}." if options.get("warning_as_error" ) is not None and options["warning_as_error"]: raise server.ServerError(message=message) _LOG.warning(message) project_dir = pathlib.Path(project_dir) # Make project directory. project_dir.mkdir() # Copy ourselves to the generated project. TVM may perform further build steps on the generated project # by launching the copy. shutil.copy2(__file__, project_dir / os.path.basename(__file__)) # Copy boards.json file to generated project. shutil.copy2(BOARDS, project_dir / BOARDS.name) # Place Model Library Format tarball in the special location, which this script uses to decide # whether it's being invoked in a template or generated project. project_model_library_format_tar_path = project_dir / MODEL_LIBRARY_FORMAT_RELPATH shutil.copy2(model_library_format_path, project_model_library_format_tar_path) # Extract Model Library Format tarball.into <project_dir>/model. extract_path = os.path.splitext( project_model_library_format_tar_path)[0] with tarfile.TarFile(project_model_library_format_tar_path) as tf: os.makedirs(extract_path) tf.extractall(path=extract_path) if self._is_qemu(options): shutil.copytree(API_SERVER_DIR / "qemu-hack", project_dir / "qemu-hack") # Populate CRT. crt_path = project_dir / "crt" crt_path.mkdir() for item in self.CRT_COPY_ITEMS: src_path = os.path.join(standalone_crt_dir, item) dst_path = crt_path / item if os.path.isdir(src_path): shutil.copytree(src_path, dst_path) else: shutil.copy2(src_path, dst_path) # Populate Makefile. with open(API_SERVER_DIR / "CMakeLists.txt.template", "r") as cmake_template_f: with open(project_dir / "CMakeLists.txt", "w") as cmake_f: for line in cmake_template_f: if self.API_SERVER_CRT_LIBS_TOKEN in line: crt_libs = self.CRT_LIBS_BY_PROJECT_TYPE[ options["project_type"]] line = line.replace("<API_SERVER_CRT_LIBS>", crt_libs) cmake_f.write(line) if options.get("compile_definitions"): flags = options.get("compile_definitions") for item in flags: cmake_f.write( f"target_compile_definitions(app PUBLIC {item})\n") self._create_prj_conf(project_dir, options) # Populate crt-config.h crt_config_dir = project_dir / "crt_config" crt_config_dir.mkdir() shutil.copy2(API_SERVER_DIR / "crt_config" / "crt_config.h", crt_config_dir / "crt_config.h") # Populate src/ src_dir = project_dir / "src" shutil.copytree(API_SERVER_DIR / "src" / options["project_type"], src_dir) # Populate extra_files if options.get("extra_files_tar"): with tarfile.open(options["extra_files_tar"], mode="r:*") as tf: tf.extractall(project_dir)