blob: 74305318466c3d0a13cca8de76c38e1ee9b50a3e [file] [log] [blame]
Brian Osmanc20d34c2016-10-31 12:37:01 -04001# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import os
6import glob
7import sys
8from shutil import copyfile
9
10srcDir = sys.argv[1]
11
12# Get list of existing directories to use as configs
13configs = []
14for root, dirs, files in os.walk("out"):
15 for outDir in dirs:
16 if os.path.exists("out/" + outDir + "/build.ninja.d"):
17 configs.append(outDir)
18 break
19
20# Ensure directories exist
21try:
22 os.makedirs("out/sln/obj")
23except OSError:
24 pass
25
26# Remove old files
27for root, dirs, files in os.walk("out/sln"):
28 for name in files:
29 os.remove(os.path.join(root, name))
30
31# Copy filter files unmodified
32for filterFile in glob.glob("out/" + srcDir + "/obj/*.filters"):
33 copyfile(filterFile, filterFile.replace("out/" + srcDir, "out/sln"))
34
35# Copy Solution file, with additional configurations
36slnLines = iter(open("out/" + srcDir + "/all.sln"))
37newSlnLines = []
38
39for line in slnLines:
40 newSlnLines.append(line)
41 if "SolutionConfigurationPlatforms" in line:
42 slnConfig = slnLines.next()
43 for config in configs:
44 newSlnLines.append(slnConfig.replace("GN", config))
45 elif "ProjectConfigurationPlatforms" in line:
46 activeCfg = slnLines.next()
47 while "EndGlobalSection" not in activeCfg:
48 buildCfg = slnLines.next()
49 for config in configs:
50 newSlnLines.append(activeCfg.replace("GN", config))
51 newSlnLines.append(buildCfg.replace("GN", config))
52 activeCfg = slnLines.next()
53 newSlnLines.append(activeCfg)
54
55with open("out/sln/skia.sln", "w") as newSln:
56 newSln.writelines(newSlnLines)
57
58# Now bring over all project files with modification
59for srcProjFilename in glob.glob("out/" + srcDir + "/obj/*.vcxproj"):
60 with open(srcProjFilename) as srcProjFile:
61 projLines = iter(srcProjFile)
62 newProjLines = []
63 for line in projLines:
64 if "ProjectConfigurations" in line:
65 newProjLines.append(line)
66 projConfigLines = [
67 projLines.next(),
68 projLines.next(),
69 projLines.next(),
70 projLines.next() ]
71 for config in configs:
72 for projConfigLine in projConfigLines:
73 newProjLines.append(
74 projConfigLine.replace("GN", config))
75 elif "<OutDir" in line:
76 newProjLines.append(line.replace(srcDir, "$(Configuration)"))
77 else:
78 newProjLines.append(line)
79 newName = "out/sln/obj/" + os.path.basename(srcProjFilename)
80 with open(newName, "w") as newProj:
81 newProj.writelines(newProjLines)