skia2/fix-gn-sln.py
Brian Osman c20d34ca03 Script to fix GN generated solutions
Assumes that all GN configurations are in 'out'. Takes the name of a
single directory (which should have been generated with --ide=vs) as
input. Creates a new solution and project tree in 'out/sln/skia.sln'
with one configuration per directory in 'out'.

Example: From skia directory, run 'python fix-gn-sln.py Debug'

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4158

Change-Id: I797b779eb5bc30cec0e6741d4262894fc0648e97
Reviewed-on: https://skia-review.googlesource.com/4158
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Cary Clark <caryclark@google.com>
2016-10-31 17:01:16 +00:00

82 lines
2.8 KiB
Python

# 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 sys
from shutil import copyfile
srcDir = sys.argv[1]
# Get list of existing directories to use as configs
configs = []
for root, dirs, files in os.walk("out"):
for outDir in dirs:
if os.path.exists("out/" + outDir + "/build.ninja.d"):
configs.append(outDir)
break
# Ensure directories exist
try:
os.makedirs("out/sln/obj")
except OSError:
pass
# Remove old files
for root, dirs, files in os.walk("out/sln"):
for name in files:
os.remove(os.path.join(root, name))
# Copy filter files unmodified
for filterFile in glob.glob("out/" + srcDir + "/obj/*.filters"):
copyfile(filterFile, filterFile.replace("out/" + srcDir, "out/sln"))
# Copy Solution file, with additional configurations
slnLines = iter(open("out/" + srcDir + "/all.sln"))
newSlnLines = []
for line in slnLines:
newSlnLines.append(line)
if "SolutionConfigurationPlatforms" in line:
slnConfig = slnLines.next()
for config in configs:
newSlnLines.append(slnConfig.replace("GN", config))
elif "ProjectConfigurationPlatforms" in line:
activeCfg = slnLines.next()
while "EndGlobalSection" not in activeCfg:
buildCfg = slnLines.next()
for config in configs:
newSlnLines.append(activeCfg.replace("GN", config))
newSlnLines.append(buildCfg.replace("GN", config))
activeCfg = slnLines.next()
newSlnLines.append(activeCfg)
with open("out/sln/skia.sln", "w") as newSln:
newSln.writelines(newSlnLines)
# Now bring over all project files with modification
for srcProjFilename in glob.glob("out/" + srcDir + "/obj/*.vcxproj"):
with open(srcProjFilename) as srcProjFile:
projLines = iter(srcProjFile)
newProjLines = []
for line in projLines:
if "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))
elif "<OutDir" in line:
newProjLines.append(line.replace(srcDir, "$(Configuration)"))
else:
newProjLines.append(line)
newName = "out/sln/obj/" + os.path.basename(srcProjFilename)
with open(newName, "w") as newProj:
newProj.writelines(newProjLines)