Skip to content

Commit 9851ed2

Browse files
DEFEDIT-992 Make platform independent robot commands for smoke test and use them!
1 parent 4285a8d commit 9851ed2

File tree

11 files changed

+103
-42
lines changed

11 files changed

+103
-42
lines changed

defold-robot/project.clj

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
(defproject defold-robot "0.6.0"
2-
:description "FIXME: write description"
3-
:url "https://www.defold.com"
4-
:license {:name "Eclipse Public License"
5-
:url "http://www.eclipse.org/legal/epl-v10.html"}
1+
(defproject defold-robot "0.7.0"
62
:dependencies [[org.clojure/clojure "1.10.0"]
73
[org.clojure/tools.cli "0.3.5"]
84
[commons-io/commons-io "2.4"]
95
[org.apache.ant/ant "1.10.1"]
10-
[org.openjfx/javafx-graphics "12-ea+8"]
11-
[org.openjfx/javafx-graphics "12-ea+8" :classifier "linux"]
12-
[org.openjfx/javafx-graphics "12-ea+8" :classifier "mac"]
13-
[org.openjfx/javafx-graphics "12-ea+8" :classifier "win"]
14-
[org.openjfx/javafx-swing "12-ea+8"]
15-
[org.openjfx/javafx-swing "12-ea+8" :classifier "linux"]
16-
[org.openjfx/javafx-swing "12-ea+8" :classifier "mac"]
17-
[org.openjfx/javafx-swing "12-ea+8" :classifier "win"]]
6+
[org.openjfx/javafx-graphics "12"]
7+
[org.openjfx/javafx-graphics "12" :classifier "linux"]
8+
[org.openjfx/javafx-graphics "12" :classifier "mac"]
9+
[org.openjfx/javafx-graphics "12" :classifier "win"]
10+
[org.openjfx/javafx-swing "12"]
11+
[org.openjfx/javafx-swing "12" :classifier "linux"]
12+
[org.openjfx/javafx-swing "12" :classifier "mac"]
13+
[org.openjfx/javafx-swing "12" :classifier "win"]]
1814
:resource-paths ["resources"]
1915
:main defold-robot.robot
2016
:aot [defold-robot.robot]

defold-robot/src/defold_robot/robot.clj

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,36 @@
129129
(.keyType robot (char->key-code c)))
130130
true)
131131

