5from __future__
import print_function
11from shutil
import copyfile
22 with open(fileName,
"w")
as f:
27 with open(projFileName)
as projFile:
28 lines = iter(projFile)
30 if "<ItemDefinitionGroup" in pLine:
31 while not "</ItemDefinitionGroup" in pLine:
42for root, dirs, files
in os.walk(
"out"):
44 gnFile = os.path.join(
"out", outDir,
"build.ninja.d")
45 if os.path.exists(gnFile):
46 slnFile = os.path.join(
"out", outDir,
"all.sln")
47 configs.append((outDir, os.path.exists(slnFile)))
51cppTypeGuid =
"8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942"
55projectPattern = (
r'Project\("\{' + cppTypeGuid +
56 r'\}"\) = "([^"]*)", "([^"]*)", "\{([^\}]*)\}"')
57projectNamePattern = (
r'obj/(.*)\.vcxproj')
61 slnLines = iter(open(
"out/" + config[0] +
"/all.sln"))
62 for slnLine
in slnLines:
63 matchObj = re.match(projectPattern, slnLine)
65 projPath = matchObj.group(2)
66 nameObj = re.match(projectNamePattern, projPath)
68 projName = nameObj.group(1).replace(
'/',
'.')
69 if projName
not in allProjects:
70 allProjects[projName] = []
71 allProjects[projName].
append((config[0], projPath,
76if len(allProjects) == 0:
77 print(
"ERROR: At least one GN directory must have been built with --ide=vs")
85 'Microsoft Visual Studio Solution File, Format Version 12.00\n')
86newSlnLines.append(
'# Visual Studio 2015\n')
87for projName, projConfigs
in allProjects.items():
88 newSlnLines.append(
'Project("{' + cppTypeGuid +
'}") = "' + projName +
89 '", "' + projConfigs[0][1] +
'", "{' + projConfigs[0][2]
91 newSlnLines.append(
'EndProject\n')
93newSlnLines.append(
'Global\n')
95 '\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n')
97 newSlnLines.append(
'\t\t' + config[0] +
'|x64 = ' + config[0] +
'|x64\n')
98newSlnLines.append(
'\tEndGlobalSection\n')
100 '\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n')
101for projName, projConfigs
in allProjects.items():
102 projGuid = projConfigs[0][2]
103 for config
in configs:
104 newSlnLines.append(
'\t\t{' + projGuid +
'}.' + config[0] +
105 '|x64.ActiveCfg = ' + config[0] +
'|x64\n')
106 newSlnLines.append(
'\t\t{' + projGuid +
'}.' + config[0] +
107 '|x64.Build.0 = ' + config[0] +
'|x64\n')
108newSlnLines.append(
'\tEndGlobalSection\n')
109newSlnLines.append(
'\tGlobalSection(SolutionProperties) = preSolution\n')
110newSlnLines.append(
'\t\tHideSolutionNode = FALSE\n')
111newSlnLines.append(
'\tEndGlobalSection\n')
112newSlnLines.append(
'\tGlobalSection(NestedProjects) = preSolution\n')
113newSlnLines.append(
'\tEndGlobalSection\n')
114newSlnLines.append(
'EndGlobal\n')
119idgHdr =
"<ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='"
122for projName, projConfigs
in allProjects.items():
124 srcProjPath = os.path.join(
"out", projConfigs[0][0], projConfigs[0][1])
125 dstProjPath = os.path.join(
"out",
"sln", projConfigs[0][1])
126 srcFilterPath = srcProjPath +
".filters"
127 dstFilterPath = dstProjPath +
".filters"
131 copyfile(srcFilterPath, dstFilterPath)
134 with open(srcProjPath)
as srcProjFile:
135 projLines = iter(srcProjFile)
137 for line
in projLines:
138 if "<ItemDefinitionGroup" in line:
142 while not "</ItemDefinitionGroup" in line:
143 idgLines.append(line)
145 idgLines.append(line)
146 for projConfig
in projConfigs:
150 newProjLines.append(idgHdr + projConfig[0] +
"|x64'\">\n")
151 for idgLine
in configIdgLines[1:]:
152 newProjLines.append(idgLine)
153 elif "ProjectConfigurations" in line:
154 newProjLines.append(line)
160 for config
in configs:
161 for projConfigLine
in projConfigLines:
162 newProjLines.append(projConfigLine.replace(
"GN",
164 elif "<OutDir" in line:
165 newProjLines.append(line.replace(projConfigs[0][0],
168 newProjLines.append(line)
169 with open(dstProjPath,
"w")
as newProj:
170 newProj.writelines(newProjLines)
static float next(float f)
static void append(char **dst, size_t *count, const char *src, size_t n)
def print(*args, **kwargs)