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 | |
Brian Osman | c20d34c | 2016-10-31 12:37:01 -0400 | [diff] [blame] | 10 | # Get list of existing directories to use as configs |
| 11 | configs = [] |
Brian Osman | 06e539a | 2016-11-18 13:38:13 -0500 | [diff] [blame] | 12 | configsWithSln = [] |
| 13 | srcDir = "" |
| 14 | newestSlnTimestamp = 0 |
Brian Osman | c20d34c | 2016-10-31 12:37:01 -0400 | [diff] [blame] | 15 | for root, dirs, files in os.walk("out"): |
| 16 | for outDir in dirs: |
Brian Osman | 06e539a | 2016-11-18 13:38:13 -0500 | [diff] [blame] | 17 | gnFile = os.path.join("out", outDir, "build.ninja.d") |
| 18 | slnFile = os.path.join("out", outDir, "all.sln") |
| 19 | if os.path.exists(gnFile): |
Brian Osman | c20d34c | 2016-10-31 12:37:01 -0400 | [diff] [blame] | 20 | configs.append(outDir) |
Brian Osman | 06e539a | 2016-11-18 13:38:13 -0500 | [diff] [blame] | 21 | if os.path.exists(slnFile): |
| 22 | configsWithSln.append(outDir) |
| 23 | slnTimestamp = os.path.getmtime(slnFile) |
| 24 | if slnTimestamp > newestSlnTimestamp: |
| 25 | newestSlnTimestamp = slnTimestamp |
| 26 | srcDir = outDir |
Brian Osman | c20d34c | 2016-10-31 12:37:01 -0400 | [diff] [blame] | 27 | break |
| 28 | |
Brian Osman | 06e539a | 2016-11-18 13:38:13 -0500 | [diff] [blame] | 29 | # We need at least one config with a solution |
| 30 | if len(configsWithSln) == 0: |
| 31 | print "ERROR: At least one GN directory must have been built with --ide=vs" |
| 32 | sys.exit() |
| 33 | |
Brian Osman | c20d34c | 2016-10-31 12:37:01 -0400 | [diff] [blame] | 34 | # Ensure directories exist |
| 35 | try: |
| 36 | os.makedirs("out/sln/obj") |
| 37 | except OSError: |
| 38 | pass |
| 39 | |
Brian Osman | c20d34c | 2016-10-31 12:37:01 -0400 | [diff] [blame] | 40 | # Copy filter files unmodified |
| 41 | for filterFile in glob.glob("out/" + srcDir + "/obj/*.filters"): |
| 42 | copyfile(filterFile, filterFile.replace("out/" + srcDir, "out/sln")) |
| 43 | |
| 44 | # Copy Solution file, with additional configurations |
| 45 | slnLines = iter(open("out/" + srcDir + "/all.sln")) |
| 46 | newSlnLines = [] |
| 47 | |
| 48 | for line in slnLines: |
| 49 | newSlnLines.append(line) |
| 50 | if "SolutionConfigurationPlatforms" in line: |
| 51 | slnConfig = slnLines.next() |
| 52 | for config in configs: |
| 53 | newSlnLines.append(slnConfig.replace("GN", config)) |
| 54 | elif "ProjectConfigurationPlatforms" in line: |
| 55 | activeCfg = slnLines.next() |
| 56 | while "EndGlobalSection" not in activeCfg: |
| 57 | buildCfg = slnLines.next() |
| 58 | for config in configs: |
| 59 | newSlnLines.append(activeCfg.replace("GN", config)) |
| 60 | newSlnLines.append(buildCfg.replace("GN", config)) |
| 61 | activeCfg = slnLines.next() |
| 62 | newSlnLines.append(activeCfg) |
| 63 | |
| 64 | with open("out/sln/skia.sln", "w") as newSln: |
| 65 | newSln.writelines(newSlnLines) |
| 66 | |
| 67 | # Now bring over all project files with modification |
| 68 | for srcProjFilename in glob.glob("out/" + srcDir + "/obj/*.vcxproj"): |
| 69 | with open(srcProjFilename) as srcProjFile: |
| 70 | projLines = iter(srcProjFile) |
| 71 | newProjLines = [] |
| 72 | for line in projLines: |
| 73 | if "ProjectConfigurations" in line: |
| 74 | newProjLines.append(line) |
| 75 | projConfigLines = [ |
| 76 | projLines.next(), |
| 77 | projLines.next(), |
| 78 | projLines.next(), |
| 79 | projLines.next() ] |
| 80 | for config in configs: |
| 81 | for projConfigLine in projConfigLines: |
| 82 | newProjLines.append( |
| 83 | projConfigLine.replace("GN", config)) |
| 84 | elif "<OutDir" in line: |
| 85 | newProjLines.append(line.replace(srcDir, "$(Configuration)")) |
| 86 | else: |
| 87 | newProjLines.append(line) |
| 88 | newName = "out/sln/obj/" + os.path.basename(srcProjFilename) |
| 89 | with open(newName, "w") as newProj: |
| 90 | newProj.writelines(newProjLines) |