@@ -535,6 +535,18 @@ def _generate_cmake_args(
535535
536536 return cmake_args
537537
538+ def _copy_src_and_header_files (self , src_dir : pathlib .Path , dst_dir : pathlib .Path ):
539+ """Copy content of src_dir from template project to dst_dir in separate
540+ source and header sub-directories.
541+ """
542+ for file in os .listdir (src_dir ):
543+ file = src_dir / file
544+ if file .is_file ():
545+ if file .suffix in [".cc" , ".c" ]:
546+ shutil .copy2 (file , dst_dir / "src" )
547+ elif file .suffix in [".h" ]:
548+ shutil .copy2 (file , dst_dir / "include" / "tvm" )
549+
538550 def generate_project (self , model_library_format_path , standalone_crt_dir , project_dir , options ):
539551 zephyr_board = options ["board" ]
540552 project_type = options ["project_type" ]
@@ -673,28 +685,16 @@ def generate_project(self, model_library_format_path, standalone_crt_dir, projec
673685 API_SERVER_DIR / "crt_config" / "crt_config.h" , crt_config_dir / "crt_config.h"
674686 )
675687
676- # Populate src and include
688+ # Populate ` src` and ` include`
677689 src_dir = project_dir / "src"
678690 src_dir .mkdir ()
679691 include_dir = project_dir / "include" / "tvm"
680692 include_dir .mkdir (parents = True )
681693 src_project_type_dir = API_SERVER_DIR / "src" / project_type
682- for file in os .listdir (src_project_type_dir ):
683- file = pathlib .Path (src_project_type_dir / file )
684- if file .is_file ():
685- if file .suffix in [".cc" , ".c" ]:
686- shutil .copy2 (file , src_dir )
687- elif file .suffix in [".h" ]:
688- shutil .copy2 (file , include_dir )
694+ self ._copy_src_and_header_files (src_project_type_dir , project_dir )
689695
690696 if self ._is_fvp (zephyr_board , use_fvp ):
691- for file in os .listdir (src_project_type_dir / "fvp" ):
692- file = pathlib .Path (src_project_type_dir / "fvp" / file )
693- if file .is_file ():
694- if file .suffix in [".cc" , ".c" ]:
695- shutil .copy2 (file , src_dir )
696- elif file .suffix in [".h" ]:
697- shutil .copy2 (file , include_dir )
697+ self ._copy_src_and_header_files (src_project_type_dir / "fvp" , project_dir )
698698
699699 if project_type == "mlperftiny" :
700700 shutil .copytree (src_project_type_dir / "api" , src_dir / "api" )
0 commit comments