[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Windows vcproj generator

From: D.J. Heap <dj_at_shadyvale.net>
Date: 2003-06-24 03:21:39 CEST

Revised refactoring patch with _item class changed to ProjectItem, and a
bit of code beautification.

Log:

Refactor code common to dsp and vcproj generator into gen_win.py.

* build/generator/gen_vcnet_vcproj.py
* build/generator/gen_msvc_dsp.py
   (write_project): refactor configs and sources generation into
   calls to gen_win.py
   (write): refactor install_targets generation into call to
   gen_win.py and use it's new ProjectItem class
   (class _item): moved to gen_win.py as ProjectItem

* build/generator/gen_win.py
   (get_install_targets): refactored method
   (get_configs): refactored method
   (get_proj_sources): refactored method
   (class ProjectItem): refactored class

Index: build/generator/gen_vcnet_vcproj.py
===================================================================
--- build/generator/gen_vcnet_vcproj.py (revision 6324)
+++ build/generator/gen_vcnet_vcproj.py (working copy)
@@ -49,41 +49,10 @@
     else:
       raise gen_base.GenError("Cannot create project for %s" % target.name)
 
- configs = [ ]
- for cfg in self.configs:
- configs.append(_item(name=cfg,
- lower=string.lower(cfg),
- defines=self.get_win_defines(target, cfg),
- libdirs=self.get_win_lib_dirs(target,rootpath, cfg),
- libs=self.get_win_libs(target, cfg),
- ))
+ configs = self.get_configs(target, rootpath)
 
+ sources = self.get_proj_sources(False, target, rootpath)
 
- sources = [ ]
-
- if not isinstance(target, gen_base.TargetUtility):
- for src, reldir in self.get_win_sources(target):
- rsrc = string.replace(os.path.join(rootpath, src), os.sep, '\\')
- sources.append(_item(path=rsrc, reldir=reldir, swig_language=None,
- swig_output=None))
-
- if isinstance(target, gen_base.SWIGLibrary):
- for obj in self.graph.get_sources(gen_base.DT_LINK, target):
- 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 = rootpath + '\\' + string.replace(cobj.fname, '/', '\\')
- sources.append(_item(path=csrc, reldir=None, swig_language=None,
- swig_output=None))
-
- for ifile in self.graph.get_sources(gen_base.DT_SWIG_C, cobj):
- isrc = rootpath + '\\' + string.replace(ifile, '/', '\\')
- sources.append(_item(path=isrc, reldir=None,
- swig_language=target.lang,
- swig_output=csrc))
-
- sources.sort(lambda x, y: cmp(x.path, y.path))
-
     data = {
       'target' : target,
       'target_type' : config_type,
@@ -144,25 +113,10 @@
     self.move_proj_file(os.path.join('apr-util','uri'), 'gen_uri_delims.vcproj')
     self.move_proj_file(os.path.join('apr-util','xml', 'expat', 'lib'), 'xml.vcproj')
 
- # Generate a fake depaprutil project
- self.targets['depsubr'] = gen_base.TargetUtility('depsubr', None,
- 'build/win32',
- None, None, self.cfg,
- None)
- self.targets['depdelta'] = gen_base.TargetUtility('depdelta', None,
- 'build/win32',
- None, None, self.cfg,
- None)
+ install_targets = self.get_install_targets()
 
     targets = [ ]
 
- install_targets = self.targets.values() \
- + self.graph.get_all_sources(gen_base.DT_INSTALL)
- install_targets = gen_base.unique(install_targets)
-
- # sort these for output stability, to watch out for regressions.
- install_targets.sort()
-
     guids = { }
 
     # VC.NET uses GUIDs to refer to projects. generate them up front
@@ -201,22 +155,21 @@
 
       deplist = [ ]
       for i in range(len(depends)):
- deplist.append(_item(guid=guids[depends[i].name],
- index=i,
- ))
- targets.append(_item(name=target.name,
- path=string.replace(fname, os.sep, '\\'),
- guid=guids[target.name],
- depends=deplist,
- ))
+ deplist.append(gen_win.ProjectItem(guid=guids[depends[i].name],
+ index=i,
+ ))
+ targets.append(gen_win.ProjectItem(name=target.name,
+ path=string.replace(fname, os.sep, '\\'),
+ guid=guids[target.name],
+ depends=deplist,
+ ))
 
     targets.sort()
 
     configs = [ ]
     for i in range(len(self.configs)):
-
       ### this is different from write_project
- configs.append(_item(name=self.configs[i], index=i))
+ configs.append(gen_win.ProjectItem(name=self.configs[i], index=i))
 
     # sort the values for output stability.
     guidvals = guids.values()
@@ -230,7 +183,3 @@
       }
 
     self.write_with_template(oname, 'vcnet_sln.ezt', data)
-
-class _item:
- def __init__(self, **kw):
- vars(self).update(kw)
Index: build/generator/gen_win.py
===================================================================
--- build/generator/gen_win.py (revision 6324)
+++ build/generator/gen_win.py (working copy)
@@ -221,6 +221,67 @@
           libs.append(gen_base.ExternalLibrary(libname))
     return libs
 
+ def get_install_targets(self):
+ "Generate the list of targets"
+ # Generate a fake depaprutil project
+ self.targets['depsubr'] = gen_base.TargetUtility('depsubr', None,
+ 'build/win32',
+ None, None, self.cfg,
+ None)
+ self.targets['depdelta'] = gen_base.TargetUtility('depdelta', None,
+ 'build/win32',
+ None, None, self.cfg,
+ None)
+
+ install_targets = self.targets.values() \
+ + self.graph.get_all_sources(gen_base.DT_INSTALL)
+ install_targets = gen_base.unique(install_targets)
+
+ # sort these for output stability, to watch out for regressions.
+ install_targets.sort()
+ return install_targets
+
+ def get_configs(self, target, rootpath):
+ "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,rootpath, cfg),
+ libs=self.get_win_libs(target, cfg),
+ ))
+ return configs
+
+ def get_proj_sources(self, quote_path, target, rootpath):
+ "Get the list of source files for each project"
+ sources = [ ]
+ if not isinstance(target, gen_base.TargetUtility):
+ for src, reldir in self.get_win_sources(target):
+ rsrc = string.replace(os.path.join(rootpath, src), os.sep, '\\')
+ if quote_path and '-' in rsrc:
+ rsrc = '"%s"' % rsrc
+ sources.append(ProjectItem(path=rsrc, reldir=reldir, swig_language=None,
+ swig_output=None))
+
+ if isinstance(target, gen_base.SWIGLibrary):
+ for obj in self.graph.get_sources(gen_base.DT_LINK, target):
+ 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 = rootpath + '\\' + string.replace(cobj.fname, '/', '\\')
+ sources.append(ProjectItem(path=csrc, reldir=None, swig_language=None,
+ swig_output=None))
+
+ for ifile in self.graph.get_sources(gen_base.DT_SWIG_C, cobj):
+ isrc = rootpath + '\\' + string.replace(ifile, '/', '\\')
+ sources.append(ProjectItem(path=isrc, reldir=None,
+ swig_language=target.lang,
+ swig_output=csrc))
+
+ sources.sort(lambda x, y: cmp(x.path, y.path))
+ return sources
+
   def gen_proj_names(self, install_targets):
     "Generate project file names for the targets"
     # Generate project file names for the targets: replace dashes with
