diff options
author | Chun-wei Fan <fanchunwei@src.gnome.org> | 2015-07-24 13:12:52 +0800 |
---|---|---|
committer | Chun-wei Fan <fanchunwei@src.gnome.org> | 2015-07-24 13:12:52 +0800 |
commit | fcc389839ce3b652674c88b410f37f6e339ff589 (patch) | |
tree | 4806af3b6827f01f988579cce58e8cfffed6fa69 | |
parent | 4e4a414561fdf869dca8a8b554b2d45d876ef14c (diff) | |
download | gobject-introspection-fcc389839ce3b652674c88b410f37f6e339ff589.tar.gz |
MSVC Builds: Generate The Tools Scripts
Since commit 7e00146, the scripts in tools/ are being generated from
tools/g-ir-tool-template.in, so we need to deal with this to fix Visual
Studio Builds.
Add a simple script to generate the Python tools scripts by splitting up
the gen-cairo-gir.py script and rename gen-cairo-gir.py to
gen-win32-cairo-gir.py to make things clearer to people, and adjust the
corresponding files accordingly.
Make sure everything here use UNIX line endings, for consistency's sake.
-rw-r--r-- | build/Makefile.am | 10 | ||||
-rw-r--r-- | build/gen-win32-cairo-gir.py (renamed from build/gen-cairo-gir.py) | 101 | ||||
-rw-r--r-- | build/gen-win32-gi-r-tools.py | 51 | ||||
-rw-r--r-- | build/gi-introspection-msvc.mak | 2 | ||||
-rw-r--r-- | build/gi_msvc_build_utils.py | 20 |
5 files changed, 121 insertions, 63 deletions
diff --git a/build/Makefile.am b/build/Makefile.am index acf85c07..a84067f4 100644 --- a/build/Makefile.am +++ b/build/Makefile.am @@ -1,10 +1,12 @@ SUBDIRS = win32 EXTRA_DIST = \ - detectenv_msvc.mak \ - gen-cairo-gir.py \ - gi-setenv-msvc.mak \ - gi-tests-msvc.mak \ + detectenv_msvc.mak \ + gen-win32-cairo-gir.py \ + gen-win32-g-ir-tools.py \ gi-build-common-msvc.mak \ gi-introspection-msvc.mak \ + gi_msvc_build_utils.py \ + gi-setenv-msvc.mak \ + gi-tests-msvc.mak \ introspection-msvc.mak diff --git a/build/gen-cairo-gir.py b/build/gen-win32-cairo-gir.py index 2fb365e2..419e8d33 100644 --- a/build/gen-cairo-gir.py +++ b/build/gen-win32-cairo-gir.py @@ -1,58 +1,43 @@ -#!/usr/bin/python
-#
-# Expand the bundled cairo-1.0.gir.in files
-# for use in Visual C++ builds of G-I
-#
-# Author: Fan, Chun-wei
-# Date: January 20, 2014
-#
-# (Adapted from setup.py in
-# $(glib_src_root)/build/win32/setup.py written by Shixin Zeng)
-
-import os
-import sys
-import re
-import string
-import subprocess
-import optparse
-
-def process_in(src, dest, vars):
- RE_VARS = re.compile(r'%(\w+?)%')
- with open(src, 'r') as s:
- with open(dest, 'w') as d:
- for i in s:
- i = RE_VARS.sub(lambda x: str(vars[x.group(1)]), i)
- d.write(i)
-
-def parent_dir(path):
- if not os.path.isabs(path):
- path = os.path.abspath(path)
- if os.path.isfile(path):
- path = os.path.dirname(path)
- return os.path.split(path)[0]
-
-def setup_vars_cairo(src, dest, dllname):
- vars = {}
- vars['CAIRO_GIR_PACKAGE'] = 'cairo-gobject'
- vars['CAIRO_SHARED_LIBRARY'] = '%s' % dllname
- process_in (src, dest, vars)
-
-def main(argv):
- parser = optparse.OptionParser()
- parser.add_option('--dllname', dest='dllname', action='store', help='Full file name of the Cairo-GObject DLL for the Cairo Introspection File')
- opt, args = parser.parse_args(argv)
- if opt.dllname is None:
- print ('dllname must be specified. Please refer to %s -h for more information' % os.path.basename(__file__))
- sys.exit()
-
- # Get the srcroot and the path where the bundled .gir files reside in the package
- srcroot = parent_dir(__file__)
- preset_gir_path = os.path.join(srcroot, 'gir')
-
- # Set up variables in cairo-1.0.gir.in to produce cairo-1.0.gir
- setup_vars_cairo(os.path.join(preset_gir_path, 'cairo-1.0.gir.in'),
- 'cairo-1.0.gir',
- opt.dllname)
-
-if __name__ == '__main__':
- sys.exit(main(sys.argv))
+#!/usr/bin/python +# +# Expand the bundled cairo-1.0.gir.in files +# for use in Visual C++ builds of G-I +# +# Author: Fan, Chun-wei +# Date: January 20, 2014 +# +# (Adapted from setup.py in +# $(glib_src_root)/build/win32/setup.py written by Shixin Zeng) + +import os +import sys +import optparse + +from gi_msvc_build_utils import process_in +from gi_msvc_build_utils import parent_dir + +def setup_vars_cairo(src, dest, dllname): + vars = {} + vars['CAIRO_GIR_PACKAGE'] = 'cairo-gobject' + vars['CAIRO_SHARED_LIBRARY'] = '%s' % dllname + process_in (src, dest, vars, 1) + +def main(argv): + parser = optparse.OptionParser() + parser.add_option('--dllname', dest='dllname', action='store', help='Full file name of the Cairo-GObject DLL for the Cairo Introspection File') + opt, args = parser.parse_args(argv) + if opt.dllname is None: + print ('dllname must be specified. Please refer to %s -h for more information' % os.path.basename(__file__)) + sys.exit() + + # Get the srcroot and the path where the bundled .gir files reside in the package + srcroot = parent_dir(__file__) + preset_gir_path = os.path.join(srcroot, 'gir') + + # Set up variables in cairo-1.0.gir.in to produce cairo-1.0.gir + setup_vars_cairo(os.path.join(preset_gir_path, 'cairo-1.0.gir.in'), + 'cairo-1.0.gir', + opt.dllname) + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/build/gen-win32-gi-r-tools.py b/build/gen-win32-gi-r-tools.py new file mode 100644 index 00000000..c598641b --- /dev/null +++ b/build/gen-win32-gi-r-tools.py @@ -0,0 +1,51 @@ +#!/usr/bin/python +# +# Expand the bundled cairo-1.0.gir.in files +# for use in Visual C++ builds of G-I +# +# Author: Fan, Chun-wei +# Date: January 20, 2014 +# +# (Adapted from setup.py in +# $(glib_src_root)/build/win32/setup.py written by Shixin Zeng) + +import os +import sys +import optparse + +from gi_msvc_build_utils import process_in +from gi_msvc_build_utils import parent_dir + +def setup_vars_tools(module, func, srcfile, outfile): + vars = {} + + # Well, we are using the "relocatable" feature on Windows... + blah = 'this\\\\is\\\\ignored\\\\on\\\\windows' + vars['datarootdir'] = blah + vars['libdir'] = blah + + # This doesn't really matter for cmd.exe usage, but + # let's just set this like this here, in case one + # wants to use MinGW with the scripts generated here + vars['PYTHON'] = 'python' + + # The parts that really matter. + vars['TOOL_MODULE'] = module + vars['TOOL_FUNCTION'] = func + process_in(srcfile, outfile, vars, 2) + +def main(argv): + modules = ['scannermain','annotationmain','docmain'] + funcs = ['scanner_main','annotation_main','doc_main'] + tools = ['g-ir-scanner','g-ir-annotation-tool','g-ir-doc-tool'] + + srcroot = parent_dir(__file__) + preset_tools_path = os.path.join(srcroot, 'tools') + src = os.path.join(preset_tools_path, 'g-ir-tool-template.in') + + for i in range(3): + dest = os.path.join(preset_tools_path, tools[i]) + setup_vars_tools(modules[i], funcs[i], src, dest) + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/build/gi-introspection-msvc.mak b/build/gi-introspection-msvc.mak index 2a7a5e3a..24257b35 100644 --- a/build/gi-introspection-msvc.mak +++ b/build/gi-introspection-msvc.mak @@ -135,7 +135,7 @@ GIRepository-$(GLIB_APIVERSION).gir: gi_list GObject-$(GLIB_APIVERSION).gir # Bundled cairo-1.0.gir.in processing cairo-1.0.gir: ..\gir\cairo-1.0.gir.in @-echo Generating $@ from $*.gir.in... - @-$(PYTHON2) gen-cairo-gir.py --dllname=$(CAIROGOBJECT_DLLNAME) + @-$(PYTHON2) gen-win32-cairo-gir.py --dllname=$(CAIROGOBJECT_DLLNAME) # Copy the .gir's bundled with G-I to this folder $(bundled_girs): ..\gir\win32-1.0.gir ..\gir\fontconfig-2.0.gir ..\gir\freetype2-2.0.gir ..\gir\GL-1.0.gir ..\gir\libxml2-2.0.gir diff --git a/build/gi_msvc_build_utils.py b/build/gi_msvc_build_utils.py new file mode 100644 index 00000000..619f0c56 --- /dev/null +++ b/build/gi_msvc_build_utils.py @@ -0,0 +1,20 @@ +import os +import re + +def process_in(src, dest, vars, mode): + if mode == 1: + RE_VARS = re.compile(r'%(\w+?)%') + if mode == 2: + RE_VARS = re.compile(r'@(\w+?)@') + with open(src, 'r') as s: + with open(dest, 'w') as d: + for i in s: + i = RE_VARS.sub(lambda x: str(vars[x.group(1)]), i) + d.write(i) + +def parent_dir(path): + if not os.path.isabs(path): + path = os.path.abspath(path) + if os.path.isfile(path): + path = os.path.dirname(path) + return os.path.split(path)[0] |