Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/update_version.rb

Parent Directory Parent Directory | Revision Log Revision Log


Revision 66 - (hide annotations) (download)
Sun May 8 09:08:24 2016 UTC (7 years, 11 months ago) by toshinagata1964
File size: 2384 byte(s)
The file 'Version' is no longer updated on Deployment build.
1 toshinagata1964 4 #!/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 toshinagata1964 66 # if date != d
18     # File.open("Version", "w") { |fp|
19     # fp.print "version = \"#{version}\"\n"
20     # fp.print "date = \"#{d}\"\n"
21     # }
22     # end
23 toshinagata1964 4 build = "build " + d
24     verstr = "v#{ver} #{build}"
25     yrange = "2000-#{year}"
26    
27     def modify_file(name, &block)
28     return if name =~ /~$/
29     ary = IO.readlines(name)
30     modified = false
31     ary.each_with_index { |s, i|
32     s = block.call(s)
33     if s
34     ary[i] = s
35     modified = true
36     end
37     }
38     if modified
39     # File.rename(name, name + "~")
40     open(name, "wb") { |fp|
41     ary.each { |s| fp.write(s) }
42     }
43     end
44     end
45    
46     # Modify Info.plist
47     nm = "Alchemusica-Info.plist"
48     version = false
49     modify_file(nm) { |s|
50     if version
51     version = false
52     "\t<string>#{ver}</string>\n"
53     else
54     version = (s =~ /\bCFBundleVersion\b/)
55     nil
56     end
57     }
58    
59     # Modify InfoPlist.strings
60     Dir["*.lproj/InfoPlist.strings"].each { |nm|
61     modify_file(nm) { |s|
62     s = s.kconv(Kconv::UTF8, Kconv::UTF16)
63     olds = s.dup
64     s.sub!(/Copyright [-0-9]+/, "Copyright #{yrange}")
65     s.sub!(/Version [.0-9a-z]+/, "Version #{ver}")
66     if olds != s
67     s = s.kconv(Kconv::UTF16, Kconv::UTF8)
68     else
69     nil
70     end
71     }
72     }
73    
74     # Modify all source files (but only the last modified year does not match year range)
75     sources = Dir["Classes/*"] + Dir["MD_package/*"] + Dir["Ruby_bindings/*"] + Dir["Ruby_Scripts/*"] + ["main.m"]
76     sources.each { |nm|
77     mtime = File::mtime(nm)
78     y = mtime.year.to_s
79     modify_file(nm) { |s|
80     news = nil
81     if s =~ /Copyright\s+(\([cC]\)\s+)?([-0-9]+)/
82     s0 = $`
83     s1 = $'
84     cmark = $1
85     years = $2
86     y1, y2 = years.split(/-/)
87     y2 ||= y1
88     if y != y2
89     years = "#{y1}-#{y}"
90     news = s0 + "Copyright #{cmark}#{years}" + s1
91     end
92     end
93     news
94     }
95     }
96    
97     # Modify doc_source.html
98     if false
99     modify_file("Documents/src/doc_source.html") { |s|
100     if s =~ /Version/ && s.sub!(/[Vv][-.0-9 A-Za-z_]*/, "Version #{ver} #{build}")
101     s
102     else
103     nil
104     end
105     }
106     end
107    
108     # Modify README
109     if false
110     modify_file("README") { |s|
111     if s =~ / Version/ && s.sub!(/[Vv][-.0-9 A-Za-z_]*/, "Version #{ver} #{build}")
112     s
113     else
114     nil
115     end
116     }
117     end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26