From 9c7df09c3bc784d19c206e8c17c3c288368541d1 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Wed, 9 Sep 2015 11:54:11 +0800 Subject: [PATCH] MSVC Builds: Simplify Script to Generate glib-mkenums Use a simple all-purpose utility script to generate the glib-mkenums PERL script with the version info, and stop using the script that tries to parse the autotools files. Move the things that were taken out from build/win32/setup.py back there. --- build/win32/Makefile.am | 2 +- build/win32/process_in_win32.py | 77 --------------- build/win32/replace.py | 98 +++++++++++++++++++ build/win32/setup.py | 35 ++++++- build/win32/vs10/Makefile.am | 3 +- ...-gen-srcs.props => glib-gen-srcs.props.in} | 4 +- build/win32/vs9/Makefile.am | 3 +- ...-srcs.vsprops => glib-gen-srcs.vsprops.in} | 2 +- configure.ac | 2 + 9 files changed, 142 insertions(+), 84 deletions(-) delete mode 100644 build/win32/process_in_win32.py create mode 100644 build/win32/replace.py rename build/win32/vs10/{glib-gen-srcs.props => glib-gen-srcs.props.in} (87%) rename build/win32/vs9/{glib-gen-srcs.vsprops => glib-gen-srcs.vsprops.in} (82%) diff --git a/build/win32/Makefile.am b/build/win32/Makefile.am index e7b1e63dc..105888db7 100644 --- a/build/win32/Makefile.am +++ b/build/win32/Makefile.am @@ -8,4 +8,4 @@ SUBDIRS = \ EXTRA_DIST = \ make.msc \ module.defs \ - process_in_win32.py + replace.py diff --git a/build/win32/process_in_win32.py b/build/win32/process_in_win32.py deleted file mode 100644 index 62a8e3a19..000000000 --- a/build/win32/process_in_win32.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/python -# vim: encoding=utf-8 -#expand *.in scripts for MSVC Builds -import os -import sys -import re -import string -import argparse - -def get_version(srcroot): - ver = {} - RE_VERSION = re.compile(r'^m4_define\(\[(glib_\w+)\],\s*\[(\d+)\]\)') - with open(os.path.join(srcroot, 'configure.ac'), 'r') as ac: - for i in ac: - mo = RE_VERSION.search(i) - if mo: - ver[mo.group(1).upper()] = int(mo.group(2)) - ver['GLIB_BINARY_AGE'] = 100 * ver['GLIB_MINOR_VERSION'] + ver['GLIB_MICRO_VERSION'] - ver['GLIB_VERSION'] = '%d.%d.%d' % (ver['GLIB_MAJOR_VERSION'], - ver['GLIB_MINOR_VERSION'], - ver['GLIB_MICRO_VERSION']) - ver['LT_RELEASE'] = '%d.%d' % (ver['GLIB_MAJOR_VERSION'], ver['GLIB_MINOR_VERSION']) - ver['LT_CURRENT'] = 100 * ver['GLIB_MINOR_VERSION'] + ver['GLIB_MICRO_VERSION'] - ver['GLIB_INTERFACE_AGE'] - ver['LT_REVISION'] = ver['GLIB_INTERFACE_AGE'] - ver['LT_AGE'] = ver['GLIB_BINARY_AGE'] - ver['GLIB_INTERFACE_AGE'] - ver['LT_CURRENT_MINUS_AGE'] = ver['LT_CURRENT'] - ver['LT_AGE'] - return ver - -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 get_srcroot(): - if not os.path.isabs(__file__): - path = os.path.abspath(__file__) - else: - path = __file__ - dirname = os.path.dirname(path) - return os.path.abspath(os.path.join(dirname, '..', '..')) - -def main(argv): - prog_desc = 'Create Various autogenerated Win32-specific Source Files' - parser = argparse.ArgumentParser(description=prog_desc) - parser.add_argument('--glib-mkenums', dest='mkenums', action='store_const', - const=1, - help='Generate glib-mkenums') - - parser.add_argument('--perl', dest='perl', metavar='PATH', - default='C:\\Perl\\bin\\perl.exe', - action='store', - help='path to the perl interpretor (default: C:\\Perl\\bin\\perl.exe)') - - args = parser.parse_args() - srcroot = get_srcroot() - ver = get_version(srcroot) - - no_args = True - - if args.mkenums is not None: - # Generate glib-mkenums script from glib-mkenums - ver.update({'PERL_PATH': args.perl}) - - target = os.path.join(srcroot, 'gobject', 'glib-mkenums') - process_in(target + '.in', - target, - ver) - no_args = False - - if no_args is True: - raise SystemExit('Action argument required. Please see %s --help for details.' % __file__) - -if __name__ == '__main__': - sys.exit(main(sys.argv)) diff --git a/build/win32/replace.py b/build/win32/replace.py new file mode 100644 index 000000000..ea75dafa5 --- /dev/null +++ b/build/win32/replace.py @@ -0,0 +1,98 @@ +#!/usr/bin/python +# +# Simple utility script to manipulate +# certain types of strings in a file +# +# Author: Fan, Chun-wei +# Date: September 03, 2014 + +import os +import sys +import re +import string +import argparse + +valid_actions = ['remove-prefix', + 'replace-var', + 'replace-str', + 'remove-str'] + +def replace(src, dest, instring, outstring): + with open(src, 'r') as s: + with open(dest, 'w') as d: + for line in s: + i = line.replace(instring, outstring) + d.write(i) + +def check_required_args(args, params): + for param in params: + if getattr(args, param, None) is None: + raise SystemExit('%s: error: --%s argument is required' % (__file__, param)) + +def warn_ignored_args(args, params): + for param in params: + if getattr(args, param, None) is not None: + print('%s: warning: --%s argument is ignored' % (__file__, param)) + +def main(argv): + + parser = argparse.ArgumentParser(description='Process strings in a file.') + parser.add_argument('-a', + '--action', + help='Action to carry out. Can be one of:\n' + 'remove-prefix\n' + 'replace-var\n' + 'replace-str\n' + 'remove-str', + choices=valid_actions) + parser.add_argument('-i', '--input', help='Input file') + parser.add_argument('-o', '--output', help='Output file') + parser.add_argument('--instring', help='String to replace or remove') + parser.add_argument('--var', help='Autotools variable name to replace') + parser.add_argument('--outstring', + help='New String to replace specified string or variable') + parser.add_argument('--removeprefix', help='Prefix of string to remove') + + args = parser.parse_args() + + input_string = '' + output_string = '' + + # We must have action, input, output for all operations + check_required_args(args, ['action','input','output']) + + # Build the arguments by the operation that is to be done, + # to be fed into replace() + + # Get rid of prefixes from a string + if args.action == 'remove-prefix': + check_required_args(args, ['instring','removeprefix']) + warn_ignored_args(args, ['outstring','var']) + input_string = args.removeprefix + args.instring + output_string = args.instring + + # Replace an m4-style variable (those surrounded by @...@) + if args.action == 'replace-var': + check_required_args(args, ['var','outstring']) + warn_ignored_args(args, ['instring','removeprefix']) + input_string = '@' + args.var + '@' + output_string = args.outstring + + # Replace a string + if args.action == 'replace-str': + check_required_args(args, ['instring','outstring']) + warn_ignored_args(args, ['var','removeprefix']) + input_string = args.instring + output_string = args.outstring + + # Remove a string + if args.action == 'remove-str': + check_required_args(args, ['instring']) + warn_ignored_args(args, ['var','outstring','removeprefix']) + input_string = args.instring + output_string = '' + + replace(args.input, args.output, input_string, output_string) + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/build/win32/setup.py b/build/win32/setup.py index ef732c6df..749b880f9 100644 --- a/build/win32/setup.py +++ b/build/win32/setup.py @@ -9,7 +9,40 @@ import string import subprocess import optparse -from process_in_win32 import get_version, process_in, get_srcroot +def get_version(srcroot): + ver = {} + RE_VERSION = re.compile(r'^m4_define\(\[(glib_\w+)\],\s*\[(\d+)\]\)') + with open(os.path.join(srcroot, 'configure.ac'), 'r') as ac: + for i in ac: + mo = RE_VERSION.search(i) + if mo: + ver[mo.group(1).upper()] = int(mo.group(2)) + ver['GLIB_BINARY_AGE'] = 100 * ver['GLIB_MINOR_VERSION'] + ver['GLIB_MICRO_VERSION'] + ver['GLIB_VERSION'] = '%d.%d.%d' % (ver['GLIB_MAJOR_VERSION'], + ver['GLIB_MINOR_VERSION'], + ver['GLIB_MICRO_VERSION']) + ver['LT_RELEASE'] = '%d.%d' % (ver['GLIB_MAJOR_VERSION'], ver['GLIB_MINOR_VERSION']) + ver['LT_CURRENT'] = 100 * ver['GLIB_MINOR_VERSION'] + ver['GLIB_MICRO_VERSION'] - ver['GLIB_INTERFACE_AGE'] + ver['LT_REVISION'] = ver['GLIB_INTERFACE_AGE'] + ver['LT_AGE'] = ver['GLIB_BINARY_AGE'] - ver['GLIB_INTERFACE_AGE'] + ver['LT_CURRENT_MINUS_AGE'] = ver['LT_CURRENT'] - ver['LT_AGE'] + return ver + +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 get_srcroot(): + if not os.path.isabs(__file__): + path = os.path.abspath(__file__) + else: + path = __file__ + dirname = os.path.dirname(path) + return os.path.abspath(os.path.join(dirname, '..', '..')) def process_include(src, dest, includes): RE_INCLUDE = re.compile(r'^\s*#include\s+"(.*)"') diff --git a/build/win32/vs10/Makefile.am b/build/win32/vs10/Makefile.am index 15fbfee57..94c1f1250 100644 --- a/build/win32/vs10/Makefile.am +++ b/build/win32/vs10/Makefile.am @@ -9,6 +9,7 @@ GENERATED_ITEMS = \ glib-compile-schemas.vcxproj.filters \ glib-compile-resources.vcxproj \ glib-compile-resources.vcxproj.filters \ + glib-gen-srcs.props \ glib-install.props EXTRA_DIST = \ @@ -46,7 +47,7 @@ EXTRA_DIST = \ glib-build-defines.props \ glib-install.propsin \ glib-version-paths.props \ - glib-gen-srcs.props \ + glib-gen-srcs.props.in \ $(GENERATED_ITEMS) glib-install.props: $(top_srcdir)/build/win32/vs10/glib-install.propsin glib.vs10.headers gobject.vs10.headers gio.vs10.headers diff --git a/build/win32/vs10/glib-gen-srcs.props b/build/win32/vs10/glib-gen-srcs.props.in similarity index 87% rename from build/win32/vs10/glib-gen-srcs.props rename to build/win32/vs10/glib-gen-srcs.props.in index 7707e6762..5cc213fac 100644 --- a/build/win32/vs10/glib-gen-srcs.props +++ b/build/win32/vs10/glib-gen-srcs.props.in @@ -8,7 +8,7 @@ copy ..\..\..\glib\glibconfig.h.win32 ..\..\..\glib\glibconfig.h copy ..\..\..\gmodule\gmoduleconf.h.win32 ..\..\..\gmodule\gmoduleconf.h copy ..\..\..\gio\gnetworking.h.win32 ..\..\..\gio\gnetworking.h - if exist $(PythonPath)\python.exe $(PythonPath)\python.exe ..\process_in_win32.py --glib-mkenums + if exist $(PythonPath)\python.exe $(PythonPath)\python.exe ..\replace.py --action=replace-var --input=..\..\..\gobject\glib-mkenums.in --output=..\..\..\gobject\glib-mkenums --var=GLIB_VERSION --outstring=@GLIB_VERSION@ <_PropertySheetDisplayName>glibgensrcsprops @@ -30,4 +30,4 @@ $(GenGLibMKEnums) - \ No newline at end of file + diff --git a/build/win32/vs9/Makefile.am b/build/win32/vs9/Makefile.am index 07cd432fc..f2c53dace 100644 --- a/build/win32/vs9/Makefile.am +++ b/build/win32/vs9/Makefile.am @@ -4,6 +4,7 @@ GENERATED_ITEMS = \ gio.vcproj \ glib-compile-schemas.vcproj \ glib-compile-resources.vcproj \ + glib-gen-srcs.vsprops \ glib-install.vsprops EXTRA_DIST = \ @@ -26,7 +27,7 @@ EXTRA_DIST = \ glib-install.vcproj \ glib-build-defines.vsprops \ glib-version-paths.vsprops \ - glib-gen-srcs.vsprops \ + glib-gen-srcs.vsprops.in \ glib-install.vspropsin \ $(GENERATED_ITEMS) diff --git a/build/win32/vs9/glib-gen-srcs.vsprops b/build/win32/vs9/glib-gen-srcs.vsprops.in similarity index 82% rename from build/win32/vs9/glib-gen-srcs.vsprops rename to build/win32/vs9/glib-gen-srcs.vsprops.in index be94d2d2d..c317aa8ad 100644 --- a/build/win32/vs9/glib-gen-srcs.vsprops +++ b/build/win32/vs9/glib-gen-srcs.vsprops.in @@ -23,6 +23,6 @@ /> diff --git a/configure.ac b/configure.ac index 975f7cd73..e344cd83a 100644 --- a/configure.ac +++ b/configure.ac @@ -3565,7 +3565,9 @@ build/Makefile build/win32/Makefile build/win32/dirent/Makefile build/win32/vs9/Makefile +build/win32/vs9/glib-gen-srcs.vsprops build/win32/vs10/Makefile +build/win32/vs10/glib-gen-srcs.props build/win32/vs11/Makefile build/win32/vs12/Makefile glib/Makefile