Update JetStream version number to 1.1.
[WebKit-https.git] / PerformanceTests / JetStream / create.rb
1 #!/usr/bin/env ruby
2
3 # Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 # 1. Redistributions of source code must retain the above copyright
9 #    notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 #    notice, this list of conditions and the following disclaimer in the
12 #    documentation and/or other materials provided with the distribution.
13 #
14 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 # THE POSSIBILITY OF SUCH DAMAGE.
25
26 require "pathname"
27 require "shellwords"
28
29 VERSION = "1.1"
30 DIRECTORY_NAME = "JetStream-#{VERSION}"
31
32 CDJS_FILES = [
33     "constants.js",
34     "util.js",
35     "red_black_tree.js",
36     "call_sign.js",
37     "vector_2d.js",
38     "vector_3d.js",
39     "motion.js",
40     "reduce_collision_set.js",
41     "simulator.js",
42     "collision.js",
43     "collision_detector.js",
44     "benchmark.js"
45 ]
46
47 raise unless system("rm -rf " + DIRECTORY_NAME)
48 raise unless system("mkdir -p " + DIRECTORY_NAME)
49 raise unless system("mkdir -p #{DIRECTORY_NAME}/sunspider")
50 raise unless system("mkdir -p #{DIRECTORY_NAME}/sources")
51 raise unless system("cp sunspider/*.js #{DIRECTORY_NAME}/sunspider")
52 raise unless system("mkdir -p #{DIRECTORY_NAME}/cdjs")
53 CDJS_FILES.each {
54     | filename |
55     raise unless system("cp cdjs/#{filename} #{DIRECTORY_NAME}/cdjs")
56 }
57 raise unless system("cp -r JetStream.css JetStreamDriver.js LLVM-test-suite-LICENSE.txt simple Octane2 Octane2Setup.js SimpleSetup.js SunSpiderSetup.js Octane OctaneSetup.js CDjsSetup.js Reference.js TestingSetup.js JetStream-Logo.png JetStream-Logo@2x.png Swoosh.png Swoosh@2x.png " + DIRECTORY_NAME)
58
59 def detemplatize(basename)
60     File.open(DIRECTORY_NAME + "/#{basename}.html", "w") {
61         | outp |
62         outp.write(IO::read("#{basename}-TEMPLATE.html").gsub(/@VERSION@/, VERSION.to_s))
63     }
64 end
65 detemplatize("index")
66 detemplatize("in-depth")
67
68 def transferSource(benchmarkName, *files)
69     files.each {
70         | filename |
71         pathname = Pathname.new(filename)
72         
73         originalBasename = pathname.basename
74         extname = originalBasename.extname
75         basename = originalBasename.basename(extname)
76         
77         if basename.to_s.start_with? benchmarkName
78             resultPathname = Pathname.new(DIRECTORY_NAME) + "sources" + "#{basename}"
79             resultName = basename.to_s
80         else
81             resultPathname = Pathname.new(DIRECTORY_NAME) + "sources" + "#{benchmarkName}-#{basename}"
82             resultName = "#{benchmarkName} / #{basename}"
83         end
84         
85         raise unless system("cp #{Shellwords.shellescape(pathname.to_s)} #{Shellwords.shellescape(resultPathname.to_s + extname)}")
86     }
87 end
88
89 File.open(DIRECTORY_NAME + "/SimplePayload.js", "w") {
90     | outp |
91     outp.puts "// THIS IS AUTO-GENERATED BY create.rb"
92     outp.puts "var SimplePayload = ["
93     directory = Pathname.new("simple")
94     Dir.foreach(directory) {
95         | filename |
96         next unless filename =~ /\.js$/
97         baseName = $~.pre_match
98         outp.puts "    {name: #{baseName.inspect}, content:#{IO::read(directory + filename).inspect}},"
99         if filename.to_s =~ /\.(cp*)\.js/
100             transferSource($~.pre_match, directory + ($~.pre_match + "." + $1), directory + filename)
101         else
102             transferSource(baseName, directory + filename)
103         end
104     }
105     outp.puts "];"
106 }
107
108 File.open(DIRECTORY_NAME + "/SunSpiderPayload.js", "w") {
109     | outp |
110     outp.puts "// THIS IS AUTO-GENERATED BY create.rb"
111     outp.puts "var SunSpiderPayload = ["
112     directory = Pathname.new("sunspider")
113     Dir.foreach(directory) {
114         | filename |
115         next unless filename =~ /\.js$/
116         baseName = $~.pre_match
117         outp.puts "    {name: #{baseName.inspect}, content:#{IO::read(directory + filename).inspect}},"
118         transferSource(baseName, directory + filename)
119     }
120     outp.puts "];"
121 }
122
123 transferSource("code-multi-load", "Octane/code-load.js")
124 transferSource("richards", "Octane2/richards.js")
125 transferSource("deltablue", "Octane2/deltablue.js")
126 transferSource("crypto", "Octane2/crypto.js")
127 transferSource("raytrace", "Octane2/raytrace.js")
128 transferSource("earley-boyer", "Octane2/earley-boyer.js")
129 transferSource("regexp", "Octane2/regexp.js")
130 transferSource("splay", "Octane2/splay.js")
131 transferSource("navier-stokes", "Octane2/navier-stokes.js")
132 transferSource("pdfjs", "Octane2/pdfjs.js")
133 transferSource("mandreel", "Octane2/mandreel.js")
134 transferSource("gbemu", "Octane2/gbemu-part1.js", "Octane2/gbemu-part2.js")
135 transferSource("code-first-load", "Octane2/code-load.js")
136 transferSource("box2d", "Octane2/box2d.js")
137 transferSource("zlib", "Octane2/zlib.js", "Octane2/zlib-data.js")
138 transferSource("typescript", "Octane2/typescript.js", "Octane2/typescript-compiler.js", "Octane2/typescript-input.js")
139 transferSource("cdjs", *(CDJS_FILES.collect { | filename | "cdjs/#{filename}" }))
140
141 puts "You can now run JetStream by navigating to file://" + (Pathname.new(DIRECTORY_NAME) + "index.html").realpath.to_s
142