132-
(defmethod exec-step :switch-focus [{:keys [robot log-fn]} _]
132+
(defmethod exec-step :switch-focus [{:keys [robot log-fn platform]} _]
133133
(log-fn (format "<p>Switch-focus</p>"))
134-
;; TODO - platform specific
135-
(press robot [:command :tab])
134+
(if (= :mac platform)
135+
(press robot [:command :tab])
136+
(press robot [:alt :tab]))
137+
true)
138+
139+
(defmethod exec-step :open-asset [{:keys [robot log-fn action-key]} _]
140+
(log-fn (format "<p>Open-asset</p>"))
141+
(press robot [action-key :p])
142+
true)
143+
144+
(defmethod exec-step :build [{:keys [robot log-fn action-key]} _]
145+
(log-fn (format "<p>Build</p>"))
146+
(press robot [action-key :b])
147+
true)
148+
149+
(defmethod exec-step :hot-reload [{:keys [robot log-fn action-key]} _]
150+
(log-fn (format "<p>Hot-reload</p>"))
151+
(press robot [action-key :r])
152+
true)
153+
154+
(defmethod exec-step :undo [{:keys [robot log-fn action-key]} _]
155+
(log-fn (format "<p>Undo</p>"))
156+
(press robot [action-key :z])
157+
true)
158+
159+
(defmethod exec-step :quit [{:keys [robot log-fn action-key]} _]
160+
(log-fn (format "<p>Quit</p>"))
161+
(press robot [action-key :q])
136162
true)
137163

138164
(defmethod exec-step :default [{:keys [log-fn]} step]
@@ -171,10 +197,17 @@
171197
log-fn (fn [s]
172198
(println s)
173199
(.write log-writer (format "%s\n" s)))
200+
platform (let [name (System/getProperty "os.name")]
201+
(cond
202+
(.contains name "Mac") :mac
203+
(.contains name "Linux") :linux
204+
:else :windows))
174205
ctx {:robot robot
175206
:log-fn log-fn
176207
:log-descs log-descs
177-
:out-dir out-dir}
208+
:out-dir out-dir
209+
:platform platform
210+
:action-key (if (= :mac platform) :command :control)}
178211
result (loop [steps (get script :steps)]
179212
(if-let [s (first steps)]
180213
(if (exec-step ctx s)

editor/test/resources/geometry_wars/input/game.input_binding

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ key_trigger {
3030
input: KEY_4
3131
action: "render4"
3232
}
33+
key_trigger {
34+
input: KEY_ESC
35+
action: "quit"
36+
}
3337
mouse_trigger {
3438
input: MOUSE_BUTTON_1
3539
action: "touch"

editor/test/resources/geometry_wars/level/level.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ embedded_components {
5151
"skeleton: \"\"\n"
5252
"animations: \"\"\n"
5353
"default_animation: \"\"\n"
54-
"name: \"\"\n"
5554
""
5655
position {
5756
x: 0.0
@@ -180,7 +179,6 @@ embedded_components {
180179
"skeleton: \"\"\n"
181180
"animations: \"\"\n"
182181
"default_animation: \"\"\n"
183-
"name: \"\"\n"
184182
""
185183
position {
186184
x: 0.0
@@ -202,7 +200,6 @@ embedded_components {
202200
"skeleton: \"\"\n"
203201
"animations: \"\"\n"
204202
"default_animation: \"\"\n"
205-
"name: \"\"\n"
206203
""
207204
position {
208205
x: 0.0

editor/test/resources/geometry_wars/level/spawner.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ embedded_components {
1717
id: "black_hole_factory"
1818
type: "factory"
1919
data: "prototype: \"/enemy/black_hole.go\"\n"
20+
"load_dynamically: false\n"
2021
""
2122
position {
2223
x: 0.0
@@ -34,6 +35,7 @@ embedded_components {
3435
id: "chaser_factory"
3536
type: "factory"
3637
data: "prototype: \"/enemy/chaser.go\"\n"
38+
"load_dynamically: false\n"
3739
""
3840
position {
3941
x: 0.0
@@ -51,6 +53,7 @@ embedded_components {
5153
id: "roamer_factory"
5254
type: "factory"
5355
data: "prototype: \"/enemy/roamer.go\"\n"
56+
"load_dynamically: false\n"
5457
""
5558
position {
5659
x: 0.0
@@ -68,6 +71,7 @@ embedded_components {
6871
id: "swirler_factory"
6972
type: "factory"
7073
data: "prototype: \"/enemy/swirler.go\"\n"
74+
"load_dynamically: false\n"
7175
""
7276
position {
7377
x: 0.0

editor/test/resources/geometry_wars/main/main.script

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ local function set_render_mode(self, action_id)
1515
msg.post("@render:", action_id)
1616
end
1717

18+
local function quit(self, action_id)
19+
sys.exit(0)
20+
end
21+
1822
function init(self)
1923
math.randomseed(1)
2024
msg.post(nil, "acquire_input_focus")
@@ -25,7 +29,8 @@ function init(self)
2529
[hash("render1")] = set_render_mode,
2630
[hash("render2")] = set_render_mode,
2731
[hash("render3")] = set_render_mode,
28-
[hash("render4")] = set_render_mode
32+
[hash("render4")] = set_render_mode,
33+
[hash("quit")] = quit
2934
}
3035
self.timer = 0
3136
self.outro = false

editor/test/resources/geometry_wars/player/bullet.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ embedded_components {
6767
id: "factory"
6868
type: "factory"
6969
data: "prototype: \"/player/bullet_impact.go\"\n"
70+
"load_dynamically: false\n"
7071
""
7172
position {
7273
x: 0.0

editor/test/resources/geometry_wars/player/cannon.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ embedded_components {
1717
id: "factory"
1818
type: "factory"
1919
data: "prototype: \"/player/bullet.go\"\n"
20+
"load_dynamically: false\n"
2021
""
2122
position {
2223
x: 0.0

scripts/build.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Run build.py --help for help
1717
"""
1818

19-
PACKAGES_ALL="protobuf-2.3.0 waf-1.5.9 gtest-1.8.0 junit-4.6 protobuf-java-2.3.0 openal-1.1 maven-3.0.1 ant-1.9.3 vecmath vpx-1.7.0 facebook-4.7.0 facebook-gameroom-2017-08-14 luajit-2.0.5 tremolo-0.0.8 PVRTexLib-4.18.0 webp-0.5.0 defold-robot-0.6.0 bullet-2.77 libunwind-395b27b68c5453222378bc5fe4dab4c6db89816a".split()
19+
PACKAGES_ALL="protobuf-2.3.0 waf-1.5.9 gtest-1.8.0 junit-4.6 protobuf-java-2.3.0 openal-1.1 maven-3.0.1 ant-1.9.3 vecmath vpx-1.7.0 facebook-4.7.0 facebook-gameroom-2017-08-14 luajit-2.0.5 tremolo-0.0.8 PVRTexLib-4.18.0 webp-0.5.0 defold-robot-0.7.0 bullet-2.77 libunwind-395b27b68c5453222378bc5fe4dab4c6db89816a".split()
2020
PACKAGES_HOST="protobuf-2.3.0 gtest-1.8.0 cg-3.1 vpx-1.7.0 webp-0.5.0 luajit-2.0.5 tremolo-0.0.8".split()
2121
PACKAGES_EGGS="protobuf-2.3.0-py2.5.egg pyglet-1.1.3-py2.5.egg gdata-2.0.6-py2.6.egg Jinja2-2.6-py2.6.egg Markdown-2.6.7-py2.7.egg".split()
2222
PACKAGES_IOS="protobuf-2.3.0 gtest-1.8.0 facebook-4.7.0 luajit-2.0.5 tremolo-0.0.8 bullet-2.77".split()
@@ -1630,11 +1630,11 @@ def _download_editor2(self, sha1):
16301630
print("No editor2 bundle found for %s" % host2)
16311631
return None
16321632

1633-
def _install_editor2(self, bundle):
1633+
def _install_editor2(self, path):
16341634
host2 = get_host_platform2()
16351635
install_path = join('tmp', 'smoke_test')
16361636
if 'darwin' in host2:
1637-
out = self.exec_command(['hdiutil', 'attach', bundle])
1637+
out = self.exec_command(['hdiutil', 'attach', path])
16381638
print("cmd:" + out)
16391639
last = [l2 for l2 in (l1.strip() for l1 in out.split('\n')) if l2][-1]
16401640
words = last.split()
@@ -1649,7 +1649,10 @@ def _install_editor2(self, bundle):
16491649
'config': join(install_path, 'Contents', 'Resources', 'config')}
16501650
return result
16511651
else:
1652-
self._extract(bundle, install_path)
1652+
if 'win32' in host2:
1653+
self._extract_zip(path, install_path)
1654+
else:
1655+
self._extract(path, install_path)
16531656
install_path = join(install_path, 'Defold')
16541657
result = {'install_path': install_path,
16551658
'resources_path': 'Defold',
@@ -1678,16 +1681,22 @@ def _get_config(self, config, section, option, overrides):
16781681
return v
16791682

16801683
def smoke_test(self):
1681-
sha1 = self._git_sha1()
1684+
# TODO(mags): REMOVE BEFORE PUSH!
1685+
sha1 = '8b7b33e4147af87ffd884a5535247658fb754642' #self._git_sha1()
16821686
cwd = join('tmp', 'smoke_test')
16831687
if os.path.exists(cwd):
16841688
shutil.rmtree(cwd)
1685-
bundle = self._download_editor2(sha1)
1686-
info = self._install_editor2(bundle)
1689+
path = self._download_editor2(sha1)
1690+
info = self._install_editor2(path)
16871691
config = ConfigParser()
16881692
config.read(info['config'])
16891693
overrides = {'bootstrap.resourcespath': info['resources_path']}
1690-
java = join('Defold.app', 'Contents', 'Resources', 'packages', 'jdk11.0.1', 'bin', 'java')
1694+
jdk = 'jdk11.0.1'
1695+
host2 = get_host_platform2()
1696+
if 'win32' in host2:
1697+
java = join('Defold', 'packages', jdk, 'bin', 'java.exe')
1698+
else:
1699+
java = join('Defold.app', 'Contents', 'Resources', 'packages', jdk, 'bin', 'java')
16911700
jar = self._get_config(config, 'launcher', 'jar', overrides)
16921701
vmargs = self._get_config(config, 'launcher', 'vmargs', overrides).split(',') + ['-Ddefold.log.dir=.']
16931702
vmargs = filter(lambda x: not str.startswith(x, '-Ddefold.update.url='), vmargs)
@@ -1696,15 +1705,23 @@ def smoke_test(self):
16961705
args = [java, '-cp', jar] + vmargs + [main, '--preferences=../../editor/test/resources/smoke_test_prefs.json', game_project]
16971706
robot_jar = '%s/ext/share/java/defold-robot.jar' % self.dynamo_home
16981707
robot_args = [java, '-jar', robot_jar, '-s', '../../share/smoke-test.edn', '-o', 'result']
1708+
origdir = os.getcwd()
1709+
origcwd = cwd
1710+
if 'win32' in host2:
1711+
os.chdir(cwd)
1712+
cwd = '.'
16991713
print('Running robot: %s' % robot_args)
17001714
robot_proc = subprocess.Popen(robot_args, cwd = cwd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = False)
17011715
time.sleep(2)
17021716
self._log('Running editor: %s' % args)
1703-
ed_proc = subprocess.Popen(args, cwd = cwd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = False)
1704-
1705-
output = robot_proc.communicate()[0]
1717+
ed_proc = subprocess.Popen(args, cwd = cwd, shell = False)
1718+
os.chdir(origdir)
1719+
cwd = origcwd
1720+
# TODO(mags): REMOVE BEFORE PUSH - errput!
1721+
output, errput = robot_proc.communicate()
17061722
if ed_proc.poll() == None:
17071723
ed_proc.terminate()
1724+
ed_proc.wait()
17081725
self._uninstall_editor2(info)
17091726

17101727
result_archive_path = '/'.join(['int.d.defold.com', 'archive', sha1, 'editor2', 'smoke_test'])

0 commit comments

Comments
 (0)