bake-toolkit 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,208 @@
1
+ #!/usr/bin/env ruby
2
+ puts "Initializing..."
3
+
4
+ $:.unshift(File.dirname(__FILE__)+"/../lib")
5
+
6
+ require "securerandom"
7
+ require "vs/options"
8
+
9
+ module Cxxproject
10
+
11
+ PATH = 0
12
+ UUID = 1
13
+
14
+ def self.writeProjects(f,projects)
15
+ projects.each do |k,v|
16
+ f.puts "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" + k + "\", \"" + v[PATH] + "/" + k + ".vcxproj\", \"{" + v[UUID] + "}\""
17
+ f.puts "EndProject"
18
+ end
19
+ end
20
+
21
+ def self.writeCfg(f,projects)
22
+ projects.each do |k,v|
23
+ f.puts " {" + v[UUID] + "}.bake|Win32.ActiveCfg = bake|Win32"
24
+ f.puts " {" + v[UUID] + "}.bake|Win32.Build.0 = bake|Win32"
25
+ end
26
+ end
27
+
28
+ @options = VsOptions.new(ARGV)
29
+ @options.parse_options
30
+
31
+ version = "error"
32
+ toolset = "error"
33
+ if @options.version == "2010"
34
+ version = "11.00"
35
+ toolset = "v100"
36
+ elsif @options.version == "2012"
37
+ version = "12.00"
38
+ toolset = "v110"
39
+ end
40
+
41
+ slnFilename = @options.roots[0] + "/" + File.basename(@options.roots[0]) + ".sln"
42
+ appendProjects = (File.exist?(slnFilename) and @options.rewriteSolution)
43
+
44
+ puts "Scanning for bake projects...."
45
+
46
+ projects = {}
47
+ @options.roots.each do |r|
48
+ Dir.glob(r + "/*/Project.meta").each do |m|
49
+ projects[File.basename(File.dirname(m))] = [File.dirname(m), SecureRandom.uuid.upcase]
50
+ end
51
+ end
52
+
53
+ #if not @options.rewriteProjects
54
+ # projects.delete_if { |k,v| File.exist?(v[PATH]+"/"+k+".vcxproj") or File.exist?(v[PATH]+"/"+k+".vcxproj.filters") }
55
+ #end
56
+
57
+ @options.rewriteSolution = true unless File.exist?(slnFilename)
58
+
59
+ slnText = ""
60
+ if not @options.rewriteSolution
61
+ pattern = /Project.*[\\\/]([^\\\/]*)\.vcxproj/
62
+ slnText=File.open(slnFilename).read
63
+ slnText.gsub!(/\r\n?/, "\n")
64
+ slnText.each_line do |line|
65
+ x = line.match(pattern)
66
+ projects.delete(x[1]) if x
67
+ end
68
+ end
69
+
70
+ if projects.length == 0
71
+ puts "Nothing to do."
72
+ exit(0)
73
+ end
74
+
75
+ if not @options.rewriteSolution
76
+
77
+ puts "Adding new projects to " + slnFilename + "... "
78
+ File.open(slnFilename, 'w') do |f|
79
+
80
+ addedProjects = false
81
+ slnText.each_line do |line|
82
+ if line.include?"Project("
83
+ writeProjects(f,projects)
84
+ addedProjects = true
85
+ end
86
+
87
+ f.puts line
88
+
89
+ if line.include?"postSolution"
90
+ writeCfg(f,projects)
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+ else
97
+
98
+ puts "Rewriting " + slnFilename + "... "
99
+ File.open(slnFilename, 'w') do |f|
100
+ f.puts "Microsoft Visual Studio Solution File, Format Version " + version
101
+
102
+ writeProjects(f,projects)
103
+
104
+ f.puts "Global"
105
+ f.puts " GlobalSection(SolutionConfigurationPlatforms) = preSolution"
106
+ f.puts " bake|Win32 = bake|Win32"
107
+ f.puts " EndGlobalSection"
108
+ f.puts " GlobalSection(ProjectConfigurationPlatforms) = postSolution"
109
+
110
+ writeCfg(f,projects)
111
+
112
+ f.puts " EndGlobalSection"
113
+ f.puts " GlobalSection(SolutionProperties) = preSolution"
114
+ f.puts " HideSolutionNode = FALSE"
115
+ f.puts " EndGlobalSection"
116
+ f.puts "EndGlobal"
117
+ end
118
+
119
+ end
120
+
121
+ projects.each do |k,v|
122
+
123
+ filename = v[PATH] + "/" + k + ".vcxproj"
124
+ puts "Writing " + filename + "... "
125
+ File.open(filename, 'w') do |f|
126
+
127
+ f.puts "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
128
+ f.puts "<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"
129
+ f.puts " <ItemGroup Label=\"ProjectConfigurations\">"
130
+ f.puts " <ProjectConfiguration Include=\"bake|Win32\">"
131
+ f.puts " <Configuration>bake</Configuration>"
132
+ f.puts " <Platform>Win32</Platform>"
133
+ f.puts " </ProjectConfiguration>"
134
+ f.puts " </ItemGroup>"
135
+ f.puts " <PropertyGroup Label=\"Globals\">"
136
+ f.puts " <Keyword>MakeFileProj</Keyword>"
137
+ f.puts " <ProjectGuid>{" + v[UUID] + "}</ProjectGuid>"
138
+ f.puts " </PropertyGroup>"
139
+ f.puts " <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />"
140
+ f.puts " <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='bake|Win32'\" Label=\"Configuration\">"
141
+ f.puts " <ConfigurationType>Makefile</ConfigurationType>"
142
+ f.puts " <PlatformToolset>" + toolset + "</PlatformToolset>"
143
+ f.puts " </PropertyGroup>"
144
+ f.puts " <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />"
145
+ f.puts " <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='bake|Win32'\">"
146
+ f.puts " <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />"
147
+ f.puts " </ImportGroup>"
148
+
149
+ f.puts " <ItemGroup>"
150
+ Dir.chdir(v[PATH]) do
151
+ files = Dir.glob("**/*")
152
+ files.each do |item|
153
+ if (item[0..5] != ".bake") and not File.directory?(item)
154
+ f.puts " <None Include=\"" + item + "\" />"
155
+ end
156
+ end
157
+ end
158
+ f.puts " </ItemGroup>"
159
+
160
+ f.puts " <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />"
161
+ f.puts "</Project>"
162
+
163
+ end
164
+
165
+ filename = filename + ".filters"
166
+ puts "Writing " + filename + "... "
167
+ File.open(filename, 'w') do |f|
168
+
169
+ f.puts "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
170
+ f.puts "<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"
171
+
172
+ fileList = []
173
+ f.puts " <ItemGroup>"
174
+ Dir.chdir(v[PATH]) do
175
+ files = Dir.glob("**/*")
176
+ files.each do |item|
177
+ if (item[0..5] != ".bake")
178
+ if (File.directory? item)
179
+ f.puts " <Filter Include=\"" + item.gsub(/\//,"\\") + "\" />"
180
+ else
181
+ fileList << item
182
+ end
183
+ end
184
+ end
185
+ end
186
+ f.puts " </ItemGroup>"
187
+
188
+ f.puts " <ItemGroup>"
189
+ fileList.each do |i|
190
+ if File.dirname(i) != "."
191
+ f.puts " <None Include=\"" + i + "\">"
192
+ f.puts " <Filter>" + File.dirname(i).gsub(/\//,"\\") + "</Filter>"
193
+ f.puts " </None>"
194
+ else
195
+ f.puts " <None Include=\"" + i + "\" />"
196
+ end
197
+ end
198
+ f.puts " </ItemGroup>"
199
+
200
+ f.puts "</Project>"
201
+
202
+ end
203
+
204
+ end
205
+
206
+ puts "Finished."
207
+
208
+ end
@@ -1,7 +1,7 @@
1
1
  module Cxxproject
2
2
  class Version
3
3
  def self.bake
4
- "1.0.2"
4
+ "1.0.3"
5
5
  end
6
6
  end
7
7
 
@@ -671,13 +671,19 @@ module Cxxproject
671
671
  if not File.exists?(@startupFilename)
672
672
  Dir.chdir(startBB.project_dir) do
673
673
  theFile = Dir.glob("**/#{@startupFilename}")
674
+ theFile.map! {|tf| startBB.project_dir + "/" + tf}
674
675
  end
675
676
  if theFile.length == 0
676
677
  Printer.printError "Error: #{@startupFilename} not found in project #{@options.project}"
677
678
  ExitHelper.exit(1)
678
679
  end
679
680
  else
680
- theFile << @startupFilename
681
+ if File.is_absolute?(@startupFilename)
682
+ theFile << @startupFilename
683
+ else
684
+ theFile << startBB.project_dir + "/" + @startupFilename
685
+ end
686
+
681
687
  end
682
688
 
683
689
  exclude_files = []
@@ -692,7 +698,7 @@ module Cxxproject
692
698
 
693
699
  source_files = c.sources.dup
694
700
  c.source_patterns.each do |p|
695
- Dir.glob(p).each {|f| source_files << f}
701
+ Dir.glob(p).each {|f| source_files << (startBB.project_dir + "/" + f)}
696
702
  end
697
703
 
698
704
  theFile.delete_if { |f| source_files.all? {|e| e!=f} }
@@ -0,0 +1,67 @@
1
+ require "option/parser"
2
+
3
+ module Cxxproject
4
+
5
+ class VsOptions < Parser
6
+ attr_accessor :version, :roots, :rewriteSolution
7
+
8
+ def initialize(argv)
9
+ super(argv)
10
+
11
+ @version = "2012"
12
+ @rewriteSolution = false
13
+ @roots = []
14
+
15
+ add_option(Option.new("--version",true) { |x| set_version(x) })
16
+ add_option(Option.new("--rewrite_solution",false) { set_rewrite_solution })
17
+ add_option(Option.new("-w",true) { |x| set_root(x) })
18
+ add_option(Option.new("-h",false) { usage; ExitHelper.exit(0) })
19
+ end
20
+
21
+ def usage
22
+ puts "\nUsage: createVSProjects [options]"
23
+ puts " -w <root> Add a workspace root. Default is current directory."
24
+ puts " This Options can be used at multiple times."
25
+ puts " Solution files will be created in the first root directory."
26
+ puts " --version <year> Visual Studio version. Currently supported: 2010 and 2012 (default)."
27
+ puts " --rewrite_solution Rewrites existing solution files instead of appending new projects."
28
+ puts " -h Print this help."
29
+ end
30
+
31
+ def parse_options()
32
+ parse_internal(false)
33
+ @roots << Dir.pwd if @roots.length == 0
34
+ end
35
+
36
+ def check_valid_dir(dir)
37
+ if not File.exists?(dir)
38
+ puts "Error: Directory #{dir} does not exist"
39
+ ExitHelper.exit(1)
40
+ end
41
+ if not File.directory?(dir)
42
+ puts "Error: #{dir} is not a directory"
43
+ ExitHelper.exit(1)
44
+ end
45
+ end
46
+
47
+ def set_version(v)
48
+ if v != "2010" and v != "2012"
49
+ puts "Error: version mut be '2010' or '2012'"
50
+ end
51
+ ExitHelper.exit(1)
52
+ @version = v
53
+ end
54
+
55
+ def set_rewrite_solution
56
+ @rewriteSolution = true
57
+ end
58
+
59
+ def set_root(dir)
60
+ check_valid_dir(dir)
61
+ r = File.expand_path(dir.gsub(/[\\]/,'/'))
62
+ @roots << r if not @roots.include?r
63
+ end
64
+
65
+ end
66
+
67
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: bake-toolkit
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.2
5
+ version: 1.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alexander Schaal
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-10-07 00:00:00 Z
13
+ date: 2013-01-04 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: cxxproject
@@ -50,6 +50,7 @@ email: alexander.schaal@esrlabs.com
50
50
  executables:
51
51
  - bake
52
52
  - bakery
53
+ - createVSProjects
53
54
  extensions: []
54
55
 
55
56
  extra_rdoc_files: []
@@ -73,10 +74,12 @@ files:
73
74
  - lib/bakery/options.rb
74
75
  - lib/option/parser.rb
75
76
  - lib/tocxx.rb
77
+ - lib/vs/options.rb
76
78
  - Rakefile.rb
77
79
  - license.txt
78
80
  - bin/bake
79
81
  - bin/bakery
82
+ - bin/createVSProjects
80
83
  homepage: http://www.esrlabs.com
81
84
  licenses: []
82
85