[PATCH v3 4/5] waf: add a sample run-on-target script

Uri Simchoni urisimchoni at gmail.com
Tue May 5 16:02:18 MDT 2015


This is a sample script that can be used with the --cross-execute
configure switch to run configure tests on a remote target for which
samba is being cross-compiled.

Signed-off-by: Uri Simchoni <urisimchoni at gmail.com>
---
 buildtools/examples/run_on_target.py | 74 ++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100755 buildtools/examples/run_on_target.py

diff --git a/buildtools/examples/run_on_target.py b/buildtools/examples/run_on_target.py
new file mode 100755
index 0000000..8ed1ebca
--- /dev/null
+++ b/buildtools/examples/run_on_target.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+#
+# Sample run-on-target script
+# This is a script that can be used as cross-execute parameter to samba
+# configuration process, running the command on a remote target for which
+# the cross-compiled configure test was compiled.
+#
+# To use:
+# ./configure \
+# --cross-compile --cross-execute=./buildtools/example/run_on_target.py
+#
+# Typically this is to be used also with --cross-answers, so that the
+# cross answers file gets built and further builds can be made without
+# the help of a remote target.
+#
+# The assumptions in this particular sample is that the target includes:
+# 1. rsync
+# 2. A running ssh service with password-less shell login
+# 3. A home writable for the ssh login
+#
+
+import sys
+import os
+import subprocess
+
+SSH = 'ssh'
+#
+# SSH='ssh -i <some private key>'
+#
+USER = 'me'
+HOST = 'my-nas'
+
+
+def xfer_files(ssh, host, user, srcdir):
+    cmd = 'rsync -rl --delete -e "%s" %s %s@%s:~/' % (ssh, srcdir, user, host)
+    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
+                         stderr=subprocess.PIPE)
+    (out, err) = p.communicate()
+    if p.returncode != 0:
+        raise Exception('failed syncing files\n stdout:\n%s\nstderr:%s\n'
+                        % (out, err))
+
+
+def exec_remote(ssh, host, user, targdir, prog, args):
+    cmd = '%s %s@%s ~/%s/%s' % (ssh, user, host, targdir, prog)
+    if args:
+        cmd = cmd + ' ' + ' '.join(args)
+    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
+                         stderr=subprocess.PIPE)
+    (out, err) = p.communicate()
+    return (p.returncode, out)
+
+
+def main(argv):
+    progpath = argv[1]
+
+    # assume that a test that was not compiled fails (e.g. getconf)
+    if progpath[0] != '/':
+        return (1, "")
+
+    progdir = os.path.dirname(progpath)
+    prog = os.path.basename(progpath)
+    targ_progdir = os.path.basename(progdir)
+
+    xfer_files(SSH, HOST, USER, progdir)
+    (rc, out) = exec_remote(SSH, HOST, USER, targ_progdir, prog, argv[2:])
+    return (rc, out)
+
+
+if __name__ == '__main__':
+    (rc, out) = main(sys.argv)
+    sys.stdout.write(out)
+    sys.exit(rc)
-- 
1.9.1



More information about the samba-technical mailing list