blob: ced4718216398fc7641c29b00b9a0bdc687f32a9 [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
Brian Osmanc20d34c2016-10-31 12:37:01 -040026# Copy filter files unmodified
27for filterFile in glob.glob("out/" + srcDir + "/obj/*.filters"):
28 copyfile(filterFile, filterFile.replace("out/" + srcDir, "out/sln"))
29
30# Copy Solution file, with additional configurations
31slnLines = iter(open("out/" + srcDir + "/all.sln"))
32newSlnLines = []
33
34for line in slnLines:
35 newSlnLines.append(line)
36 if "SolutionConfigurationPlatforms" in line:
37 slnConfig = slnLines.next()
38 for config in configs:
39 newSlnLines.append(slnConfig.replace("GN", config))
40 elif "ProjectConfigurationPlatforms" in line:
41 activeCfg = slnLines.next()
42 while "EndGlobalSection" not in activeCfg:
43 buildCfg = slnLines.next()
44 for config in configs:
45 newSlnLines.append(activeCfg.replace("GN", config))
46 newSlnLines.append(buildCfg.replace("GN", config))
47 activeCfg = slnLines.next()
48 newSlnLines.append(activeCfg)
49
50with open("out/sln/skia.sln", "w") as newSln:
51 newSln.writelines(newSlnLines)
52
53# Now bring over all project files with modification
54for srcProjFilename in glob.glob("out/" + srcDir + "/obj/*.vcxproj"):
55 with open(srcProjFilename) as srcProjFile:
56 projLines = iter(srcProjFile)
57 newProjLines = []
58 for line in projLines:
59 if "ProjectConfigurations" in line:
60 newProjLines.append(line)
61 projConfigLines = [
62 projLines.next(),
63 projLines.next(),
64 projLines.next(),
65 projLines.next() ]
66 for config in configs:
67 for projConfigLine in projConfigLines:
68 newProjLines.append(
69 projConfigLine.replace("GN", config))
70 elif "<OutDir" in line:
71 newProjLines.append(line.replace(srcDir, "$(Configuration)"))
72 else:
73 newProjLines.append(line)
74 newName = "out/sln/obj/" + os.path.basename(srcProjFilename)
75 with open(newName, "w") as newProj:
76 newProj.writelines(newProjLines)