26 vcversions = {
"VC8": {
"sln":
"9.00",
"vc":
"2005"},
27 "VC9": {
"sln":
"10.00",
"vc":
"2008"},
28 "VC10": {
"sln":
"11.00",
"vc":
"2010"}
30 sln_template =
"""Microsoft Visual Studio Solution File, Format Version %s 32 [for proj in Projects] 33 Project("{[SolutionGUID]}") = "[proj.Name]", "[proj.FileName]", "{[proj.GUID]}" 34 ProjectSection(ProjectDependencies) = postProject 36 [for dep in proj.Depend] 44 GlobalSection(SolutionConfigurationPlatforms) = preSolution 45 [for conf in Configurations] 50 GlobalSection(ProjectConfigurationPlatforms) = postSolution 51 [for proj in Projects] 52 [for conf in Configurations] 53 {[proj.GUID]}.[conf].ActiveCfg = [conf] 55 {[proj.GUID]}.[conf].Build.0 = [conf] 60 GlobalSection(SolutionProperties) = preSolution 61 HideSolutionNode = FALSE 68 SolutionGUID: 8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942 78 slntool.py --dep dep_file [--outfile outfile] vcproj_files... 81 --vcversion: Visual C++'s version [VC8|VC9|VC10] 82 --dep: dependency file 83 --out or --output: output file name 86 * make solution from all of found vcprojs 87 slntool.py --dep dep_file --outfile MyApp.sln \ 88 `find ./ --name '*.vcproj'` 89 * output solution to stdout 90 slntool.py --dep dep_file *.vcproj 92 Depfile examples: The rule is similar to Makefile's dependency rule 93 All of entries should be Projectname. 94 [target Projectname]: [dependent projectsname...] 96 In the following App.dep file, "App" dpends on "Lib1" and "Lib2". 97 "Lib2" depends on "Lib1", "Lib1" has no dependency. 98 For this solution, "App", "Lib1" and "Lib2"'s project files are necessary. 111 re_guid = re.compile(
'^.*?ProjectGUID=\"{(.*)}\"')
112 re_name = re.compile(
'^.*?Name=\"(.*)\"')
113 fd = open(fname,
"r") 119 if name ==
None and n:
121 if guid ==
None and g:
127 return {
"Name": name,
"GUID": guid,
"FileName": fname}
132 regexs = {
"VC8": {
"guid":
'^.*?ProjectGUID=\"{(.*)}\"',
"name":
'^.*?Name=\"(.*)\"'},
133 "VC9": {
"guid":
'^.*?ProjectGUID=\"{(.*)}\"',
"name":
'^.*?Name=\"(.*)\"'},
134 "VC10": {
"guid":
'^.*?<ProjectGuid>{(.*)}</ProjectGuid>',
"name":
'^.*<ProjectName>(.*)</ProjectName>'}
136 re_guid = re.compile(regexs[vcversion][
"guid"])
137 re_name = re.compile(regexs[vcversion][
"name"])
138 fd = open(fname,
"r") 144 if name ==
None and n:
146 if guid ==
None and g:
152 return {
"Name": name,
"GUID": guid,
"FileName": fname}
155 if fname ==
None:
return {}
157 fd = open(fname,
"r") 158 for l
in fd.readlines():
159 (key, val) = l.split(
":")
175 if i < argc: depfile = argv[i]
177 elif opt ==
"--output" or opt ==
"--out":
179 if i < argc: outfile = argv[i]
181 elif opt ==
"--vcversion":
183 if i < argc: vcversion = argv[i]
185 if not vcversions.has_key(vcversion):
186 allowedvers = vcversions.keys().__repr__()
189 while i < argc
and argv[i][:2] !=
"--":
190 flist.append(argv[i])
193 return (vcversion, depfile, outfile, flist)
198 projlist =
"""Projects: 202 if depdict.has_key(pj[
"Name"]):
203 pj[
"Depend"] = depdict[pj[
"Name"]]
211 d0_depends = d0.has_key(
"Depend")
212 d1_depends = d1.has_key(
"Depend")
213 if not d0_depends
and not d1_depends:
217 if not d0_depends
and d1_depends:
221 if d0_depends
and not d1_depends:
226 d0_in_dep = depdict.has_key(d0[
"Name"])
227 d1_in_dep = depdict.has_key(d1[
"Name"])
228 if not d0_in_dep
and not d1_in_dep:
230 if not d0_in_dep
and d1_in_dep:
232 if d0_in_dep
and not d1_in_dep:
236 if depdict[d0[
"Name"]].count(d1[
"Name"]) > 0:
238 if depdict[d1[
"Name"]].count(d0[
"Name"]) > 0:
244 list =
""" - Name: %s 248 """ % (pj[
"Name"], pj[
"FileName"], pj[
"Name"], pj[
"GUID"])
249 if pj.has_key(
"Depend"):
250 for dep
in pj[
"Depend"]:
255 yaml_text = sln_yaml + projlist
261 projlist =
"""Projects: 265 if depdict.has_key(pj[
"Name"]):
266 pj[
"Depend"] = depdict[pj[
"Name"]]
274 d0_depends = d0.has_key(
"Depend")
275 d1_depends = d1.has_key(
"Depend")
276 if not d0_depends
and not d1_depends:
280 if not d0_depends
and d1_depends:
284 if d0_depends
and not d1_depends:
289 d0_in_dep = depdict.has_key(d0[
"Name"])
290 d1_in_dep = depdict.has_key(d1[
"Name"])
291 if not d0_in_dep
and not d1_in_dep:
293 if not d0_in_dep
and d1_in_dep:
295 if d0_in_dep
and not d1_in_dep:
299 if depdict[d0[
"Name"]].count(d1[
"Name"]) > 0:
301 if depdict[d1[
"Name"]].count(d0[
"Name"]) > 0:
307 list =
""" - Name: %s 311 """ % (pj[
"Name"], pj[
"FileName"], pj[
"Name"], pj[
"GUID"])
312 if pj.has_key(
"Depend"):
313 for dep
in pj[
"Depend"]:
318 yaml_text = sln_yaml + projlist
323 dict = yaml.load(yaml_text)
325 % (vcversions[version][
"sln"],
326 vcversions[version][
"vc"]))
327 return t.generate(dict).replace(
"\r\n",
"\n").replace(
"\n",
"\r\n")
333 class InvalidOption(SlnToolException):
335 self.
msg =
"Error: InvalidOption:\n " 347 except SlnToolException, e:
348 print "\n" + e.msg +
"\n" 362 fd = open(outfile,
"wb")
370 for f
in sys.argv[1:]:
382 if __name__ ==
"__main__":