OSDN Git Service

Ruby: AtomRef#symop can now be set from script.
[molby/Molby.git] / update_version.rb
1 #!/usr/bin/ruby
2
3 require 'kconv'
4
5 #  Get the version string
6 #  version = "X.X.X"
7 #  date = "yyyymmdd"
8 version = nil
9 date = nil
10 eval IO.read("Version")
11 ver = version
12 t = Time.now
13 year = t.year
14 month = t.month
15 day = t.day
16 d = sprintf("%04d%02d%02d", year, month, day)
17 # exit 0 if date == d
18 File.open("Version", "w") { |fp|
19   fp.print "version = \"#{version}\"\n"
20   fp.print "date = \"#{d}\"\n"
21 }
22 build = "build " + d
23 # verstr = "v#{ver} #{build}"
24 verstr = "v#{ver}"
25 yrange = (year > 2008 ? "2008-#{year}" : "2008")
26
27 def modify_file(name, &block)
28   ary = IO.readlines(name) rescue return
29   modified = false
30   ary.each_with_index { |s, i|
31     s = block.call(s)
32     if s
33       ary[i] = s
34       modified = true
35     end
36   }
37   if modified
38     File.rename(name, name + "~")
39     open(name, "wb") { |fp|
40       ary.each { |s| fp.write(s) }
41     }
42     File.delete(name + "~")
43   end
44 end
45
46 #  Modify Info.plist
47 nm = "xcode-build/Info.plist"
48 version = false
49 modify_file(nm) { |s|
50   if version
51     version = false
52     "\t<string>#{verstr}</string>\n"
53   else
54     version = (s =~ /\bCFBundleVersion\b/)
55     nil
56   end
57 }
58
59 #  Modify InfoPlist.strings
60 Dir["xcode-build/*.lproj/InfoPlist.strings"].each { |nm|
61   modify_file(nm) { |s|
62     s = s.kconv(Kconv::UTF8, Kconv::UTF16)
63     if s =~ /Copyright/ && s.sub!(/Toshi Nagata, [-0-9]+/, "Toshi Nagata, #{yrange}")
64       s = s.kconv(Kconv::UTF16, Kconv::UTF8)
65     else
66       nil
67     end
68   }
69 }
70
71 #  Modify Molby.iss
72 modify_file("msw-build/molby.iss") { |s|
73   if s =~ /AppVerName/ && s.sub!(/\(.*\)*/, "(#{verstr})")
74     s
75   else
76     nil
77   end
78 }
79
80 #  Modify MyVersion.c
81 modify_file("wxSources/MyVersion.c") { |s|
82   if s =~ /Version/ && s.sub!(/\".*\"/, "\"#{verstr}\"")
83     s
84   else
85     nil
86   end
87 }
88
89 #  Modify doc_source.html
90 modify_file("Documents/src/doc_source.html") { |s|
91   if s =~ /Version/ && s =~ /<!-- version -->/ && s.sub!(/[Vv][-.0-9 A-Za-z_]*/, "Version #{ver}")
92     s
93   elsif s =~ /<!-- copyright -->/ && s.sub!(/\d\d\d\d(-\d\d\d\d)?/, yrange)
94     s
95   else 
96     nil
97   end
98 }
99
100 #  Modify README
101 modify_file("README") { |s|
102   if s =~ /        Version/ && s.sub!(/[Vv][-.0-9 A-Za-z_]*/, "Version #{ver}")
103     s
104   elsif s =~ /       Copyright/ && s =~ /Toshi Nagata/ && s.sub!(/\d\d\d\d(-\d\d\d\d)?/, yrange)
105     s
106   else
107     nil
108   end
109 }