From 2052c86a30dffcf124fd7beac293e7fce87bf5cb Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Wed, 14 Dec 2016 11:06:04 -0500 Subject: Move, rename, and document Visual Studio GN helper script BUG=skia: DOCS_PREVIEW= https://skia.org/?cl=5983 Change-Id: I32ac2c5275eb86adaa2be9ceee061b2956db70ad Reviewed-on: https://skia-review.googlesource.com/5983 Commit-Queue: Brian Osman Reviewed-by: Hal Canary --- gn/gn_meta_sln.py | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 gn/gn_meta_sln.py (limited to 'gn/gn_meta_sln.py') diff --git a/gn/gn_meta_sln.py b/gn/gn_meta_sln.py new file mode 100644 index 0000000000..2cb4ae59ae --- /dev/null +++ b/gn/gn_meta_sln.py @@ -0,0 +1,164 @@ +# 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. + +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'\}"\) = "([^"]*)", "([^"]*)", "\{([^\}]*)\}"') + +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: + projName = matchObj.group(1) + if not allProjects.has_key(projName): + allProjects[projName] = [] + allProjects[projName].append((config[0], matchObj.group(2), + 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 "