mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-09 12:25:48 +01:00
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.
This commit is contained in:
parent
0570adff80
commit
9c7df09c3b
@ -8,4 +8,4 @@ SUBDIRS = \
|
|||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
make.msc \
|
make.msc \
|
||||||
module.defs \
|
module.defs \
|
||||||
process_in_win32.py
|
replace.py
|
||||||
|
@ -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))
|
|
98
build/win32/replace.py
Normal file
98
build/win32/replace.py
Normal file
@ -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))
|
@ -9,7 +9,40 @@ import string
|
|||||||
import subprocess
|
import subprocess
|
||||||
import optparse
|
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):
|
def process_include(src, dest, includes):
|
||||||
RE_INCLUDE = re.compile(r'^\s*#include\s+"(.*)"')
|
RE_INCLUDE = re.compile(r'^\s*#include\s+"(.*)"')
|
||||||
|
@ -9,6 +9,7 @@ GENERATED_ITEMS = \
|
|||||||
glib-compile-schemas.vcxproj.filters \
|
glib-compile-schemas.vcxproj.filters \
|
||||||
glib-compile-resources.vcxproj \
|
glib-compile-resources.vcxproj \
|
||||||
glib-compile-resources.vcxproj.filters \
|
glib-compile-resources.vcxproj.filters \
|
||||||
|
glib-gen-srcs.props \
|
||||||
glib-install.props
|
glib-install.props
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
@ -46,7 +47,7 @@ EXTRA_DIST = \
|
|||||||
glib-build-defines.props \
|
glib-build-defines.props \
|
||||||
glib-install.propsin \
|
glib-install.propsin \
|
||||||
glib-version-paths.props \
|
glib-version-paths.props \
|
||||||
glib-gen-srcs.props \
|
glib-gen-srcs.props.in \
|
||||||
$(GENERATED_ITEMS)
|
$(GENERATED_ITEMS)
|
||||||
|
|
||||||
glib-install.props: $(top_srcdir)/build/win32/vs10/glib-install.propsin glib.vs10.headers gobject.vs10.headers gio.vs10.headers
|
glib-install.props: $(top_srcdir)/build/win32/vs10/glib-install.propsin glib.vs10.headers gobject.vs10.headers gio.vs10.headers
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<GenGLibConfigH>copy ..\..\..\glib\glibconfig.h.win32 ..\..\..\glib\glibconfig.h</GenGLibConfigH>
|
<GenGLibConfigH>copy ..\..\..\glib\glibconfig.h.win32 ..\..\..\glib\glibconfig.h</GenGLibConfigH>
|
||||||
<GenGModuleConfH>copy ..\..\..\gmodule\gmoduleconf.h.win32 ..\..\..\gmodule\gmoduleconf.h</GenGModuleConfH>
|
<GenGModuleConfH>copy ..\..\..\gmodule\gmoduleconf.h.win32 ..\..\..\gmodule\gmoduleconf.h</GenGModuleConfH>
|
||||||
<GenGNetworkingH>copy ..\..\..\gio\gnetworking.h.win32 ..\..\..\gio\gnetworking.h</GenGNetworkingH>
|
<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>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<_PropertySheetDisplayName>glibgensrcsprops</_PropertySheetDisplayName>
|
<_PropertySheetDisplayName>glibgensrcsprops</_PropertySheetDisplayName>
|
||||||
@ -30,4 +30,4 @@
|
|||||||
<Value>$(GenGLibMKEnums)</Value>
|
<Value>$(GenGLibMKEnums)</Value>
|
||||||
</BuildMacro>
|
</BuildMacro>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -4,6 +4,7 @@ GENERATED_ITEMS = \
|
|||||||
gio.vcproj \
|
gio.vcproj \
|
||||||
glib-compile-schemas.vcproj \
|
glib-compile-schemas.vcproj \
|
||||||
glib-compile-resources.vcproj \
|
glib-compile-resources.vcproj \
|
||||||
|
glib-gen-srcs.vsprops \
|
||||||
glib-install.vsprops
|
glib-install.vsprops
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
@ -26,7 +27,7 @@ EXTRA_DIST = \
|
|||||||
glib-install.vcproj \
|
glib-install.vcproj \
|
||||||
glib-build-defines.vsprops \
|
glib-build-defines.vsprops \
|
||||||
glib-version-paths.vsprops \
|
glib-version-paths.vsprops \
|
||||||
glib-gen-srcs.vsprops \
|
glib-gen-srcs.vsprops.in \
|
||||||
glib-install.vspropsin \
|
glib-install.vspropsin \
|
||||||
$(GENERATED_ITEMS)
|
$(GENERATED_ITEMS)
|
||||||
|
|
||||||
|
@ -23,6 +23,6 @@
|
|||||||
/>
|
/>
|
||||||
<UserMacro
|
<UserMacro
|
||||||
Name="GenGLibMKEnums"
|
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>
|
</VisualStudioPropertySheet>
|
@ -3565,7 +3565,9 @@ build/Makefile
|
|||||||
build/win32/Makefile
|
build/win32/Makefile
|
||||||
build/win32/dirent/Makefile
|
build/win32/dirent/Makefile
|
||||||
build/win32/vs9/Makefile
|
build/win32/vs9/Makefile
|
||||||
|
build/win32/vs9/glib-gen-srcs.vsprops
|
||||||
build/win32/vs10/Makefile
|
build/win32/vs10/Makefile
|
||||||
|
build/win32/vs10/glib-gen-srcs.props
|
||||||
build/win32/vs11/Makefile
|
build/win32/vs11/Makefile
|
||||||
build/win32/vs12/Makefile
|
build/win32/vs12/Makefile
|
||||||
glib/Makefile
|
glib/Makefile
|
||||||
|
Loading…
x
Reference in New Issue
Block a user