2 # Copyright 2008, Google Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 base
= os
.getcwd().split(os
.path
.sep
+ "googleclient" + os
.path
.sep
).pop(0)
36 return os
.path
.join(base
, "googleclient", "native_client")
38 def GetSelLdr(target
):
39 sys_platform
= sys
.platform
.lower()
40 if sys_platform
in ("linux", "linux2"):
43 elif sys_platform
in ("win", "win32", "windows", "cygwin"):
45 sel_ldr
= "sel_ldr.exe"
46 elif sys_platform
in ("darwin", "mac"):
50 print "ERROR: Unsupported platform for nacl demo!"
53 sel_ldr
= os
.path
.join(GetBase(), "scons-out",
54 target
+ "-" + platform
, "staging", sel_ldr
)
55 if not os
.path
.exists(sel_ldr
):
60 def FindSelLdr(target
):
62 # target explicitly specified
63 sel_ldr
= GetSelLdr(target
)
65 # target not specified, so look for dbg first, then opt
66 sel_ldr
= GetSelLdr("dbg")
68 sel_ldr
= GetSelLdr("opt")
70 print "ERROR: Cannot locate sel_ldr executable"
71 print " See documentation for SCons build instructions"
76 scons_target
= os
.path
.join(GetBase(), "scons-out", "nacl", "staging", target
)
77 if os
.path
.exists(scons_target
):
79 print ("ERROR: Cannot find Native Client executable at %s" % scons_target
)
80 print (" See documentation for SCons build instructions")
84 def SubProcessCall(*command
):
86 ret_val
= os
.spawnv(os
.P_WAIT
, arglist
[0], arglist
)
90 def GetArgs(default_args
):
96 def LaunchSelLdr(demo_exe
, args
, sel_ldr_target
= None):
97 sel_ldr
= FindSelLdr(sel_ldr_target
)
98 if not sel_ldr
or not demo_exe
:
100 print "Launching sel_ldr at %s" % sel_ldr
101 print "Using executable at %s" % demo_exe
102 print "Args: %s" % repr(args
)
103 command
= [sel_ldr
, "-d", "-f", demo_exe
]
106 command
= command
+ ["--"] + args
107 ret_val
= SubProcessCall(command
)
111 if __name__
== '__main__':
112 assert len(sys
.argv
) > 1
113 nexe_name
= sys
.argv
[1]
115 sys
.exit(LaunchSelLdr(GetExe(nexe_name
), GetArgs(nexe_args
)))