@@ -514,3 +575,8 @@
     "Override me when creating a new project type"
 
     raise NotImplementedError
+
+class ProjectItem:
+ "A generic item class for holding sources info, config info, etc for a project"
+ def __init__(self, **kw):
+ vars(self).update(kw)
Index: build/generator/gen_msvc_dsp.py
===================================================================
--- build/generator/gen_msvc_dsp.py (revision 6324)
+++ build/generator/gen_msvc_dsp.py (working copy)
@@ -51,41 +51,10 @@
     else:
       raise gen_base.GenError("Cannot create project for %s" % target.name)
 
- configs = [ ]
- for cfg in self.configs:
- configs.append(_item(name=cfg,
- lower=string.lower(cfg),
- defines=self.get_win_defines(target, cfg),
- libdirs=self.get_win_lib_dirs(target,rootpath, cfg),
- libs=self.get_win_libs(target, cfg),
- ))
+ configs = self.get_configs(target, rootpath)
 
- sources = [ ]
- if not isinstance(target, gen_base.TargetUtility):
- for src, reldir in self.get_win_sources(target):
- rsrc = string.replace(os.path.join(rootpath, src), os.sep, '\\')
- if '-' in rsrc:
- rsrc = '"%s"' % rsrc
- sources.append(_item(path=rsrc, reldir=reldir, swig_language=None,
- swig_output=None))
+ sources = self.get_proj_sources(True, target, rootpath)
 
- if isinstance(target, gen_base.SWIGLibrary):
- for obj in self.graph.get_sources(gen_base.DT_LINK, target):
- 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 = rootpath + '\\' + string.replace(cobj.fname, '/', '\\')
- sources.append(_item(path=csrc, reldir=None, swig_language=None,
- swig_output=None))
-
- for ifile in self.graph.get_sources(gen_base.DT_SWIG_C, cobj):
- isrc = rootpath + '\\' + string.replace(ifile, '/', '\\')
- sources.append(_item(path=isrc, reldir=None,
- swig_language=target.lang,
- swig_output=csrc))
-
- sources.sort(lambda x, y: cmp(x.path, y.path))
-
     data = {
       'target' : target,
       'target_type' : targtype,
@@ -113,23 +82,8 @@
   def write(self, oname):
     "Write a Workspace (.dsw)"
 
- # Generate a fake depaprutil project
- self.targets['depsubr'] = gen_base.TargetUtility('depsubr', None,
- 'build/win32',
- None, None, self.cfg,
- None)
- self.targets['depdelta'] = gen_base.TargetUtility('depdelta', None,
- 'build/win32',
- None, None, self.cfg,
- None)
-
- install_targets = self.targets.values() \
- + self.graph.get_all_sources(gen_base.DT_INSTALL)
- install_targets = gen_base.unique(install_targets)
-
- # sort these for output stability, to watch out for regressions.
- install_targets.sort()
-
+ install_targets = self.get_install_targets()
+
     targets = [ ]
 
     self.gen_proj_names(install_targets)
@@ -164,9 +118,9 @@
       for dep in depends:
         dep_names.append(dep.proj_name)
 
- targets.append(_item(name=target.proj_name,
- dsp=string.replace(fname, os.sep, '\\'),
- depends=dep_names))
+ targets.append(gen_win.ProjectItem(name=target.proj_name,
+ dsp=string.replace(fname, os.sep, '\\'),
+ depends=dep_names))
 
     targets.sort()
     data = {
@@ -174,8 +128,3 @@
       }
 
     self.write_with_template(oname, 'msvc_dsw.ezt', data)
-
-
-class _item:
- def __init__(self, **kw):
- vars(self).update(kw)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Jun 24 03:22:40 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.