[glib] MSVC Builds: Simplify Script to Generate glib-mkenums
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] MSVC Builds: Simplify Script to Generate glib-mkenums
- Date: Wed, 9 Sep 2015 07:21:36 +0000 (UTC)
commit 9c7df09c3bc784d19c206e8c17c3c288368541d1
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Wed Sep 9 11:54:11 2015 +0800
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 +-
...{glib-gen-srcs.props => glib-gen-srcs.props.in} | 4 +-
build/win32/vs9/Makefile.am | 3 +-
...b-gen-srcs.vsprops => glib-gen-srcs.vsprops.in} | 2 +-
configure.ac | 2 +
9 files changed, 142 insertions(+), 84 deletions(-)
---
diff --git a/build/win32/Makefile.am b/build/win32/Makefile.am
index e7b1e63..105888d 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/replace.py b/build/win32/replace.py
new file mode 100644
index 0000000..ea75daf
--- /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 ef732c6..749b880 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 15fbfee..94c1f12 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 7707e67..5cc213f 100644
--- a/build/win32/vs10/glib-gen-srcs.props
+++ b/build/win32/vs10/glib-gen-srcs.props.in
@@ -8,7 +8,7 @@
<GenGLibConfigH>copy ..\..\..\glib\glibconfig.h.win32 ..\..\..\glib\glibconfig.h</GenGLibConfigH>
<GenGModuleConfH>copy ..\..\..\gmodule\gmoduleconf.h.win32
..\..\..\gmodule\gmoduleconf.h</GenGModuleConfH>
<GenGNetworkingH>copy ..\..\..\gio\gnetworking.h.win32 ..\..\..\gio\gnetworking.h</GenGNetworkingH>
- <GenGLibMKEnums>if exist $(PythonPath)\python.exe $(PythonPath)\python.exe ..\process_in_win32.py
--glib-mkenums</GenGLibMKEnums>
+ <GenGLibMKEnums>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@</GenGLibMKEnums>
</PropertyGroup>
<PropertyGroup>
<_PropertySheetDisplayName>glibgensrcsprops</_PropertySheetDisplayName>
@@ -30,4 +30,4 @@
<Value>$(GenGLibMKEnums)</Value>
</BuildMacro>
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/build/win32/vs9/Makefile.am b/build/win32/vs9/Makefile.am
index 07cd432..f2c53da 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 be94d2d..c317aa8 100644
--- a/build/win32/vs9/glib-gen-srcs.vsprops
+++ b/build/win32/vs9/glib-gen-srcs.vsprops.in
@@ -23,6 +23,6 @@
/>
<UserMacro
Name="GenGLibMKEnums"
- Value="if exist $(PythonPath)\python.exe $(PythonPath)\python.exe ..\process_in_win32.py
--glib-mkenums"
+ Value="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@"
/>
</VisualStudioPropertySheet>
diff --git a/configure.ac b/configure.ac
index 975f7cd..e344cd8 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]