[v1,05/24] docker: Add "cc" subcommand

Message ID 20180410193919.28026-6-alex.bennee@linaro.org
State Superseded
Headers show
Series
  • fix building of tests/tcg
Related show

Commit Message

Alex Bennée April 10, 2018, 7:39 p.m.
From: Fam Zheng <famz@redhat.com>


Signed-off-by: Fam Zheng <famz@redhat.com>

---
 tests/docker/docker.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

-- 
2.16.2

Comments

Philippe Mathieu-Daudé April 16, 2018, 1:48 a.m. | #1
On 04/10/2018 04:39 PM, Alex Bennée wrote:
> From: Fam Zheng <famz@redhat.com>

> 

> Signed-off-by: Fam Zheng <famz@redhat.com>


Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


> ---

>  tests/docker/docker.py | 23 +++++++++++++++++++++++

>  1 file changed, 23 insertions(+)

> 

> diff --git a/tests/docker/docker.py b/tests/docker/docker.py

> index 1246ba9578..8733266153 100755

> --- a/tests/docker/docker.py

> +++ b/tests/docker/docker.py

> @@ -390,6 +390,29 @@ class ImagesCommand(SubCommand):

>      def run(self, args, argv):

>          return Docker().command("images", argv, args.quiet)

>  

> +class CcCommand(SubCommand):

> +    """Compile sources with cc in images"""

> +    name = "cc"

> +

> +    def args(self, parser):

> +        parser.add_argument("--image", "-i", required=True,

> +                            help="The docker image in which to run cc")

> +        parser.add_argument("--source-path", "-s", nargs="*", dest="paths",

> +                            help="""Extra paths to (ro) mount into container for

> +                            reading sources""")

> +

> +    def run(self, args, argv):

> +        if argv and argv[0] == "--":

> +            argv = argv[1:]

> +        cwd = os.getcwd()

> +        cmd = ["--rm", "-w", cwd,

> +               "-v", "%s:%s:rw" % (cwd, cwd)]

> +        for p in args.paths:

> +           cmd += ["-v", "%s:%s:ro,z" % (p, p)]

> +        cmd += [args.image, "cc"]

> +        cmd += argv

> +        return Docker().command("run", cmd, True)

> +

>  def main():

>      parser = argparse.ArgumentParser(description="A Docker helper",

>              usage="%s <subcommand> ..." % os.path.basename(sys.argv[0]))

>

Patch

diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index 1246ba9578..8733266153 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -390,6 +390,29 @@  class ImagesCommand(SubCommand):
     def run(self, args, argv):
         return Docker().command("images", argv, args.quiet)
 
+class CcCommand(SubCommand):
+    """Compile sources with cc in images"""
+    name = "cc"
+
+    def args(self, parser):
+        parser.add_argument("--image", "-i", required=True,
+                            help="The docker image in which to run cc")
+        parser.add_argument("--source-path", "-s", nargs="*", dest="paths",
+                            help="""Extra paths to (ro) mount into container for
+                            reading sources""")
+
+    def run(self, args, argv):
+        if argv and argv[0] == "--":
+            argv = argv[1:]
+        cwd = os.getcwd()
+        cmd = ["--rm", "-w", cwd,
+               "-v", "%s:%s:rw" % (cwd, cwd)]
+        for p in args.paths:
+           cmd += ["-v", "%s:%s:ro,z" % (p, p)]
+        cmd += [args.image, "cc"]
+        cmd += argv
+        return Docker().command("run", cmd, True)
+
 def main():
     parser = argparse.ArgumentParser(description="A Docker helper",
             usage="%s <subcommand> ..." % os.path.basename(sys.argv[0]))