📄 gen_win.py
字号:
#
# gen_win.py -- base class for generating windows projects
#
import os
import sys
import string
import fnmatch
import re
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
import gen_base
import ezt
class WinGeneratorBase(gen_base.GeneratorBase):
"Base class for all Windows project files generators"
_extension_map = {
('exe', 'target'): '.exe',
('exe', 'object'): '.obj',
('lib', 'target'): '.dll',
('lib', 'object'): '.obj',
('script', 'target'): '',
('script', 'object'): '',
}
def parse_options(self, options):
self.apr_path = 'apr'
self.apr_util_path = 'apr-util'
self.apr_iconv_path = 'apr-iconv'
self.bdb_path = 'db4-win32'
self.httpd_path = None
self.zlib_path = None
self.openssl_path = None
self.junit_path = None
self.skip_sections = { 'mod_dav_svn': None,
'mod_authz_svn': None }
# Instrumentation options
self.instrument_apr_pools = None
self.instrument_purify_quantify = None
self.configure_apr_util = None
# NLS options
self.enable_nls = None
for opt, val in options:
if opt == '--with-berkeley-db':
self.bdb_path = val
elif opt == '--with-apr':
self.apr_path = val
elif opt == '--with-apr-util':
self.apr_util_path = val
elif opt == '--with-apr-iconv':
self.apr_iconv_path = val
elif opt == '--with-httpd':
self.httpd_path = val
del self.skip_sections['mod_dav_svn']
del self.skip_sections['mod_authz_svn']
elif opt == '--with-junit':
self.junit_path = val
elif opt == '--with-zlib':
self.zlib_path = val
elif opt == '--with-openssl':
self.openssl_path = val
elif opt == '--enable-purify':
self.instrument_purify_quantify = 1
self.instrument_apr_pools = 1
elif opt == '--enable-quantify':
self.instrument_purify_quantify = 1
elif opt == '--enable-pool-debug':
self.instrument_apr_pools = 1
elif opt == '--enable-nls':
self.enable_nls = 1
elif opt == '--enable-bdb-in-apr-util':
self.configure_apr_util = 1
def __init__(self, fname, verfname, options, subdir):
"""
Do some Windows specific setup
Build the list of Platforms & Configurations &
create the necessary paths
"""
# parse (and save) the options that were passed to us
self.parse_options(options)
# Find db-4.0.x or db-4.1.x
self._find_bdb()
# Find the right Perl library name to link SWIG bindings with
self._find_perl()
# Find the installed SWIG version to adjust swig options
self._find_swig()
# Run apr-util's w32locatedb.pl script
self._configure_apr_util()
#Make some files for the installer so that we don't need to
#require sed or some other command to do it
### GJS: don't do this right now
if 0:
buf = open(os.path.join("packages","win32-innosetup","svn.iss.in"), 'rb').read()
buf = buf.replace("@VERSION@", "0.16.1+").replace("@RELEASE@", "4365")
buf = buf.replace("@DBBINDLL@", self.dbbindll)
svnissrel = os.path.join("packages","win32-innosetup","svn.iss.release")
svnissdeb = os.path.join("packages","win32-innosetup","svn.iss.debug")
if self.write_file_if_changed(svnissrel, buf.replace("@CONFIG@", "Release")):
print 'Wrote %s' % svnissrel
if self.write_file_if_changed(svnissdeb, buf.replace("@CONFIG@", "Debug")):
print 'Wrote %s' % svnissdeb
# Generate the build_neon.bat file
data = {'expat_path': self.apr_util_path
and (os.path.abspath(self.apr_util_path)
+ '/xml/expat/lib'),
'zlib_path': self.zlib_path
and os.path.abspath(self.zlib_path),
'openssl_path': self.openssl_path
and os.path.abspath(self.openssl_path)}
self.write_with_template(os.path.join('build', 'win32', 'build_neon.bat'),
'build_neon.ezt', data)
# Generate the build_locale.bat file
pofiles = []
if self.enable_nls:
for po in os.listdir(os.path.join('subversion', 'po')):
if fnmatch.fnmatch(po, '*.po'):
pofiles.append(POFile(po[:-3]))
data = {'pofiles': pofiles}
self.write_with_template(os.path.join('build', 'win32', 'build_locale.bat'),
'build_locale.ezt', data)
#Initialize parent
gen_base.GeneratorBase.__init__(self, fname, verfname)
#Make the project files directory if it doesn't exist
#TODO win32 might not be the best path as win64 stuff will go here too
self.projfilesdir=os.path.join("build","win32",subdir)
self.rootpath = ".." + "\\.." * string.count(self.projfilesdir, os.sep)
if not os.path.exists(self.projfilesdir):
os.makedirs(self.projfilesdir)
#Here we can add additional platforms to compile for
self.platforms = ['Win32']
#Here we can add additional modes to compile for
self.configs = ['Debug','Release']
def path(self, *paths):
"""Convert build path to msvc path and prepend root"""
return msvc_path_join(self.rootpath, *map(msvc_path, paths))
def apath(self, path, *paths):
"""Convert build path to msvc path and prepend root if not absolute"""
### On Unix, os.path.isabs won't do the right thing if "item"
### contains backslashes or drive letters
if os.path.isabs(path):
return msvc_path_join(msvc_path(path), *map(msvc_path, paths))
else:
return msvc_path_join(self.rootpath, msvc_path(path),
*map(msvc_path, paths))
def get_install_targets(self):
"Generate the list of targets"
# Get list of targets to generate project files for
install_targets = self.graph.get_all_sources(gen_base.DT_INSTALL) \
+ self.graph.get_sources(gen_base.DT_LIST,
gen_base.LT_PROJECT)
# Don't create projects for scripts
install_targets = filter(lambda x: not isinstance(x, gen_base.TargetScript),
install_targets)
for target in install_targets:
if isinstance(target, gen_base.TargetLib) and target.msvc_fake:
install_targets.append(self.create_fake_target(target))
# sort these for output stability, to watch out for regressions.
install_targets.sort(lambda t1, t2: cmp(t1.name, t2.name))
return install_targets
def create_fake_target(self, dep):
"Return a new target which depends on another target but builds nothing"
section = gen_base.TargetProject.Section({'path': 'build/win32'},
gen_base.TargetProject)
section.create_targets(self.graph, dep.name + "_fake", self.cfg,
self._extension_map)
section.target.msvc_name = dep.msvc_name and dep.msvc_name + "_fake"
self.graph.add(gen_base.DT_LINK, section.target.name, dep)
dep.msvc_fake = section.target
return section.target
def get_configs(self, target):
"Get the list of configurations for the project"
configs = [ ]
for cfg in self.configs:
configs.append(
ProjectItem(name=cfg,
lower=string.lower(cfg),
defines=self.get_win_defines(target, cfg),
libdirs=self.get_win_lib_dirs(target, cfg),
libs=self.get_win_libs(target, cfg),
))
return configs
def get_proj_sources(self, quote_path, target):
"Get the list of source files for each project"
sources = [ ]
if not isinstance(target, gen_base.TargetProject):
cbuild = None
ctarget = None
for source, object, reldir in self.get_win_sources(target):
if isinstance(target, gen_base.TargetJavaHeaders):
classes = self.path(target.classes)
if self.junit_path is not None:
classes = "%s;%s" % (classes, self.junit_path)
headers = self.path(target.headers)
classname = target.package + "." + source.class_name
cbuild = "javah -verbose -force -classpath %s -d %s %s" \
% (self.quote(classes), self.quote(headers), classname)
ctarget = self.path(object.filename_win)
elif isinstance(target, gen_base.TargetJavaClasses):
classes = targetdir = self.path(target.classes)
if self.junit_path is not None:
classes = "%s;%s" % (classes, self.junit_path)
sourcepath = self.path(source.sourcepath)
cbuild = "javac -g -classpath %s -d %s -sourcepath %s $(InputPath)" \
% tuple(map(self.quote, (classes, targetdir, sourcepath)))
ctarget = self.path(object.filename)
rsrc = self.path(str(source))
if quote_path and '-' in rsrc:
rsrc = '"%s"' % rsrc
sources.append(ProjectItem(path=rsrc, reldir=reldir, user_deps=[],
custom_build=cbuild, custom_target=ctarget))
if isinstance(target, gen_base.TargetJavaClasses) and target.jar:
classdir = self.path(target.classes)
jarfile = msvc_path_join(classdir, target.jar)
cbuild = "jar cf %s -C %s %s" \
% (jarfile, classdir, string.join(target.packages))
deps = map(lambda x: x.custom_target, sources)
sources.append(ProjectItem(path='makejar', reldir='', user_deps=deps,
custom_build=cbuild, custom_target=jarfile))
if isinstance(target, gen_base.TargetSWIGRuntime):
for obj in self.graph.get_sources(gen_base.DT_LINK, target.name):
if isinstance(obj, gen_base.SWIGObject):
for cobj in self.graph.get_sources(gen_base.DT_OBJECT, obj):
if isinstance(cobj, gen_base.SWIGObject):
csrc = self.path(cobj.filename)
bsrc = self.path("build/win32/gen_swig_runtime.py")
cbuild = "python $(InputPath) %s %s %s" \
% (target.lang, csrc, self.quote(self.swig_libdir))
sources.append(ProjectItem(path=bsrc, reldir=None,
custom_build=cbuild,
custom_target=csrc,
user_deps=[]))
elif isinstance(target, gen_base.TargetSWIG):
swig_options = ["-" + target.lang]
swig_deps = []
if self.swig_vernum >= 103024:
pass
elif self.swig_vernum >= 103020:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -