[PATCH rdma-core 13/19] build/azp: Update check-build to work with python3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jason Gunthorpe <jgg@xxxxxxxxxxxx>

Remove dependencies on python2.7 so it can be removed from the container.

Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx>
---
 buildlib/azure-pipelines.yml | 10 +++++---
 buildlib/cbuild              |  7 +++--
 buildlib/check-build         | 50 +++++++++++++++++++-----------------
 3 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/buildlib/azure-pipelines.yml b/buildlib/azure-pipelines.yml
index 7df483e3329534..39188a4c0b727b 100644
--- a/buildlib/azure-pipelines.yml
+++ b/buildlib/azure-pipelines.yml
@@ -44,11 +44,13 @@ stages:
               ninja
             displayName: gcc 9.1 Compile
 
-          - bash: |
-              set -e
-              cd build-gcc9
-              python2.7 ../buildlib/check-build --src .. --cc gcc-9
+          - task: PythonScript@0
             displayName: Check Build Script
+            inputs:
+              scriptPath: buildlib/check-build
+              arguments: --src .. --cc gcc-9
+              workingDirectory: build-gcc9
+              pythonInterpreter: /usr/bin/python3
 
           # Run sparse on the subdirectories which are sparse clean
           - bash: |
diff --git a/buildlib/cbuild b/buildlib/cbuild
index 1441a91a8427fd..1de550e7bf8934 100755
--- a/buildlib/cbuild
+++ b/buildlib/cbuild
@@ -903,8 +903,11 @@ def run_azp_build(args,env):
             script.append(I["bash"]);
         elif I.get("task") == "PythonScript@0":
             script.append("set -e");
-            script.append("%s %s"%(I["inputs"]["pythonInterpreter"],
-                                   I["inputs"]["scriptPath"]));
+            if "workingDirectory" in I["inputs"]:
+                script.append("cd %s"%(os.path.join(srcdir,I["inputs"]["workingDirectory"])));
+            script.append("%s %s %s"%(I["inputs"]["pythonInterpreter"],
+                                      os.path.join(srcdir,I["inputs"]["scriptPath"]),
+                                      I["inputs"].get("arguments","")));
         else:
             raise ValueError("Unknown stanza %r"%(I));
 
diff --git a/buildlib/check-build b/buildlib/check-build
index 82812272b40b1d..acb72f0e1f2588 100755
--- a/buildlib/check-build
+++ b/buildlib/check-build
@@ -1,7 +1,8 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright 2017 Obsidian Research Corp.
 # Licensed under BSD (MIT variant) or GPLv2. See COPYING.
 """check-build - Run static checks on a build"""
+from __future__ import print_function
 import argparse
 import inspect
 import os
@@ -18,7 +19,7 @@ from distutils.version import LooseVersion;
 
 def get_src_dir():
     """Get the source directory using git"""
-    git_top = subprocess.check_output(["git","rev-parse","--git-dir"]).strip();
+    git_top = subprocess.check_output(["git","rev-parse","--git-dir"]).decode().strip();
     if git_top == ".git":
         return ".";
     return os.path.dirname(git_top);
@@ -55,7 +56,8 @@ def private_tmp():
 
 def get_symbol_vers(fn,exported=True):
     """Return the symbol version suffixes from the ELF file, eg IB_VERBS_1.0, etc"""
-    syms = subprocess.check_output(["readelf","--wide","-s",fn]);
+    syms = subprocess.check_output(["readelf","--wide","-s",fn]).decode();
+
     go = False;
     res = set();
     for I in syms.splitlines():
@@ -166,7 +168,7 @@ def check_abi(args,fn):
                            "-o",cur_fn]);
 
     if not os.path.exists(ref_fn):
