11import os
22import sys
3+ import subprocess
34import shutil
5+ import time
46from git import repo
57from git import TagReference
68from packaging import version
@@ -39,53 +41,62 @@ def tags_filter(tags: list) -> list:
3941 ret_tags .append (main )
4042 return ret_tags
4143
42- def build_repo (pkpy_repo :repo .Repo , tag : TagReference | BranchAsTag ) -> None :
44+ def build_repo (pkpy_repo :repo .Repo , tag : TagReference | BranchAsTag ) -> float :
4345 """Build the repo with specific tag/branch static, copy excutable into
4446 the corresponding folder
4547 """
4648 pkpy_repo .git .checkout ('-f' , tag .name )
4749 # build dir All_in_one/{tag}
4850 assert os .path .exists ('pocketpy' )
51+ if os .path .exists ('pocketpy/build' ):
52+ shutil .rmtree ('pocketpy/build' )
53+
4954 if not os .path .exists ('All_in_one' ):
5055 os .mkdir ('All_in_one' )
5156 if os .path .exists (f'All_in_one/{ tag .name } ' ):
5257 shutil .rmtree (f'All_in_one/{ tag .name } ' )
5358 os .mkdir (f'All_in_one/{ tag .name } ' )
5459 # build the current version of pkpy
55- os .chdir ('pocketpy' )
56- assert os .system ('python prebuild.py' ) == 0
60+ try :
61+ subprocess .run ('python prebuild.py' , cwd = 'pocketpy' , stderr = subprocess .PIPE )
62+ except subprocess .CalledProcessError as e :
63+ print (f'prebuild.py run failed with return code { e .returncode } : { e .stderr } ' )
5764
58- if os .path .exists ('build' ):
59- shutil .rmtree ('build' )
60- os .mkdir ('build' )
61-
62- os .chdir ('build' )
63- code = os .system ('cmake .. -DPK_ENABLE_OS=ON -DPK_ENABLE_THREADS=OFF -DPK_ENABLE_DETERMINISM=OFF -DPK_ENABLE_WATCHDOG=OFF -DPK_ENABLE_CUSTOM_SNAME=OFF -DPK_ENABLE_MIMALLOC=OFF -DPK_BUILD_MODULE_LZ4=OFF -DPK_BUILD_MODULE_LIBHV=OFF -DCMAKE_BUILD_TYPE=Release' )
64- assert code == 0
65- code = os .system (f'cmake --build . --config Release' )
66- assert code == 0
65+ start_time = time .perf_counter ()
66+ subprocess .run ('cmake -B build -S . -DPK_ENABLE_OS=ON -DPK_ENABLE_THREADS=OFF -DPK_ENABLE_DETERMINISM=OFF -DPK_ENABLE_WATCHDOG=OFF -DPK_ENABLE_CUSTOM_SNAME=OFF -DPK_ENABLE_MIMALLOC=OFF -DPK_BUILD_MODULE_LZ4=OFF -DPK_BUILD_MODULE_LIBHV=OFF -DCMAKE_BUILD_TYPE=Release' ,
67+ cwd = 'pocketpy' , check = True )
68+ subprocess .run (f'cmake --build build --config Release' , cwd = 'pocketpy' , check = True )
69+ elapsed_time = time .perf_counter () - start_time
6770
6871 if sys .platform == 'win32' :
69- shutil .copy (f'Release/main.exe' , f'../../ All_in_one/{ tag .name } /main.exe' )
70- dll_path = f'Release/pocketpy.dll'
72+ shutil .copy (f'pocketpy/build/ Release/main.exe' , f'All_in_one/{ tag .name } /main.exe' )
73+ dll_path = f'pocketpy/build/ Release/pocketpy.dll'
7174 if os .path .exists (dll_path ):
72- shutil .copy (dll_path , f'../../ All_in_one/{ tag .name } /pocketpy.dll' )
75+ shutil .copy (dll_path , f'All_in_one/{ tag .name } /pocketpy.dll' )
7376 elif sys .platform == 'darwin' :
74- shutil .copy ('main' , '../ All_in_one/{tag.name}/main' )
75- dll_path = 'libpocketpy .dylib'
77+ shutil .copy ('pocketpy/build/ main' , 'All_in_one/{tag.name}/main' )
78+ dll_path = 'pocketpy/build/ibpocketpy .dylib'
7679 if os .path .exists (dll_path ):
77- shutil .copy (dll_path , f'../ All_in_one/{ tag .name } /libpocketpy.dylib' )
80+ shutil .copy (dll_path , f'All_in_one/{ tag .name } /libpocketpy.dylib' )
7881 else :
79- shutil .copy ('main' , f'../ All_in_one/{ tag .name } /main' )
80- dll_path = 'libpocketpy.so'
82+ shutil .copy ('pocketpy/build/ main' , f'All_in_one/{ tag .name } /main' )
83+ dll_path = 'pocketpy/build/ libpocketpy.so'
8184 if os .path .exists (dll_path ):
82- shutil .copy (dll_path , f'../ All_in_one/{ tag .name } /libpocketpy.so' )
85+ shutil .copy (dll_path , f'All_in_one/{ tag .name } /libpocketpy.so' )
8386
84- os .chdir ('../..' )
85-
87+ return elapsed_time
8688
8789pkpy_repo = clone_pkpy_repo ()
8890
8991tag_list = tags_filter (pkpy_repo .tags )
90- for tag in reversed (tag_list ):
91- build_repo (pkpy_repo , tag )
92+
93+ # build_repo also has 'All_in_one' path check, if the code run for the first time, log will need the following code
94+ if not os .path .exists ('All_in_one' ):
95+ os .mkdir ('All_in_one' )
96+
97+ with open ('All_in_one/log.txt' , 'w' ) as fp :
98+ fp .write (f'Building pocketpy with shared compilation, v1.1.0 - latest release, including main branch version.\n ' )
99+ for tag in reversed (tag_list ):
100+ elapsed_time = build_repo (pkpy_repo , tag )
101+ fp .write (f'{ tag .name } :\t { elapsed_time :.2f} s\n ' )
102+ fp .flush ()
0 commit comments