mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-29 04:51:09 +00:00
Improve generator script
This commit is contained in:
parent
a7749b7933
commit
37dad014ec
1 changed files with 86 additions and 43 deletions
129
generator.py
129
generator.py
|
@ -1,58 +1,101 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from os.path import isfile, join
|
from os.path import isfile, isdir, join
|
||||||
from subprocess import call
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
need_rebuild = False
|
|
||||||
|
|
||||||
def update_workspace():
|
NOTHING_TO_BE_DONE = 0
|
||||||
try:
|
NEED_UPDATE = 1
|
||||||
call(['bash', '-c', 'cd gir && cargo build --release'])
|
FAILURE = 2
|
||||||
except:
|
|
||||||
|
|
||||||
|
def run_command(command, folder=None):
|
||||||
|
if folder is None:
|
||||||
|
folder = "."
|
||||||
|
child = subprocess.Popen(command, cwd=folder)
|
||||||
|
child.communicate()
|
||||||
|
if child.returncode != 0:
|
||||||
|
print("Command `{}` failed with return code `{}`...".format(command, child.returncode))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
if not isfile('./gir/src'):
|
def update_workspace():
|
||||||
need_rebuild = True
|
try:
|
||||||
|
return run_command(['cargo', 'build', '--release'], 'gir')
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def def_check_submodule(submodule_path):
|
||||||
|
if len(listdir(submodule_path)) != 0:
|
||||||
|
return NOTHING_TO_BE_DONE
|
||||||
print('=> Initializing gir submodule...')
|
print('=> Initializing gir submodule...')
|
||||||
call(['bash', '-c', 'git submodule update --init'])
|
if not run_command(['git', 'submodule', 'update', '--init']):
|
||||||
|
return FAILURE
|
||||||
print('<= Done!')
|
print('<= Done!')
|
||||||
|
|
||||||
question = 'Do you want to update gir submodule? [y/N] '
|
question = 'Do you want to update gir submodule? [y/N] '
|
||||||
if sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
line = raw_input(question)
|
line = raw_input(question)
|
||||||
else:
|
|
||||||
line = input(question)
|
|
||||||
line = line.strip()
|
|
||||||
if line.lower() == 'y':
|
|
||||||
need_rebuild = True
|
|
||||||
print('=> Updating gir submodule...')
|
|
||||||
call(['bash', '-c', 'cd gir && git reset --hard HEAD && git pull -f origin master'])
|
|
||||||
print('<= Done!')
|
|
||||||
|
|
||||||
if need_rebuild is True or not os.path.isfile('./gir/target/release/gir'):
|
|
||||||
print('=> Building gir...')
|
|
||||||
if update_workspace() is True:
|
|
||||||
print('<= Done!')
|
|
||||||
else:
|
else:
|
||||||
print('<= Failed...')
|
line = input(question)
|
||||||
sys.exit(1)
|
line = line.strip()
|
||||||
|
if line.lower() == 'y':
|
||||||
|
print('=> Updating gir submodule...')
|
||||||
|
if not run_command(['git', 'reset', '--hard', 'HEAD'], 'gir'):
|
||||||
|
return FAILURE
|
||||||
|
if not run_command(['git', 'pull', '-f', 'origin', 'master'], 'gir'):
|
||||||
|
return FAILURE
|
||||||
|
print('<= Done!')
|
||||||
|
return NEED_UPDATE
|
||||||
|
return NOTHING_TO_BE_DONE
|
||||||
|
|
||||||
print('=> Regenerating crates...')
|
|
||||||
for entry in [f for f in listdir('.') if isfile(join('.', f))]:
|
def build_gir_if_needed(updated_submodule):
|
||||||
if entry.startswith('Gir_Gst') and entry.endswith('.toml'):
|
if updated_submodule == FAILURE:
|
||||||
print('==> Regenerating "{}"...'.format(entry))
|
return False
|
||||||
try:
|
elif updated_submodule == NEED_UPDATE or not isfile('./gir/target/release/gir'):
|
||||||
call(['./gir/target/release/gir', '-c', entry])
|
print('=> Building gir...')
|
||||||
except Exception as err:
|
if update_workspace() is True:
|
||||||
print('The following error occurred: {}'.format(err))
|
print('<= Done!')
|
||||||
line = input('Do you want to continue? [y/N] ').strip().lower()
|
else:
|
||||||
if line != 'y':
|
print('<= Failed...')
|
||||||
sys.exit(1)
|
return False
|
||||||
print('<== Done!')
|
return True
|
||||||
call(['cargo', 'fmt'])
|
|
||||||
print('<= Done!')
|
|
||||||
print("Don't forget to check if everything has been correctly generated!")
|
def regen_crates():
|
||||||
|
for entry in [f for f in listdir('.') if isfile(join('.', f))]:
|
||||||
|
if entry.startswith('Gir_Gst') and entry.endswith('.toml'):
|
||||||
|
print('==> Regenerating "{}"...'.format(entry))
|
||||||
|
try:
|
||||||
|
run_command(['./gir/target/release/gir', '-c', entry])
|
||||||
|
except Exception as err:
|
||||||
|
print('The following error occurred: {}'.format(err))
|
||||||
|
line = input('Do you want to continue? [y/N] ').strip().lower()
|
||||||
|
if line != 'y':
|
||||||
|
sys.exit(1)
|
||||||
|
print('<== Done!')
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if def_check_submodule("gir-files") == FAILURE:
|
||||||
|
return 1
|
||||||
|
if not build_gir_if_needed(def_check_submodule("gir")):
|
||||||
|
return 1
|
||||||
|
|
||||||
|
print('=> Regenerating crates...')
|
||||||
|
if not regen_crates():
|
||||||
|
return 1
|
||||||
|
if not run_command(['cargo', 'fmt']):
|
||||||
|
return 1
|
||||||
|
print('<= Done!')
|
||||||
|
print("Don't forget to check if everything has been correctly generated!")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
|
|
Loading…
Reference in a new issue