From: <sv...@ww...> - 2007-01-02 00:06:34
|
Author: mkrose Date: 2007-01-01 16:06:26 -0800 (Mon, 01 Jan 2007) New Revision: 2050 Added: trunk/csp/tools/build/vcproj.py Modified: trunk/csp/tools/build/setup.py Log: Add support for generating vcproj files from the build definitions to allow the code to be browsed and edited more easily in Visual Studio. To generate csp.vcproj, run 'scons vcproj'. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=2050 Modified: trunk/csp/tools/build/setup.py =================================================================== --- trunk/csp/tools/build/setup.py 2007-01-01 07:41:35 UTC (rev 2049) +++ trunk/csp/tools/build/setup.py 2007-01-02 00:06:26 UTC (rev 2050) @@ -29,6 +29,7 @@ from csp.tools.build import registry from csp.tools.build import scons from csp.tools.build import util +from csp.tools.build import vcproj import atexit import logging @@ -85,6 +86,7 @@ CustomizeForPlatform(env, settings) AddSetupTargets(env) + AddVCProjectTarget(env) return env Initialize = classmethod(Initialize) @@ -255,7 +257,6 @@ #else: # print 'Setup failed; see .setup.log for details.' - def AddSetupTargets(env): def SetupProxy(*args, **kw): SetupClientWorkspace(0) def ForceSetupProxy(*args, **kw): SetupClientWorkspace(1) @@ -263,3 +264,7 @@ env.Command('setup', sources, SetupProxy) env.Command('force_setup', sources, ForceSetupProxy) +def AddVCProjectTarget(env): + def generate(*args, **kw): vcproj.Generate() + env.Command('vcproj', [], generate) + Added: trunk/csp/tools/build/vcproj.py =================================================================== --- trunk/csp/tools/build/vcproj.py 2007-01-01 07:41:35 UTC (rev 2049) +++ trunk/csp/tools/build/vcproj.py 2007-01-02 00:06:26 UTC (rev 2050) @@ -0,0 +1,91 @@ +# Copyright 2006 Mark Rose <mk...@us...> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +""" +Provides tools for generating Microsoft Visual C project files +from the registered source file definitions. The output is +currently intended only for browsing and editing the source +code in Visual Studio; support for building directly from +VS has not been implemented. +""" + +from csp.tools.build import registry +import random + +FILTER = { + 'Header Files': 'h;hpp;hxx;hm;inl;inc;xsd', + 'Source Files': 'cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx', +} + +def Generate(): + def addFiles(files, map): + for f in files: map[f.path] = f + + # todo: add other file types (e.g., swig interfaces)? + + files_by_type = {} + for name, group in registry.BuildRegistry._sources.iteritems(): + addFiles(group.getHeaders(), files_by_type.setdefault('Header Files', {})) + addFiles(group.getSources(), files_by_type.setdefault('Source Files', {})) + + vc = open('csp.vcproj', 'wt') + print >>vc, '<?xml version="1.0" encoding="Windows-1252"?>' + print >>vc, '<VisualStudioProject' + print >>vc, ' ProjectType="Visual C++"' + print >>vc, ' Version="8,00"' + print >>vc, ' Name="csp"' + print >>vc, ' ProjectGUID="{A8F54A28-33C4-4E48-A4F4-C15E062C3D50}"' + print >>vc, ' >' + print >>vc, ' <Platforms>' + print >>vc, ' <Platform Name="Win32"/>' + print >>vc, ' </Platforms>' + print >>vc, ' <Configurations>' + print >>vc, ' <Configuration' + print >>vc, ' Name="Debug|Win32"' + print >>vc, ' IntermediateDirectory="$(ConfigurationName)"' + print >>vc, ' ConfigurationType="1"' + print >>vc, ' >' + print >>vc, ' </Configuration>' + print >>vc, ' <Configuration' + print >>vc, ' Name="Release|Win32"' + print >>vc, ' IntermediateDirectory="$(ConfigurationName)"' + print >>vc, ' ConfigurationType="1"' + print >>vc, ' >' + print >>vc, ' </Configuration>' + print >>vc, ' </Configurations>' + print >>vc, ' <Files>' + for section, files in files_by_type.iteritems(): + print >>vc, ' <Filter' + print >>vc, ' Name="%s"' % section + print >>vc, ' Filter="%s"' % FILTER[section] + print >>vc, ' UniqueIdentifier="{4FC737F1-C7A5-4376-A066-%012X}"' % random.randint(0, 16**12) + print >>vc, ' >' + files = files.values() + files.sort() + for f in files: + print >>vc, ' <File RelativePath="%s"/>' % f.path + print >>vc, ' </Filter>' + print >>vc, ' </Files>' + print >>vc, '</VisualStudioProject>' + + print + print 'Wrote project definition to csp.vcproj.' + print + print 'Note that this project file is only useful for browsing and' + print 'editing the source code in Microsoft Visual Studio. To build,' + print 'run "scons all" from the command line. The vcproj file must' + print 'be manually regenerated by running "scons vcproj" whenever the' + print 'SConstruct/SConscript files change.' |