-        print >> sys.stderr, "ABI file does not exist for %r"%(ref_fn);
+        print("ABI file does not exist for %r"%(ref_fn), file=sys.stderr);
         return False;
 
     subprocess.check_call(["abi-compliance-checker",
@@ -183,7 +185,7 @@ def test_verbs_uapi(args):
 
     # User must provide the ABI dir in the source tree
     if not os.path.isdir(os.path.join(args.SRC,"ABI")):
-        print "ABI check skipped, no ABI/ directory.";
+        print("ABI check skipped, no ABI/ directory.");
         return;
 
     libd = os.path.join(args.BUILD,"lib");
@@ -221,24 +223,24 @@ def get_headers(incdir):
     return includes;
 
 def compile_test_headers(tmpd,incdir,includes,with_cxx=False):
-    cppflags = subprocess.check_output(["pkg-config","libnl-3.0","--cflags-only-I"]).strip();
+    cppflags = subprocess.check_output(["pkg-config","libnl-3.0","--cflags-only-I"]).decode().strip();
     cppflags = "-I %s %s"%(incdir,cppflags)
     with open(os.path.join(tmpd,"build.ninja"),"wt") as F:
-        print >> F,"rule comp";
-        print >> F," command = %s -Werror -c %s $in -o $out"%(args.CC,cppflags);
-        print >> F," description=Header check for $in";
-        print >> F,"rule comp_cxx";
-        print >> F," command = %s -Werror -c %s $in -o $out"%(args.CXX,cppflags);
-        print >> F," description=Header C++ check for $in";
+        print("rule comp", file=F);
+        print(" command = %s -Werror -c %s $in -o $out"%(args.CC,cppflags), file=F);
+        print(" description=Header check for $in", file=F);
+        print("rule comp_cxx", file=F);
+        print(" command = %s -Werror -c %s $in -o $out"%(args.CXX,cppflags), file=F);
+        print(" description=Header C++ check for $in", file=F);
         count = 0;
         for I in sorted(includes):
             if is_obsolete(I) or is_fixup(I):
                 continue;
-            print >> F,"build %s : comp %s"%("out%d.o"%(count),I);
-            print >> F,"default %s"%("out%d.o"%(count));
-            print >> F,"build %s : comp_cxx %s"%("outxx%d.o"%(count),I);
+            print("build %s : comp %s"%("out%d.o"%(count),I), file=F);
+            print("default %s"%("out%d.o"%(count)), file=F);
+            print("build %s : comp_cxx %s"%("outxx%d.o"%(count),I), file=F);
             if with_cxx:
-                print >> F,"default %s"%("outxx%d.o"%(count));
+                print("default %s"%("outxx%d.o"%(count)), file=F);
             count = count + 1;
     subprocess.check_call(["ninja"],cwd=tmpd);
 
@@ -286,7 +288,7 @@ def test_installed_headers(args):
         subprocess.check_output(["ninja","install"],env=env,cwd=args.BUILD);
 
         includes = get_headers(tmpd);
-        incdir = os.path.commonprefix(includes);
+        incdir = os.path.commonprefix(list(includes));
         rincludes = {I[len(incdir):] for I in includes};
 
         bincdir = os.path.abspath(os.path.join(args.BUILD,"include"));
@@ -308,7 +310,7 @@ def test_installed_headers(args):
                 os.makedirs(dfn);
             assert not os.path.exists(I);
             with open(I,"w") as F:
-                print >> F,'#error "Private internal header"';
+                print('#error "Private internal header"', file=F);
 
         # Roughly check that the headers have the extern "C" for C++
         # compilation.
@@ -324,7 +326,7 @@ def test_installed_headers(args):
 
 def get_symbol_names(fn):
     """Return the defined, public, symbols from a ELF shlib"""
-    syms = subprocess.check_output(["readelf", "--wide", "-s", fn])
+    syms = subprocess.check_output(["readelf", "--wide", "-s", fn]).decode()
     go = False
     res = set()
     for I in syms.splitlines():
@@ -352,7 +354,7 @@ def get_cc_args_from_pkgconfig(args, name, static):
     flags = ["pkg-config", "--errors-to-stdout", "--cflags", "--libs"]
     if static:
         flags.append("--static")
-    opts = subprocess.check_output(flags + ["lib" + name])
+    opts = subprocess.check_output(flags + ["lib" + name]).decode()
     opts = shlex.split(opts)
 
     opts.insert(0, "-Wall")
@@ -365,7 +367,7 @@ def get_cc_args_from_pkgconfig(args, name, static):
     # The old pkg-config that travis uses incorrectly removes duplicated
     # flags, which breaks linking.
     if (name == "ibverbs" and
-        subprocess.check_output(["pkg-config", "--version"]).strip() == "0.26"):
+        subprocess.check_output(["pkg-config", "--version"]).decode().strip() == "0.26"):
         opts.insert(0, "-libverbs")
 
     # Only static link the pkg-config stuff, otherwise we get warnings about
@@ -392,7 +394,7 @@ def get_cc_args_from_pkgconfig(args, name, static):
 
 
 def compile_ninja(args, Fninja, name, cfn, opts):
-    print >> Fninja, """
+    print("""
 rule comp_{name}
     command = {CC} -Wall -o $out $in {opts}
     description = Compile and link $out
@@ -401,7 +403,7 @@ default {name}""".format(
         name=name,
         CC=args.CC,
         cfn=cfn,
-        opts=" ".join(pipes.quote(I) for I in opts))
+        opts=" ".join(pipes.quote(I) for I in opts)), file=Fninja)
 
 
 def get_providers(args):
@@ -510,6 +512,6 @@ args.SRC = os.path.abspath(args.SRC);
 args.PACKAGE_VERSION = get_package_version(args);
 
 funcs = globals();
-for k,v in funcs.items():
+for k,v in list(funcs.items()):
     if k.startswith("test_") and inspect.isfunction(v):
         v(args);
-- 
2.22.0




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux