From 8e49fa9f4911b3421438423d07c057b9389ce7d7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 27 Nov 2017 10:46:54 +0100 Subject: [PATCH] Add gir submodule and automatic build script --- .gitmodules | 3 +++ generator.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gir | 1 + 3 files changed, 64 insertions(+) create mode 100644 .gitmodules create mode 100755 generator.py create mode 160000 gir diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..d4e793287 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "gir"] + path = gir + url = https://github.com/gtk-rs/gir diff --git a/generator.py b/generator.py new file mode 100755 index 000000000..abef9f4f2 --- /dev/null +++ b/generator.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python + +from os import listdir +from os.path import isfile, join +from subprocess import call +import sys + +need_rebuild = False + +def update_workspace(): + with open('Cargo.toml', 'r') as f: + old_lines = f.readlines() + lines = old_lines[:] + with open('Cargo.toml', 'w') as f: + lines.insert(len(lines) - 1, '"gir",') + f.write(''.join(lines)) + success = True + try: + call(['bash', '-c', 'cd gir && cargo build --release']) + except: + success = False + with open('Cargo.toml', 'w') as f: + f.write(''.join(old_lines)) + return success + + +if not isfile('./gir/src'): + need_rebuild = True + print('=> Initializing gir submodule...') + call(['bash', '-c', 'git submodule update --init']) + print('<= Done!') + +question = 'Do you want to update gir submodule? [y/N]' +if sys.version_info[0] < 3: + line = raw_input(question) +else: + line = input(question) +line = line.strip() +if line.lower() == 'n' or len(line) == 0: + 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: + print('<= Failed...') + sys.exit(1) + +print('=> Regenerating 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)) + call(['./target/release/gir', '-c', entry]) + print('<== Done!') +print('<= Done!') +print("Don't forget to check if everything has been correctly generated!") diff --git a/gir b/gir new file mode 160000 index 000000000..011373584 --- /dev/null +++ b/gir @@ -0,0 +1 @@ +Subproject commit 01137358493a9e19382045c84a141273f7e29b46