Brian Osman | c20d34c | 2016-10-31 12:37:01 -0400 | [diff] [blame] | 1 | # 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 | |
| 5 | import os |
| 6 | import glob |
| 7 | import sys |
| 8 | from shutil import copyfile |
| 9 | |
| 10 | srcDir = sys.argv[1] |
| 11 | |
| 12 | # Get list of existing directories to use as configs |
| 13 | configs = [] |
| 14 | for 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 |
| 21 | try: |
| 22 | os.makedirs("out/sln/obj") |
| 23 | except OSError: |
| 24 | pass |
| 25 | |
Brian Osman | c20d34c | 2016-10-31 12:37:01 -0400 | [diff] [blame] | 26 | # Copy filter files unmodified |
| 27 | for 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 |
| 31 | slnLines = iter(open("out/" + srcDir + "/all.sln")) |
| 32 | newSlnLines = [] |
| 33 | |
| 34 | for 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 | |
| 50 | with open("out/sln/skia.sln", "w") as newSln: |
| 51 | newSln.writelines(newSlnLines) |
| 52 | |
| 53 | # Now bring over all project files with modification |
| 54 | for 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) |