#!/usr/bin/env ruby
$:.unshift(File.dirname(__FILE__)+"/../lib")
require "securerandom"
require "vs/options"
require 'common/version'
puts "-- bake #{Bake::Version.number}, ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}, platform #{RUBY_PLATFORM} --"
module Bake
PATH = 0
UUID = 1
def self.writeProjects(f,projects)
projects.each do |k,v|
f.puts "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" + k + "\", \"" + v[PATH] + "/" + k + ".vcxproj\", \"{" + v[UUID] + "}\""
f.puts "EndProject"
end
end
def self.writeCfg(f,projects)
projects.each do |k,v|
f.puts " {" + v[UUID] + "}.bake|Win32.ActiveCfg = bake|Win32"
f.puts " {" + v[UUID] + "}.bake|Win32.Build.0 = bake|Win32"
end
end
@options = VsOptions.new(ARGV)
@options.parse_options
version = "12.00"
toolset = "v110"
if @options.version == "2010"
version = "11.00"
toolset = "v100"
end
slnFilename = @options.roots[0] + "/" + File.basename(@options.roots[0]) + ".sln"
appendProjects = (File.exist?(slnFilename) and @options.rewriteSolution)
puts "Scanning for bake projects...."
projects = {}
@options.roots.each do |r|
Dir.glob(r + "/**/Project.meta").each do |m|
projects[File.basename(File.dirname(m))] = [File.dirname(m), SecureRandom.uuid.upcase]
end
end
#if not @options.rewriteProjects
# projects.delete_if { |k,v| File.exist?(v[PATH]+"/"+k+".vcxproj") or File.exist?(v[PATH]+"/"+k+".vcxproj.filters") }
#end
@options.rewriteSolution = true unless File.exist?(slnFilename)
slnText = ""
if not @options.rewriteSolution
pattern = /Project.*[\\\/]([^\\\/]*)\.vcxproj/
slnText=File.open(slnFilename).read
slnText.gsub!(/\r\n?/, "\n")
slnText.each_line do |line|
x = line.match(pattern)
projects.delete(x[1]) if x
end
end
if projects.length == 0
puts "Nothing to do."
exit(0)
end
if not @options.rewriteSolution
puts "Adding new projects to " + slnFilename + "... "
File.open(slnFilename, 'w') do |f|
addedProjects = false
slnText.each_line do |line|
if line.include?"Project("
writeProjects(f,projects)
addedProjects = true
end
f.puts line
if line.include?"postSolution"
writeCfg(f,projects)
end
end
end
else
puts "Rewriting " + slnFilename + "... "
File.open(slnFilename, 'w') do |f|
f.puts "Microsoft Visual Studio Solution File, Format Version " + version
writeProjects(f,projects)
f.puts "Global"
f.puts " GlobalSection(SolutionConfigurationPlatforms) = preSolution"
f.puts " bake|Win32 = bake|Win32"
f.puts " EndGlobalSection"
f.puts " GlobalSection(ProjectConfigurationPlatforms) = postSolution"
writeCfg(f,projects)
f.puts " EndGlobalSection"
f.puts " GlobalSection(SolutionProperties) = preSolution"
f.puts " HideSolutionNode = FALSE"
f.puts " EndGlobalSection"
f.puts "EndGlobal"
end
end
projects.each do |k,v|
filename = v[PATH] + "/" + k + ".vcxproj"
puts "Writing " + filename + "... "
File.open(filename, 'w') do |f|
f.puts ""
f.puts ""
f.puts " "
f.puts " "
f.puts " bake"
f.puts " Win32"
f.puts " "
f.puts " "
f.puts " "
f.puts " MakeFileProj"
f.puts " {" + v[UUID] + "}"
f.puts " "
f.puts " "
f.puts " "
f.puts " Makefile"
f.puts " " + toolset + ""
f.puts " "
f.puts " "
f.puts " $(PATH)"
f.puts " "
f.puts " "
f.puts " "
f.puts " "
f.puts " "
f.puts " "
Dir.chdir(v[PATH]) do
files = Dir.glob("**/*")
files.each do |item|
if (item[0..5] != ".bake") and not File.directory?(item)
f.puts " "
end
end
end
f.puts " "
f.puts " "
f.puts ""
end
filename = filename + ".filters"
puts "Writing " + filename + "... "
File.open(filename, 'w') do |f|
f.puts ""
f.puts ""
fileList = []
f.puts " "
Dir.chdir(v[PATH]) do
files = Dir.glob("**/*")
files.each do |item|
if (item[0..5] != ".bake")
if (File.directory? item)
f.puts " "
else
fileList << item
end
end
end
end
f.puts " "
f.puts " "
fileList.each do |i|
if File.dirname(i) != "."
f.puts " "
f.puts " " + File.dirname(i).gsub(/\//,"\\") + ""
f.puts " "
else
f.puts " "
end
end
f.puts " "
f.puts ""
end
end
puts "Finished."
end