# Copyright 2016 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. from __future__ import print_function import os import glob import re import sys from shutil import copyfile # Helpers def ensureExists(path): try: os.makedirs(path) except OSError: pass def writeLinesToFile(lines, fileName): ensureExists(os.path.dirname(fileName)) with open(fileName, "w") as f: f.writelines(lines) def extractIdg(projFileName): result = [] with open(projFileName) as projFile: lines = iter(projFile) for pLine in lines: if " [ (config, pathToProject, GUID), ... ] allProjects = {} projectPattern = (r'Project\("\{' + cppTypeGuid + r'\}"\) = "([^"]*)", "([^"]*)", "\{([^\}]*)\}"') projectNamePattern = (r'obj/(.*)\.vcxproj') for config in configs: if config[1]: slnLines = iter(open("out/" + config[0] + "/all.sln")) for slnLine in slnLines: matchObj = re.match(projectPattern, slnLine) if matchObj: projPath = matchObj.group(2) nameObj = re.match(projectNamePattern, projPath) if nameObj: projName = nameObj.group(1).replace('/', '.') if not allProjects.has_key(projName): allProjects[projName] = [] allProjects[projName].append((config[0], projPath, matchObj.group(3))) # We need something to work with. Typically, this will fail if no GN folders # have IDE files if len(allProjects) == 0: print("ERROR: At least one GN directory must have been built with --ide=vs") sys.exit() # Create a new solution. We arbitrarily use the first config as the GUID source # (but we need to match that behavior later, when we copy/generate the project # files). newSlnLines = [] newSlnLines.append( 'Microsoft Visual Studio Solution File, Format Version 12.00\n') newSlnLines.append('# Visual Studio 2015\n') for projName, projConfigs in allProjects.items(): newSlnLines.append('Project("{' + cppTypeGuid + '}") = "' + projName + '", "' + projConfigs[0][1] + '", "{' + projConfigs[0][2] + '}"\n') newSlnLines.append('EndProject\n') newSlnLines.append('Global\n') newSlnLines.append( '\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n') for config in configs: newSlnLines.append('\t\t' + config[0] + '|x64 = ' + config[0] + '|x64\n') newSlnLines.append('\tEndGlobalSection\n') newSlnLines.append( '\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n') for projName, projConfigs in allProjects.items(): projGuid = projConfigs[0][2] for config in configs: newSlnLines.append('\t\t{' + projGuid + '}.' + config[0] + '|x64.ActiveCfg = ' + config[0] + '|x64\n') newSlnLines.append('\t\t{' + projGuid + '}.' + config[0] + '|x64.Build.0 = ' + config[0] + '|x64\n') newSlnLines.append('\tEndGlobalSection\n') newSlnLines.append('\tGlobalSection(SolutionProperties) = preSolution\n') newSlnLines.append('\t\tHideSolutionNode = FALSE\n') newSlnLines.append('\tEndGlobalSection\n') newSlnLines.append('\tGlobalSection(NestedProjects) = preSolution\n') newSlnLines.append('\tEndGlobalSection\n') newSlnLines.append('EndGlobal\n') # Write solution file writeLinesToFile(newSlnLines, "out/sln/skia.sln") idgHdr = "\n") for idgLine in configIdgLines[1:]: newProjLines.append(idgLine) elif "ProjectConfigurations" in line: newProjLines.append(line) projConfigLines = [ projLines.next(), projLines.next(), projLines.next(), projLines.next() ] for config in configs: for projConfigLine in projConfigLines: newProjLines.append(projConfigLine.replace("GN", config[0])) elif "