-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupdate_version.rb
executable file
·51 lines (45 loc) · 1.36 KB
/
update_version.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/ruby
input_file = ARGV.shift
dir = File.dirname(input_file)
hash = ''
ref = ''
begin
ref = File.read("#{dir}/.git/HEAD").scan(/^ref: (.+)$/)[0][0].strip
ref = "#{dir}/.git/"+ref
full_hash = File.read(ref)
hash = full_hash[0..12]
rescue
end
ref = File.expand_path ref if File.exists?(ref)
if ARGV.first == '--dep'
puts ref
head = "#{dir}/.git/HEAD"
head = File.expand_path head if File.exists?(head)
puts head
exit 0
end
output_file = ARGV.shift
version = File.read(input_file).strip
lst = version.split('.', 3)
lst[2], lst[3] = lst[2].scan(/^(\d+)(.*)/)[0]
File.open(output_file, 'w') do |f|
f.puts "#ifndef VERSION_HPP"
f.puts "#define VERSION_HPP"
f.puts
f.puts "// This file is also included from app.rc, that doesn't know how to parse namespaces"
f.puts "#ifdef __cplusplus"
f.puts "namespace Shaderkit {"
f.puts " static const int MAJOR = #{lst[0]};"
f.puts " static const int MINOR = #{lst[1]};"
f.puts " static const int REVISION = #{lst[2]};"
f.puts " static const char* EXTRA = \"#{lst[3]}\";"
f.puts " static const char* HASH = \"#{hash}\";"
f.puts " static const char* STR = \"#{version}\";"
f.puts " static const char* STR_HASH = \"#{hash.empty? ? version : version+'+'+hash}\";"
f.puts "}"
f.puts "#else"
f.puts "#define SHADERKIT_VERSION \"#{version}\""
f.puts "#endif"
f.puts ""
f.puts "#endif"
end