25 vcversions = {
"VC8": {
"sln":
"9.00",
"vc":
"2005"},
26 "VC9": {
"sln":
"10.00",
"vc":
"2008"},
27 "VC10": {
"sln":
"11.00",
"vc":
"2010"},
28 "VC11": {
"sln":
"12.00",
"vc":
"2012"},
29 "VC12": {
"sln":
"13.00",
"vc":
"2013"},
30 "VC14": {
"sln":
"15.00",
"vc":
"2015"},
32 sln_template =
"""Microsoft Visual Studio Solution File, Format Version %s 34 [for proj in Projects] 35 Project("{[SolutionGUID]}") = "[proj.Name]", "[proj.FileName]", "{[proj.GUID]}" 36 ProjectSection(ProjectDependencies) = postProject 38 [for dep in proj.Depend] 46 GlobalSection(SolutionConfigurationPlatforms) = preSolution 47 [for conf in Configurations] 52 GlobalSection(ProjectConfigurationPlatforms) = postSolution 53 [for proj in Projects] 54 [for conf in Configurations] 55 {[proj.GUID]}.[conf].ActiveCfg = [conf] 57 {[proj.GUID]}.[conf].Build.0 = [conf] 62 GlobalSection(SolutionProperties) = preSolution 63 HideSolutionNode = FALSE 70 SolutionGUID: 8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942 82 slntool.py --dep dep_file [--outfile outfile] vcproj_files... 85 --vcversion: Visual C++'s version [VC8|VC9|VC10|VC11|VC12|VC14] 86 --dep: dependency file 87 --out or --output: output file name 90 * make solution from all of found vcprojs 91 slntool.py --dep dep_file --outfile MyApp.sln \ 92 `find ./ --name '*.vcproj'` 93 * output solution to stdout 94 slntool.py --dep dep_file *.vcproj 96 Depfile examples: The rule is similar to Makefile's dependency rule 97 All of entries should be Projectname. 98 [target Projectname]: [dependent projectsname...] 100 In the following App.dep file, "App" dpends on "Lib1" and "Lib2". 101 "Lib2" depends on "Lib1", "Lib1" has no dependency. 102 For this solution, "App", "Lib1" and "Lib2"'s project files are necessary. 115 regexs = {
"VC8": {
"guid":
'^.*?ProjectGUID=\"{(.*)}\"',
"name":
'^.*?Name=\"(.*)\"'},
116 "VC9": {
"guid":
'^.*?ProjectGUID=\"{(.*)}\"',
"name":
'^.*?Name=\"(.*)\"'},
117 "VC10": {
"guid":
'^.*?<ProjectGuid>{(.*)}</ProjectGuid>',
"name":
'^.*<ProjectName>(.*)</ProjectName>'},
118 "VC11": {
"guid":
'^.*?<ProjectGuid>{(.*)}</ProjectGuid>',
"name":
'^.*<ProjectName>(.*)</ProjectName>'},
119 "VC12": {
"guid":
'^.*?<ProjectGuid>{(.*)}</ProjectGuid>',
"name":
'^.*<ProjectName>(.*)</ProjectName>'},
120 "VC14": {
"guid":
'^.*?<ProjectGuid>{(.*)}</ProjectGuid>',
"name":
'^.*<ProjectName>(.*)</ProjectName>'},
122 re_guid = re.compile(regexs[vcversion][
"guid"])
123 re_name = re.compile(regexs[vcversion][
"name"])
124 fd = open(fname,
"r") 130 if name ==
None and n:
132 if guid ==
None and g:
138 return {
"Name": name,
"GUID": guid,
"FileName": fname}
141 if fname ==
None:
return {}
143 fd = open(fname,
"r") 144 for l
in fd.readlines():
145 (key, val) = l.split(
":")
161 if i < argc: depfile = argv[i]
163 elif opt ==
"--output" or opt ==
"--out":
165 if i < argc: outfile = argv[i]
167 elif opt ==
"--vcversion":
169 if i < argc: vcversion = argv[i]
171 if not vcversions.has_key(vcversion):
172 allowedvers = vcversions.keys().__repr__()
175 while i < argc
and argv[i][:2] !=
"--":
176 flist.append(argv[i])
179 return (vcversion, depfile, outfile, flist)
184 projlist =
"""Projects: 188 if depdict.has_key(pj[
"Name"]):
189 pj[
"Depend"] = depdict[pj[
"Name"]]
197 d0_depends = d0.has_key(
"Depend")
198 d1_depends = d1.has_key(
"Depend")
199 if not d0_depends
and not d1_depends:
203 if not d0_depends
and d1_depends:
207 if d0_depends
and not d1_depends:
212 d0_in_dep = depdict.has_key(d0[
"Name"])
213 d1_in_dep = depdict.has_key(d1[
"Name"])
214 if not d0_in_dep
and not d1_in_dep:
216 if not d0_in_dep
and d1_in_dep:
218 if d0_in_dep
and not d1_in_dep:
222 if depdict[d0[
"Name"]].count(d1[
"Name"]) > 0:
224 if depdict[d1[
"Name"]].count(d0[
"Name"]) > 0:
230 list =
""" - Name: %s 234 """ % (pj[
"Name"], pj[
"FileName"], pj[
"Name"], pj[
"GUID"])
235 if pj.has_key(
"Depend"):
236 for dep
in pj[
"Depend"]:
241 yaml_text = sln_yaml + projlist
246 dict = yaml.load(yaml_text)
248 % (vcversions[version][
"sln"],
249 vcversions[version][
"vc"]))
250 return t.generate(dict).replace(
"\r\n",
"\n").replace(
"\n",
"\r\n")
256 class InvalidOption(SlnToolException):
258 self.
msg =
"Error: InvalidOption:\n " 270 except SlnToolException, e:
271 print "\n" + e.msg +
"\n" 285 fd = open(outfile,
"wb")
293 for f
in sys.argv[1:]:
305 if __name__ ==
"__main__":