update helper scripts and more

This commit is contained in:
Dengke Tang
2023-02-27 15:37:22 -08:00
parent 908f6c4dba
commit 1500c855e9
6 changed files with 81 additions and 87 deletions
+27 -46
View File
@@ -5,55 +5,36 @@ import shutil
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
WORK_DIR = os.path.join(TOOLS_DIR, '..')
# Remove specified directories
DIRS_TO_REMOVE = [
'.deps',
'.libs',
'build',
'include',
'modules',
'vendor',
'autom4te.cache']
# Remove specified files
FILES_TO_REMOVE = [
'Makefile',
'Makefile.fragments',
'Makefile.global',
'Makefile.objects',
'config.guess',
'config.h',
'config.h.in',
'config.log',
'config.nice',
'config.status',
'config.sub',
'configure',
'configure.in',
'configure.ac',
'install-sh',
'libtool',
'ltmain.sh',
'missing',
'mkinstalldirs',
'run-tests.php',
'awscrt.la',
'composer.lock',
'ext/awscrt.stub.php',
'acinclude.m4',
'aclocal.m4',
'**/*.lo',
'**/*.o',
'**/*.la',
'**/*.a',
'*.tgz']
def remove_files(files):
for file in files:
if os.path.exists(file):
os.remove(file)
os.chdir(WORK_DIR)
for directory in DIRS_TO_REMOVE:
# Remove specified directories
dirs_to_remove = ['.deps', '.libs', 'build', 'include', 'modules', 'vendor']
for directory in dirs_to_remove:
shutil.rmtree(directory, ignore_errors=True)
for pattern in FILES_TO_REMOVE:
for filepath in glob.glob(pattern):
os.remove(filepath)
# Remove specified files
files_to_remove = ['Makefile', 'Makefile.fragments', 'Makefile.global', 'Makefile.objects',
'config.guess', 'config.h', 'config.log', 'config.nice', 'config.status',
'config.sub', 'configure', 'configure.in', 'configure.ac', 'install-sh',
'libtool', 'ltmain.sh', 'missing', 'mkinstalldirs', 'run-tests.php',
'awscrt.la', 'composer.lock', 'ext/awscrt.stub.php', 'acinclude.m4', 'aclocal.m4',
'autom4te.cache']
# Remove all .lo and .o files
files_to_remove += glob.glob(os.path.join(WORK_DIR, '**/*.lo'))
files_to_remove += glob.glob(os.path.join(WORK_DIR, '**/*.o'))
# Remove all .la and .a files
files_to_remove += glob.glob(os.path.join(WORK_DIR, '**/*.la'))
files_to_remove += glob.glob(os.path.join(WORK_DIR, '**/*.a'))
# Remove all .tgz files
files_to_remove += glob.glob(os.path.join(WORK_DIR, '*.tgz'))
remove_files(files_to_remove)
+16 -15
View File
@@ -84,25 +84,26 @@ def process_dir(dir_name, f):
return
f.write(f'<dir name="{dir_name}">\n')
os.chdir(dir_name)
for file_name in os.listdir():
if os.path.isfile(file_name):
process_file(file_name, f)
else:
process_dir(file_name, f)
# Special cases for compiler features placed in tests directories in and s2n
if dir_name == 's2n' and os.path.isdir('tests'):
f.write('<dir name="tests">')
f.write('<dir name="features">')
if dir_name == 'tests' and os.path.isdir('tests'):
f.write('<dir name="tests">\n')
f.write('<dir name="features">\n')
os.chdir('tests/features')
for a in os.listdir():
process_file(a, f)
for file_name in os.listdir():
process_file(file_name)
os.chdir('../..')
f.write('</dir>')
f.write('</dir>')
f.write('</dir>\n')
f.write('</dir>\n')
f.write('</dir>')
else:
os.chdir(dir_name)
for file_name in os.listdir():
if os.path.isfile(file_name):
process_file(file_name, f)
else:
process_dir(file_name, f)
f.write('</dir>\n')
os.chdir('..')
+12 -23
View File
@@ -1,8 +1,6 @@
import argparse
import os
import subprocess
import xml.dom.minidom
import sys
parser = argparse.ArgumentParser(description='PECL Package generator')
@@ -27,32 +25,23 @@ NOTES = args.notes
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
WORK_DIR = os.path.join(TOOLS_DIR, '..')
def run(args):
print(f"$ {subprocess.list2cmdline(args)}")
subprocess.check_call(args)
run(['python3', f'{TOOLS_DIR}/cleanup_build.py'])
subprocess.run(['python3', f'{TOOLS_DIR}/cleanup_build.py'], check=True)
os.chdir(WORK_DIR)
run(['git', 'submodule', 'update', '--init', '--recursive'])
subprocess.run(['git', 'submodule', 'update',
'--init', '--recursive'], check=True)
subprocess.run(['python3', f'{TOOLS_DIR}/prepare_pecl_package_xml.py', '--name', NAME, '--user', USER,
'--email', EMAIL, '--version', VERSION, '--notes', NOTES], check=True)
try:
run(['python3', f'{TOOLS_DIR}/prepare_pecl_package_xml.py', '--name', NAME, '--user', USER,
'--email', EMAIL, '--version', VERSION, '--notes', NOTES])
with open('package.xml', 'r') as f:
package_xml = f.read()
subprocess.run(['tidy', '-xml', '-m', '-i', 'package.xml'], check=True)
subprocess.run(['pear', 'package-validate'], check=True)
subprocess.run(['pear', 'package'], check=True)
except subprocess.CalledProcessError as e:
sys.exit(f'ERROR PROCESSING review package.xml: {e}')
with open('package.xml', 'r') as f:
package_xml = f.read()
doc = xml.dom.minidom.parse('package.xml')
doc.encoding = 'UTF-8'
xml_str = doc.toprettyxml(indent=' ', newl='')
with open('package.xml', 'w') as f:
f.write(xml_str)
run(['pear', 'package-validate'])
run(['pear', 'package'])
print(f'ERROR PROCESSING review package.xml: {e}')
exit(1)
print(f'Size of {PACKAGE}-{VERSION}.tgz: {os.path.getsize(f"{PACKAGE}-{VERSION}.tgz") / 1024 / 1024:.2f} MB')
+14
View File
@@ -12,6 +12,20 @@ set "script_dir=%~dp0"
set "work_dir=%script_dir%/.."
cd %work_dir%
set vendor_path=vendor
if not exist "%vendor_path%" (
REM Run command to get composer_dir
set "composer_dir="
for /f "usebackq delims=" %%i in (`where composer.phar`) do set "composer_dir=%%i"
REM Check if composer_dir was found
if "%composer_dir%"=="" (
echo No composer found.
exit /b 1
)
)
call %PHP_BINARY% -c php-win.ini %composer_dir% update
call %PHP_BINARY% -c php-win.ini vendor/bin/phpunit tests --debug
+9
View File
@@ -0,0 +1,9 @@
import os
# get the absolute path of the script file
script_path = os.path.abspath(__file__)
# get the directory of the script file
script_dir = os.path.dirname(script_path)
print("Directory of the script file:", script_dir)