Debian Codegraph @

buildlib/cbuild

raw
1 #!/usr/bin/env python3
2 # Copyright 2015-2016 Obsidian Research Corp.
3 # Licensed under BSD (MIT variant) or GPLv2. See COPYING.
4 # PYTHON_ARGCOMPLETE_OK
5 """cbuild - Build in a docker container
6
7 This script helps using docker containers to run software builds. This allows
8 building for a wide range of distributions without having to install them.
9
10 Each target distribution has a base docker image and a set of packages to
11 install. The first step is to build the customized docker container:
12
13 $ buildlib/cbuild build-images fedora
14
15 This will download the base image and customize it with the required packages.
16
17 Next, a build can be performed 'in place'. This is useful to do edit/compile
18 cycles with an alternate distribution.
19
20 $ buildlib/cbuild make fedora
21
22 The build output will be placed in build-fcXX, where XX is latest fedora release.
23
24 Finally, a full package build can be performed inside the container. Note this
25 mode actually creates a source tree inside the container based on the current
26 git HEAD commit, so any uncommitted edits will be lost.
27
28 $ buildlib/cbuild pkg fedora
29
30 In this case only the final package results are copied outside the container
31 (to ..) and everything else is discarded.
32
33 In all cases the containers that are spun up are deleted after they are
34 finished, only the base container created during 'build-images' is kept. The
35 '--run-shell' option can be used to setup the container to the point of
36 running the build command and instead run an interactive bash shell. This is
37 useful for debugging certain kinds of build problems."""
38
39 from __future__ import print_function
40 import argparse
41 import collections
42 import filecmp
43 import grp
44 import inspect
45 import json
46 import multiprocessing
47 import os
48 import pwd
49 import re
50 import shutil
51 import subprocess
52 import sys
53 import tempfile
54 import yaml
55 from contextlib import contextmanager;
56
57 project = "rdma-core";
58
59 def get_version():
60 """Return the version string for the project, this gets automatically written
61 into the packaging files."""
62 with open("CMakeLists.txt","r") as F:
63 for ln in F:
64 g = re.match(r'^set\(PACKAGE_VERSION "(.+)"\)',ln)
65 if g is None:
66 continue;
67 return g.group(1);
68 raise RuntimeError("Could not find version");
69
70 class DockerFile(object):
71 def __init__(self,src):
72 self.lines = ["FROM %s"%(src)];
73
74 class Environment(object):
75 azp_images = None;
76 pandoc = True;
77 python_cmd = "python3";
78 aliases = set();
79 use_make = False;
80 proxy = True;
81 build_pyverbs = True;
82 docker_opts = []
83
84 to_azp = False;
85
86 def _get_azp_names(self):
87 if Environment.azp_images:
88 return Environment.azp_images;
89
90 with open("buildlib/azure-pipelines.yml") as F:
91 azp = yaml.safe_load(F)
92 Environment.azp_images = set(I["image"] for I in azp["resources"]["containers"])
93 return Environment.azp_images;
94
95 def image_name(self):
96 if self.to_azp:
97 # Get the version number of the container out of the azp file.
98 prefix = "ucfconsort.azurecr.io/%s/%s:"%(project, self.name);
99 for I in self._get_azp_names():
100 if I.startswith(prefix):
101 return I;
102 raise ValueError("Image is not used in buildlib/azure-pipelines.yml")
103 return "build-%s/%s"%(project,self.name);
104
105 # -------------------------------------------------------------------------
106
107 class YumEnvironment(Environment):
108 is_rpm = True;
109 def get_docker_file(self,tmpdir):
110 res = DockerFile(self.docker_parent);
111 res.lines.append("RUN yum install -y %s && yum clean all"%(
112 " ".join(sorted(self.pkgs))));
113 return res;
114
115 class centos7(YumEnvironment):
116 docker_parent = "centos:7";
117 pkgs = {
118 'cmake',
119 'gcc',
120 'libnl3-devel',
121 'libudev-devel',
122 'make',
123 'pkgconfig',
124 'python',
125 'python-argparse',
126 'python-docutils',
127 'rpm-build',
128 'systemd-devel',
129 'valgrind-devel',
130 }
131 name = "centos7";
132 use_make = True;
133 pandoc = False;
134 build_pyverbs = False;
135 specfile = "redhat/rdma-core.spec";
136 python_cmd = "python";
137 to_azp = True;
138
139 class centos7_epel(centos7):
140 pkgs = (centos7.pkgs - {"cmake","make"}) | {
141 "cmake3",
142 "ninja-build",
143 "pandoc",
144 "python34-setuptools",
145 'python34-Cython',
146 'python34-devel',
147 };
148 name = "centos7_epel";
149 build_pyverbs = True;
150 use_make = False;
151 pandoc = True;
152 ninja_cmd = "ninja-build";
153 # Our spec file does not know how to cope with cmake3
154 is_rpm = False;
155 to_azp = False;
156
157 def get_docker_file(self,tmpdir):
158 res = YumEnvironment.get_docker_file(self,tmpdir);
159 res.lines.insert(1,"RUN yum install -y epel-release");
160 res.lines.append("RUN ln -s /usr/bin/cmake3 /usr/local/bin/cmake && ln -sf /usr/bin/python3.4 /usr/bin/python3");
161 return res;
162
163 class amazonlinux2(YumEnvironment):
164 docker_parent = "amazonlinux:2";
165 pkgs = centos7.pkgs;
166 name = "amazonlinux2";
167 use_make = True;
168 pandoc = False;
169 build_pyverbs = False;
170 specfile = "redhat/rdma-core.spec";
171 python_cmd = "python";
172 to_azp = False;
173
174 class centos8(Environment):
175 docker_parent = "quay.io/centos/centos:stream8"
176 pkgs = {
177 "pandoc",
178 "perl-generators",
179 "python3-Cython",
180 "python3-devel",
181 "python3-docutils",
182 'cmake',
183 'gcc',
184 'libnl3-devel',
185 'libudev-devel',
186 'ninja-build',
187 'pkgconfig',
188 'rpm-build',
189 'systemd-devel',
190 'valgrind-devel',
191 };
192 name = "centos8";
193 specfile = "redhat/rdma-core.spec";
194 is_rpm = True;
195 to_azp = True;
196 proxy = False;
197
198 def get_docker_file(self,tmpdir):
199 res = DockerFile(self.docker_parent);
200 res.lines.append("RUN dnf config-manager --set-enabled powertools && "
201 "dnf install -y %s && dnf clean all" %
202 (" ".join(sorted(self.pkgs))))
203 return res;
204
205 class centos9(Environment):
206 docker_parent = "quay.io/centos/centos:stream9"
207 pkgs = centos8.pkgs
208 name = "centos9"
209 specfile = "redhat/rdma-core.spec"
210 ninja_cmd = "ninja-build"
211 is_rpm = True
212 to_azp = True
213 proxy = False
214
215 def get_docker_file(self,tmpdir):
216 res = DockerFile(self.docker_parent);
217 res.lines.append("RUN dnf install -y 'dnf-command(config-manager)' epel-release &&"
218 "dnf config-manager --set-enabled crb && "
219 "dnf install -y %s && dnf clean all" %
220 (" ".join(sorted(self.pkgs))))
221 return res
222
223 class fc44(Environment):
224 docker_parent = "fedora:44";
225 pkgs = centos8.pkgs | {"util-linux"}
226 name = "fc44";
227 specfile = "redhat/rdma-core.spec";
228 ninja_cmd = "ninja-build";
229 is_rpm = True;
230 aliases = {"fedora"};
231 to_azp = True;
232
233 def get_docker_file(self,tmpdir):
234 res = DockerFile(self.docker_parent);
235 res.lines.append("RUN dnf install -y %s && dnf clean all"%(
236 " ".join(sorted(self.pkgs))));
237 return res;
238
239 # -------------------------------------------------------------------------
240
241 class APTEnvironment(Environment):
242 is_deb = True;
243 build_python = True;
244 def get_docker_file(self,tmpdir):
245 res = DockerFile(self.docker_parent);
246 res.lines.append("RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends %s && apt-get clean && rm -rf /usr/share/doc/ /usr/lib/debug /var/lib/apt/lists/"%(
247 " ".join(sorted(self.pkgs))));
248 return res;
249
250 def add_source_list(self,tmpdir,name,content):
251 sld = os.path.join(tmpdir,"etc","apt","sources.list.d");
252 if not os.path.isdir(sld):
253 os.makedirs(sld);
254 with open(os.path.join(sld,name),"w") as F:
255 F.write(content + "\n");
256
257 def fix_https(self,tmpdir):
258 """The ubuntu image does not include ca-certificates, so if we want to use
259 HTTPS disable certificate validation."""
260 cfgd = os.path.join(tmpdir,"etc","apt","apt.conf.d")
261 if not os.path.isdir(cfgd):
262 os.makedirs(cfgd)
263 with open(os.path.join(cfgd,"01nossl"),"w") as F:
264 F.write('Acquire::https { Verify-Peer "false"; };')
265
266 class xenial(APTEnvironment):
267 docker_parent = "ubuntu:16.04"
268 pkgs = {
269 'build-essential',
270 'cmake',
271 'debhelper',
272 'dh-systemd',
273 'fakeroot', # for AZP
274 'gcc',
275 'libnl-3-dev',
276 'libnl-route-3-dev',
277 'libsystemd-dev',
278 'libudev-dev',
279 'make',
280 'ninja-build',
281 'pandoc',
282 'pkg-config',
283 'python3',
284 'python3-docutils',
285 'valgrind',
286 };
287 name = "ubuntu-16.04";
288 aliases = {"xenial"};
289 to_azp = True;
290
291 class bionic(APTEnvironment):
292 docker_parent = "ubuntu:18.04"
293 pkgs = xenial.pkgs | {
294 'cython3',
295 'python3-dev',
296 };
297 name = "ubuntu-18.04";
298 aliases = {"bionic", "ubuntu"};
299 to_azp = True
300
301 class focal(APTEnvironment):
302 docker_parent = "ubuntu:20.04"
303 pkgs = bionic.pkgs | {
304 'dh-python',
305 }
306 name = "ubuntu-20.04";
307 aliases = {"focal", "ubuntu"};
308 to_azp = True
309
310 class jammy(APTEnvironment):
311 docker_parent = "ubuntu:22.04"
312 pkgs = (bionic.pkgs ^ {"dh-systemd"}) | {
313 'dh-python',
314 }
315 name = "ubuntu-22.04";
316 aliases = {"jammy", "ubuntu"};
317
318 class jessie(APTEnvironment):
319 docker_parent = "debian:8"
320 pkgs = xenial.pkgs;
321 name = "debian-8";
322 aliases = {"jessie"};
323 build_pyverbs = False;
324
325 class stretch(APTEnvironment):
326 docker_parent = "debian:9"
327 pkgs = bionic.pkgs;
328 name = "debian-9";
329 aliases = {"stretch"};
330
331 class bullseye(APTEnvironment):
332 docker_parent = "debian:11"
333 pkgs = {
334 'build-essential',
335 'cmake',
336 'debhelper',
337 'fakeroot', # for AZP
338 'gcc',
339 'libnl-3-dev',
340 'libnl-route-3-dev',
341 'libsystemd-dev',
342 'libudev-dev',
343 'make',
344 'ninja-build',
345 'pandoc',
346 'pkg-config',
347 'python3',
348 'python3-docutils',
349 'valgrind',
350 };
351 name = "debian-11";
352 aliases = {"bullseye"};
353
354 class bullseye_i386(APTEnvironment):
355 docker_parent = "debian:11"
356 pkgs = bullseye.pkgs | {"nodejs"}
357 name = "debian-11-i386";
358 aliases = {"bullseye_i386"};
359 docker_opts = ["--platform","linux/386"]
360 to_azp = True
361
362 def get_docker_file(self,tmpdir):
363 res = json.loads(docker_cmd_str(args,"manifest","inspect",self.docker_parent))
364
365 # Docker is somewhat obnoxious in how it handles the multi-platform
366 # images since it does not store the manifest locally and thus
367 # overwrites the local tag. Figure out the tag we want by hash and
368 # use it directly. Docker will cache this.
369 for image in res["manifests"]:
370 platform = image["platform"]
371 if platform["architecture"] == "386" and platform["os"] == "linux":
372 base = f"{self.docker_parent}@{image['digest']}"
373 break
374 else:
375 raise RuntimeError("Docker manifest failed");
376 res = DockerFile(base);
377 res.lines.append("RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends %s && apt-get clean && rm -rf /usr/share/doc/ /usr/lib/debug /var/lib/apt/lists/"%(
378 " ".join(sorted(self.pkgs))));
379 res.lines.append('LABEL "com.azure.dev.pipelines.agent.handler.node.path"="/usr/bin/node"')
380 return res;
381
382 class debian_experimental(APTEnvironment):
383 docker_parent = "debian:experimental"
384 pkgs = (stretch.pkgs ^ {"gcc"}) | {"gcc-9"};
385 name = "debian-experimental";
386
387 def get_docker_file(self,tmpdir):
388 res = DockerFile(self.docker_parent);
389 res.lines.append("RUN apt-get update && apt-get -t experimental install -y --no-install-recommends %s && apt-get clean"%(
390 " ".join(sorted(self.pkgs))));
391 return res;
392
393 # -------------------------------------------------------------------------
394
395 class ZypperEnvironment(Environment):
396 proxy = False;
397 is_rpm = True;
398 def get_docker_file(self,tmpdir):
399 res = DockerFile(self.docker_parent);
400 res.lines.append("RUN zypper --non-interactive refresh");
401 res.lines.append("RUN zypper --non-interactive dist-upgrade");
402 res.lines.append("RUN zypper --non-interactive install %s"%(
403 " ".join(sorted(self.pkgs))));
404 return res;
405
406 class leap(ZypperEnvironment):
407 docker_parent = "opensuse/leap:15.0";
408 specfile = "suse/rdma-core.spec";
409 pkgs = {
410 'cmake',
411 'gcc',
412 'libnl3-devel',
413 'libudev-devel',
414 'udev',
415 'make',
416 'ninja',
417 'pandoc',
418 'pkg-config',
419 'python3',
420 'rpm-build',
421 'systemd-devel',
422 'valgrind-devel',
423 'python3-Cython',
424 'python3-devel',
425 'python3-docutils',
426 };
427 rpmbuild_options = [ "--without=curlmini" ];
428 to_azp = True;
429 name = "opensuse-15.0";
430 aliases = {"leap"};
431
432 class tumbleweed(ZypperEnvironment):
433 docker_parent = "opensuse/tumbleweed:latest";
434 pkgs = (leap.pkgs ^ {"valgrind-devel"}) | {
435 "valgrind-client-headers",
436 "perl"
437 };
438 name = "tumbleweed";
439 specfile = "suse/rdma-core.spec";
440 rpmbuild_options = [ "--without=curlmini" ];
441
442 # -------------------------------------------------------------------------
443
444 class azure_pipelines(APTEnvironment):
445 docker_parent = "ubuntu:22.04"
446 pkgs = {
447 "abi-compliance-checker",
448 "abi-dumper",
449 "ca-certificates",
450 "clang-15",
451 "cmake",
452 "cython3",
453 "debhelper",
454 "dh-python",
455 "dpkg-dev",
456 "fakeroot",
457 "gcc-12",
458 "git",
459 "libc6-dev",
460 "libnl-3-dev",
461 "libnl-route-3-dev",
462 "libsystemd-dev",
463 "libudev-dev",
464 "lintian",
465 "make",
466 "ninja-build",
467 "pandoc",
468 "pkg-config",
469 "python3",
470 "python3-dev",
471 "python3-docutils",
472 "python3-pkg-resources",
473 "python3-yaml",
474 "sparse",
475 "valgrind",
476 } | {
477 # ARM 64 cross compiler
478 "gcc-12-aarch64-linux-gnu",
479 "libgcc-12-dev:arm64",
480 "libc6-dev:arm64",
481 "libnl-3-dev:arm64",
482 "libnl-route-3-dev:arm64",
483 "libsystemd-dev:arm64",
484 "libudev-dev:arm64",
485 } | {
486 # PPC 64 cross compiler
487 "gcc-12-powerpc64le-linux-gnu",
488 "libgcc-12-dev:ppc64el",
489 "libc6-dev:ppc64el",
490 "libnl-3-dev:ppc64el",
491 "libnl-route-3-dev:ppc64el",
492 "libsystemd-dev:ppc64el",
493 "libudev-dev:ppc64el",
494 }
495 to_azp = True;
496 name = "azure_pipelines";
497 aliases = {"azp"}
498
499 llvm_sources = """
500 Types: deb
501 URIs: http://apt.llvm.org/jammy/
502 Suites: llvm-toolchain-jammy-15
503 Components: main
504 Architectures: amd64
505 Signed-By:
506 -----BEGIN PGP PUBLIC KEY BLOCK-----
507 Version: GnuPG v1.4.12 (GNU/Linux)
508 .
509 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
555 bXb5c6gCHESH5PXwPU4jQEE7Ib9J6sbk7ZT2Mw==
556 =j+4q
557 -----END PGP PUBLIC KEY BLOCK-----
558 """
559
560 gcc12_sources = """
561 Types: deb
562 URIs: https://ppa.launchpadcontent.net/ubuntu-toolchain-r/test/ubuntu
563 Suites: jammy
564 Components: main
565 Architectures: amd64 arm64 ppc64el
566 Signed-By:
567 -----BEGIN PGP PUBLIC KEY BLOCK-----
568 .
569 xo0ESuBvRwEEAMi4cDba7xlKaaoXjO1n1HX8RKrkW+HEIl79nSOSJyvzysajs7zU
570 ow/OzCQp9NswqrDmNuH1+lPTTRNAGtK8r2ouq2rnXT1mTl23dpgHZ9spseR73s4Z
571 BGw/ag4bpU5dNUStvfmHhIjVCuiSpNn7cyy1JSSvSs3N2mxteKjXLBf7ABEBAAHN
572 GkxhdW5jaHBhZCBUb29sY2hhaW4gYnVpbGRzwrYEEwECACAFAkrgb0cCGwMGCwkI
573 BwMCBBUCCAMEFgIDAQIeAQIXgAAKCRAek3eiup7yfzGKA/4xzUqNACSlB+k+DxFF
574 HqkwKa/ziFiAlkLQyyhm+iqz80htRZr7Ls/ZRYZl0aSU56/hLe0V+TviJ1s8qdN2
575 lamkKdXIAFfavA04nOnTzyIBJ82EAUT3Nh45skMxo4z4iZMNmsyaQpNl/m/lNtOL
576 hR64v5ZybofB2EWkMxUzX8D/FQ==
577 =xe+/
578 -----END PGP PUBLIC KEY BLOCK-----
579 """
580
581 ports_sources = """
582 Types: deb
583 URIS: http://ports.ubuntu.com
584 Suites: jammy jammy-security jammy-updates
585 Components: main universe
586 Architectures: arm64 ppc64el
587 """
588
589 amd64_sources = """
590 Types: deb
591 URIS: http://archive.ubuntu.com/ubuntu
592 Suites: jammy jammy-security jammy-updates
593 Components: main universe
594 Architectures: amd64
595 """
596
597 def get_docker_file(self,tmpdir):
598 res = focal.get_docker_file(self,tmpdir);
599 self.fix_https(tmpdir)
600
601 self.add_source_list(tmpdir, "llvm.sources", self.llvm_sources)
602 self.add_source_list(tmpdir,
603 "ubuntu-toolchain-r-ubuntu-test-jammy.sources",
604 self.gcc12_sources)
605 self.add_source_list(tmpdir, "ports.sources", self.ports_sources)
606
607 # Replace the main sources so we can limit the architecture
608 self.add_source_list(tmpdir, "amd64.sources", self.amd64_sources)
609
610 res.lines.insert(1,"ADD etc/ /etc/");
611 res.lines.insert(1,"RUN rm /etc/apt/sources.list && "
612 "dpkg --add-architecture ppc64el && "
613 "dpkg --add-architecture arm64")
614 return res;
615
616 # -------------------------------------------------------------------------
617
618 environments = [centos7(),
619 centos7_epel(),
620 centos8(),
621 centos9(),
622 amazonlinux2(),
623 xenial(),
624 bionic(),
625 focal(),
626 jammy(),
627 jessie(),
628 stretch(),
629 fc44(),
630 leap(),
631 tumbleweed(),
632 debian_experimental(),
633 azure_pipelines(),
634 bullseye(),
635 bullseye_i386(),
636 ];
637
638 class ToEnvActionPkg(argparse.Action):
639 """argparse helper to parse environment lists into environment classes"""
640 def __call__(self, parser, namespace, values, option_string=None):
641 if not isinstance(values,list):
642 values = [values];
643
644 res = set();
645 for I in values:
646 if I == "all":
647 for env in environments:
648 if env.name != "centos7_epel":
649 res.add(env);
650 else:
651 for env in environments:
652 if env.name == I or I in env.aliases:
653 res.add(env);
654 setattr(namespace, self.dest, sorted(res,key=lambda x:x.name))
655
656
657 class ToEnvAction(argparse.Action):
658 """argparse helper to parse environment lists into environment classes"""
659 def __call__(self, parser, namespace, values, option_string=None):
660 if not isinstance(values,list):
661 values = [values];
662
663 res = set();
664 for I in values:
665 if I == "all":
666 res.update(environments);
667 else:
668 for env in environments:
669 if env.name == I or I in env.aliases:
670 res.add(env);
671 setattr(namespace, self.dest, sorted(res,key=lambda x:x.name))
672
673 def env_choices_pkg():
674 """All the names that can be used with ToEnvAction"""
675 envs = set(("all",));
676 for I in environments:
677 if getattr(I,"is_deb",False) or getattr(I,"is_rpm",False):
678 envs.add(I.name);
679 envs.update(I.aliases);
680 return envs;
681
682 def env_choices():
683 """All the names that can be used with ToEnvAction"""
684 envs = set(("all",));
685 for I in environments:
686 envs.add(I.name);
687 envs.update(I.aliases);
688 return envs;
689
690 def docker_cmd(env,*cmd):
691 """Invoke docker"""
692 cmd = list(cmd);
693 if env.sudo:
694 return subprocess.check_call(["sudo","docker"] + cmd);
695 return subprocess.check_call(["docker"] + cmd);
696
697 def docker_cmd_str(env,*cmd):
698 """Invoke docker"""
699 cmd = list(cmd);
700 if env.sudo:
701 return subprocess.check_output(["sudo","docker"] + cmd).decode();
702 return subprocess.check_output(["docker"] + cmd).decode();
703
704 @contextmanager
705 def private_tmp(args):
706 """Simple version of Python 3's tempfile.TemporaryDirectory"""
707 dfn = tempfile.mkdtemp();
708 try:
709 yield dfn;
710 finally:
711 try:
712 shutil.rmtree(dfn);
713 except:
714 # The debian builds result in root owned files because we don't use fakeroot
715 subprocess.check_call(['sudo','rm','-rf',dfn]);
716
717 @contextmanager
718 def inDirectory(dir):
719 cdir = os.getcwd();
720 try:
721 os.chdir(dir);
722 yield True;
723 finally:
724 os.chdir(cdir);
725
726 def map_git_args(src_root,to):
727 """Return a list of docker arguments that will map the .git directory into the
728 container"""
729 git_dir = subprocess.check_output([
730 "git",
731 "-C", src_root,
732 "rev-parse",
733 "--absolute-git-dir",
734 ]).decode().strip()
735 if ".git/worktrees" in git_dir:
736 with open(os.path.join(git_dir, "commondir")) as F:
737 git_dir = os.path.join(git_dir, F.read().strip())
738 git_dir = os.path.abspath(git_dir)
739 res = ["-v", "%s:%s:ro" % (os.path.join(src_root, ".git"), os.path.join(to, ".git")),
740 "-v", "%s:%s:ro" % (git_dir, git_dir)]
741 else:
742 res = ["-v", "%s:%s:ro" % (git_dir, os.path.join(to, ".git"))]
743
744 alternates = os.path.join(git_dir, "objects/info/alternates")
745 if os.path.exists(alternates):
746 with open(alternates) as F:
747 for I in F.readlines():
748 I = os.path.normpath(I.strip())
749 res.extend(["-v","%s:%s:ro"%(I,I)]);
750
751 return res;
752
753 def get_image_id(args,image_name):
754 img = json.loads(docker_cmd_str(args,"inspect",image_name));
755 image_id = img[0]["Id"];
756 # Newer dockers put a prefix
757 if ":" in image_id:
758 image_id = image_id.partition(':')[2];
759 return image_id;
760
761 # -------------------------------------------------------------------------
762
763 def get_tar_file(args,tarfn,pandoc_prebuilt=False):
764 """Create a tar file that matches what buildlib/github-release would do if it
765 was a tagged release"""
766 prefix = "%s-%s/"%(project,get_version());
767 if not pandoc_prebuilt:
768 subprocess.check_call(["git","archive",
769 # This must match the prefix generated buildlib/github-release
770 "--prefix",prefix,
771 "--output",tarfn,
772 "HEAD"]);
773 return;
774
775 # When the OS does not support pandoc we got through the extra step to
776 # build pandoc output in the azp container and include it in the
777 # tar.
778 if not args.use_prebuilt_pandoc:
779 subprocess.check_call(["buildlib/cbuild","make","azure_pipelines","docs"]);
780
781 cmd_make_dist_tar(argparse.Namespace(BUILD="build-azure_pipelines",tarfn=tarfn,
782 script_pwd="",tag=None));
783
784 def run_rpm_build(args,spec_file,env):
785 with open(spec_file,"r") as F:
786 for ln in F:
787 if ln.startswith("Version:"):
788 ver = ln.strip().partition(' ')[2].strip();
789 assert(ver == get_version());
790
791 if ln.startswith("Source:"):
792 tarfn = ln.strip().partition(' ')[2].strip();
793
794 image_id = get_image_id(args,env.image_name());
795 with private_tmp(args) as tmpdir:
796 os.mkdir(os.path.join(tmpdir,"SOURCES"));
797 os.mkdir(os.path.join(tmpdir,"tmp"));
798
799 get_tar_file(args,os.path.join(tmpdir,"SOURCES",tarfn),
800 pandoc_prebuilt=not env.pandoc);
801
802 with open(spec_file,"r") as inF:
803 spec = list(inF);
804 tspec_file = os.path.basename(spec_file);
805 with open(os.path.join(tmpdir,tspec_file),"w") as outF:
806 outF.write("".join(spec));
807
808 home = os.path.join(os.path.sep,"home",os.getenv("LOGNAME"));
809 vdir = os.path.join(home,"rpmbuild");
810
811 opts = [
812 "run",
813 "--rm=true",
814 "-v","%s:%s"%(tmpdir,vdir),
815 "-w",vdir,
816 "-h","builder-%s"%(image_id[:12]),
817 "-e","HOME=%s"%(home),
818 "-e","TMPDIR=%s"%(os.path.join(vdir,"tmp")),
819 ];
820
821 # rpmbuild complains if we do not have an entry in passwd and group
822 # for the user we are going to use to do the build.
823 with open(os.path.join(tmpdir,"go.py"),"w") as F:
824 print("""
825 import os,subprocess;
826 with open("/etc/passwd","a") as F:
827 F.write({passwd!r} + "\\n");
828 with open("/etc/group","a") as F:
829 F.write({group!r} + "\\n");
830 os.setgid({gid:d});
831 os.setuid({uid:d});
832
833 # Get RPM to tell us the expected tar filename.
834 for ln in subprocess.check_output(["rpmspec","-P",{tspec_file!r}]).splitlines():
835 if ln.startswith(b"Source:"):
836 tarfn = ln.strip().partition(b' ')[2].strip();
837 if tarfn != {tarfn!r}:
838 os.symlink({tarfn!r},os.path.join(b"SOURCES",tarfn));
839 """.format(passwd=":".join(str(I) for I in pwd.getpwuid(os.getuid())),
840 group=":".join(str(I) for I in grp.getgrgid(os.getgid())),
841 uid=os.getuid(),
842 gid=os.getgid(),
843 tarfn=tarfn,
844 tspec_file=tspec_file), file=F);
845
846 extra_opts = getattr(env,"rpmbuild_options", [])
847 bopts = ["-bb",tspec_file] + extra_opts;
848 for arg in args.with_flags:
849 bopts.extend(["--with", arg]);
850 for arg in args.without_flags:
851 bopts.extend(["--without", arg]);
852 if "pyverbs" not in args.with_flags + args.without_flags:
853 if env.build_pyverbs:
854 bopts.extend(["--with", "pyverbs"]);
855
856 print('os.execlp("rpmbuild","rpmbuild",%s)'%(
857 ",".join(repr(I) for I in bopts)), file=F);
858
859 if args.run_shell:
860 opts.append("-ti");
861 opts.append(env.image_name());
862
863 if args.run_shell:
864 opts.append("/bin/bash");
865 else:
866 opts.extend([env.python_cmd,"go.py"]);
867
868 docker_cmd(args,*opts)
869
870 print()
871 for path,jnk,files in os.walk(os.path.join(tmpdir,"RPMS")):
872 for I in files:
873 print("Final RPM: ",os.path.join("..",I));
874 shutil.move(os.path.join(path,I),
875 os.path.join("..",I));
876
877 def run_deb_build(args,env):
878 image_id = get_image_id(args,env.image_name());
879 with private_tmp(args) as tmpdir:
880 os.mkdir(os.path.join(tmpdir,"src"));
881 os.mkdir(os.path.join(tmpdir,"tmp"));
882
883 opwd = os.getcwd();
884 with inDirectory(os.path.join(tmpdir,"src")):
885 subprocess.check_call(["git",
886 "--git-dir",os.path.join(opwd,".git"),
887 "reset","--hard","HEAD"]);
888
889 home = os.path.join(os.path.sep,"home",os.getenv("LOGNAME"));
890
891 opts = [
892 "run",
893 "--read-only",
894 "--rm=true",
895 "-v","%s:%s"%(tmpdir,home),
896 "-w",os.path.join(home,"src"),
897 "-h","builder-%s"%(image_id[:12]),
898 "-e","HOME=%s"%(home),
899 "-e","TMPDIR=%s"%(os.path.join(home,"tmp")),
900 "-e","DEB_BUILD_OPTIONS=parallel=%u"%(multiprocessing.cpu_count()),
901 ];
902
903 # Create a go.py that will let us run the compilation as the user and
904 # then switch to root only for the packaging step.
905 with open(os.path.join(tmpdir,"go.py"),"w") as F:
906 print("""
907 import subprocess,os;
908 def to_user():
909 os.setgid({gid:d});
910 os.setuid({uid:d});
911 subprocess.check_call(["debian/rules","debian/rules","build"],
912 preexec_fn=to_user);
913 subprocess.check_call(["debian/rules","debian/rules","binary"]);
914 """.format(uid=os.getuid(),
915 gid=os.getgid()), file=F);
916
917 if args.run_shell:
918 opts.append("-ti");
919 opts.append(env.image_name());
920
921 if args.run_shell:
922 opts.append("/bin/bash");
923 else:
924 opts.extend(["python3",os.path.join(home,"go.py")]);
925
926 docker_cmd(args,*opts);
927
928 print()
929 for I in os.listdir(tmpdir):
930 if I.endswith(".deb"):
931 print("Final DEB: ",os.path.join("..",I));
932 shutil.move(os.path.join(tmpdir,I),
933 os.path.join("..",I));
934
935 def copy_abi_files(src):
936 """Retrieve the current ABI files and place them in the source tree."""
937 if not os.path.isdir(src):
938 return;
939
940 for path,jnk,files in os.walk(src):
941 for I in files:
942 if not I.startswith("current-"):
943 continue;
944
945 ref_fn = os.path.join("ABI",I[8:]);
946 cur_fn = os.path.join(src, path, I);
947
948 if os.path.isfile(ref_fn) and filecmp.cmp(ref_fn,cur_fn,False):
949 continue;
950
951 print("Changed ABI File: ", ref_fn);
952 shutil.copy(cur_fn, ref_fn);
953
954 def run_azp_build(args,env):
955 # Load the commands from the pipelines file
956 with open("buildlib/azure-pipelines.yml") as F:
957 azp = yaml.safe_load(F);
958 for bst in azp["stages"]:
959 if bst["stage"] == "Build":
960 break;
961 else:
962 raise ValueError("No Build stage found");
963 for job in bst["jobs"]:
964 if job["job"] == "Compile":
965 break;
966 else:
967 raise ValueError("No Compile job found");
968
969 script = ["#!/bin/bash"]
970 workdir = "/__w/1"
971 srcdir = os.path.join(workdir,"s");
972 for I in job["steps"]:
973 script.append("echo ===================================");
974 script.append("echo %s"%(I["displayName"]));
975 script.append("cd %s"%(srcdir));
976 if "bash" in I:
977 script.append(I["bash"]);
978 elif I.get("task") == "PythonScript@0":
979 script.append("set -e");
980 if "workingDirectory" in I["inputs"]:
981 script.append("cd %s"%(os.path.join(srcdir,I["inputs"]["workingDirectory"])));
982 script.append("%s %s %s"%(I["inputs"]["pythonInterpreter"],
983 os.path.join(srcdir,I["inputs"]["scriptPath"]),
984 I["inputs"].get("arguments","")));
985 else:
986 raise ValueError("Unknown stanza %r"%(I));
987
988 with private_tmp(args) as tmpdir:
989 os.mkdir(os.path.join(tmpdir,"s"));
990 os.mkdir(os.path.join(tmpdir,"tmp"));
991
992 opwd = os.getcwd();
993 with inDirectory(os.path.join(tmpdir,"s")):
994 subprocess.check_call(["git",
995 "--git-dir",os.path.join(opwd,".git"),
996 "reset","--hard","HEAD"]);
997 subprocess.check_call(["git",
998 "--git-dir",os.path.join(opwd,".git"),
999 "fetch",
1000 "--no-tags",
1001 "https://github.com/linux-rdma/rdma-core.git","HEAD",
1002 "master"]);
1003 base = subprocess.check_output(["git",
1004 "--git-dir",os.path.join(opwd,".git"),
1005 "merge-base",
1006 "HEAD","FETCH_HEAD"]).decode().strip();
1007
1008 opts = [
1009 "run",
1010 "--read-only",
1011 "--rm=true",
1012 "-v","%s:%s"%(tmpdir, workdir),
1013 "-w",srcdir,
1014 "-u",str(os.getuid()),
1015 "-e","SYSTEM_PULLREQUEST_SOURCECOMMITID=HEAD",
1016 # azp puts the branch name 'master' here, we need to put a commit ID..
1017 "-e","SYSTEM_PULLREQUEST_TARGETBRANCH=%s"%(base),
1018 "-e","HOME=%s"%(workdir),
1019 "-e","TMPDIR=%s"%(os.path.join(workdir,"tmp")),
1020 ] + map_git_args(opwd,srcdir);
1021
1022 if args.run_shell:
1023 opts.append("-ti");
1024 opts.append(env.image_name());
1025
1026 with open(os.path.join(tmpdir,"go.sh"),"w") as F:
1027 F.write("\n".join(script))
1028
1029 if args.run_shell:
1030 opts.append("/bin/bash");
1031 else:
1032 opts.extend(["/bin/bash",os.path.join(workdir,"go.sh")]);
1033
1034 try:
1035 docker_cmd(args,*opts);
1036 except subprocess.CalledProcessError as e:
1037 copy_abi_files(os.path.join(tmpdir, "s/ABI"));
1038 raise;
1039 copy_abi_files(os.path.join(tmpdir, "s/ABI"));
1040
1041 def args_pkg(parser):
1042 parser.add_argument("ENV",action=ToEnvActionPkg,choices=env_choices_pkg());
1043 parser.add_argument("--run-shell",default=False,action="store_true",
1044 help="Instead of running the build, enter a shell");
1045 parser.add_argument("--use-prebuilt-pandoc",default=False,action="store_true",
1046 help="Do not rebuild the pandoc cache in build-azure_pipelines/pandoc-prebuilt/");
1047 parser.add_argument("--with", default=[],action="append", dest="with_flags",
1048 help="Enable specified feature in RPM builds");
1049 parser.add_argument("--without", default=[],action="append", dest="without_flags",
1050 help="Disable specified feature in RPM builds");
1051 def cmd_pkg(args):
1052 """Build a package in the given environment."""
1053 for env in args.ENV:
1054 if env.name == "azure_pipelines":
1055 run_azp_build(args,env);
1056 elif getattr(env,"is_deb",False):
1057 run_deb_build(args,env);
1058 elif getattr(env,"is_rpm",False):
1059 run_rpm_build(args,
1060 getattr(env,"specfile","%s.spec"%(project)),
1061 env);
1062 else:
1063 print("%s does not support packaging"%(env.name));
1064
1065 # -------------------------------------------------------------------------
1066
1067 def args_make(parser):
1068 parser.add_argument("--run-shell",default=False,action="store_true",
1069 help="Instead of running the build, enter a shell");
1070 parser.add_argument("ENV",action=ToEnvAction,choices=env_choices());
1071 parser.add_argument('ARGS', nargs=argparse.REMAINDER);
1072 def cmd_make(args):
1073 """Run cmake and ninja within a docker container. If cmake has not yet been
1074 run then this runs it with the given environment variables, then invokes ninja.
1075 Otherwise ninja is invoked without calling cmake."""
1076 SRC = os.getcwd();
1077
1078 for env in args.ENV:
1079 BUILD = "build-%s"%(env.name)
1080 if not os.path.exists(BUILD):
1081 os.mkdir(BUILD);
1082
1083 home = os.path.join(os.path.sep,"home",os.getenv("LOGNAME"));
1084
1085 dirs = [os.getcwd(),"/tmp"];
1086 # Import the symlink target too if BUILD is a symlink
1087 BUILD_r = os.path.realpath(BUILD);
1088 if not BUILD_r.startswith(os.path.realpath(SRC)):
1089 dirs.append(BUILD_r);
1090
1091 cmake_args = []
1092 if not env.build_pyverbs:
1093 cmake_args.extend(["-DNO_PYVERBS=1"]);
1094
1095 cmake_envs = []
1096 ninja_args = []
1097 for I in args.ARGS:
1098 if I.startswith("-D"):
1099 cmake_args.append(I);
1100 elif I.find('=') != -1:
1101 cmake_envs.append(I);
1102 else:
1103 ninja_args.append(I);
1104 if env.use_make:
1105 need_cmake = not os.path.exists(os.path.join(BUILD_r,"Makefile"));
1106 else:
1107 need_cmake = not os.path.exists(os.path.join(BUILD_r,"build.ninja"));
1108 opts = ["run",
1109 "--read-only",
1110 "--rm=true",
1111 "-ti",
1112 "-u",str(os.getuid()),
1113 "-e","HOME=%s"%(home),
1114 "-w",BUILD_r,
1115 ];
1116 opts.extend(env.docker_opts)
1117 for I in dirs:
1118 opts.append("-v");
1119 opts.append("%s:%s"%(I,I));
1120 for I in cmake_envs:
1121 opts.append("-e");
1122 opts.append(I);
1123 if args.run_shell:
1124 opts.append("-ti");
1125 opts.append(env.image_name());
1126
1127 if args.run_shell:
1128 os.execlp("sudo","sudo","docker",*(opts + ["/bin/bash"]));
1129
1130 if need_cmake:
1131 if env.use_make:
1132 prog_args = ["cmake",SRC] + cmake_args;
1133 else:
1134 prog_args = ["cmake","-GNinja",SRC] + cmake_args;
1135 docker_cmd(args,*(opts + prog_args));
1136
1137 if env.use_make:
1138 prog_args = ["make","-C",BUILD_r] + ninja_args;
1139 else:
1140 prog_args = [getattr(env,"ninja_cmd","ninja"),
1141 "-C",BUILD_r] + ninja_args;
1142
1143 if len(args.ENV) <= 1:
1144 os.execlp("sudo","sudo","docker",*(opts + prog_args));
1145 else:
1146 docker_cmd(args,*(opts + prog_args));
1147
1148 # -------------------------------------------------------------------------
1149
1150 def get_build_args(args,env):
1151 """Return extra docker arguments for building. This is the system APT proxy."""
1152 res = [];
1153 if args.pull:
1154 res.append("--pull");
1155
1156 if env.proxy and os.path.exists("/etc/apt/apt.conf.d/01proxy"):
1157 # The line in this file must be 'Acquire::http { Proxy "http://xxxx:3142"; };'
1158 with open("/etc/apt/apt.conf.d/01proxy") as F:
1159 proxy = F.read().strip().split('"')[1];
1160 res.append("--build-arg");
1161 res.append('http_proxy=%s'%(proxy));
1162 return res;
1163
1164 def args_build_images(parser):
1165 parser.add_argument("ENV",nargs="+",action=ToEnvAction,choices=env_choices());
1166 parser.add_argument("--no-pull",default=True,action="store_false",
1167 dest="pull",
1168 help="Instead of running the build, enter a shell");
1169 def cmd_build_images(args):
1170 """Run from the top level source directory to make the docker images that are
1171 needed for building. This only needs to be run once."""
1172 # Docker copies the permissions from the local host and we need this umask
1173 # to be 022 or the container breaks
1174 os.umask(0o22)
1175 for env in args.ENV:
1176 with private_tmp(args) as tmpdir:
1177 df = env.get_docker_file(tmpdir);
1178 fn = os.path.join(tmpdir,"Dockerfile");
1179 with open(fn,"wt") as F:
1180 for ln in df.lines:
1181 print(ln, file=F);
1182 opts = (["build"] +
1183 get_build_args(args,env) +
1184 env.docker_opts +
1185 ["-f",fn,
1186 "-t",env.image_name(),
1187 tmpdir]);
1188 print(opts)
1189 docker_cmd(args,*opts);
1190
1191 # -------------------------------------------------------------------------
1192
1193 def args_push_azp_images(args):
1194 pass
1195 def cmd_push_azp_images(args):
1196 """Push the images required for Azure Pipelines to the container
1197 registry. Must have done 'az login' first"""
1198 subprocess.check_call(["sudo","az","acr","login","--name","ucfconsort"]);
1199 with private_tmp(args) as tmpdir:
1200 nfn = os.path.join(tmpdir,"build.ninja");
1201 with open(nfn,"w") as F:
1202 F.write("""rule push
1203 command = docker push $img
1204 description=Push $img\n""");
1205
1206 for env in environments:
1207 name = env.image_name()
1208 if "ucfconsort.azurecr.io" not in name:
1209 continue
1210 F.write("build push_%s : push\n img = %s\n"%(env.name,env.image_name()));
1211 F.write("default push_%s\n"%(env.name));
1212 subprocess.check_call(["sudo","ninja"],cwd=tmpdir);
1213
1214 # -------------------------------------------------------------------------
1215 def args_make_dist_tar(parser):
1216 parser.add_argument("BUILD",help="Path to the build directory")
1217 parser.add_argument("--tarfn",help="Output TAR filename")
1218 parser.add_argument("--tag",help="git tag to sanity check against")
1219 def cmd_make_dist_tar(args):
1220 """Make the standard distribution tar. The BUILD argument must point to a build
1221 output directory that has pandoc-prebuilt"""
1222 ver = get_version();
1223
1224 if not args.tarfn:
1225 args.tarfn = "%s-%s.tar.gz"%(project,ver)
1226
1227 # The tag name and the cmake file must match.
1228 if args.tag:
1229 assert args.tag == "v" + ver;
1230
1231 os.umask(0o22)
1232 with private_tmp(args) as tmpdir:
1233 tmp_tarfn = os.path.join(tmpdir,"tmp.tar");
1234
1235 prefix = "%s-%s/"%(project,get_version());
1236 subprocess.check_call(["git","archive",
1237 "--prefix",prefix,
1238 "--output",tmp_tarfn,
1239 "HEAD"]);
1240
1241 # Mangle the paths and append the prebuilt stuff to the tar file
1242 if args.BUILD:
1243 subprocess.check_call([
1244 "tar",
1245 "-C",os.path.join(args.script_pwd,args.BUILD,"pandoc-prebuilt"),
1246 "-rf",tmp_tarfn,
1247 "./",
1248 "--xform",r"s|^\.|%sbuildlib/pandoc-prebuilt|g"%(prefix)]);
1249
1250 assert args.tarfn.endswith(".gz") or args.tarfn.endswith(".tgz");
1251 with open(os.path.join(args.script_pwd,args.tarfn),"w") as F:
1252 subprocess.check_call(["gzip","-9c",tmp_tarfn],stdout=F);
1253
1254 # -------------------------------------------------------------------------
1255
1256 if __name__ == '__main__':
1257 parser = argparse.ArgumentParser(description='Operate docker for building this package')
1258 subparsers = parser.add_subparsers(title="Sub Commands",dest="command");
1259 subparsers.required = True;
1260
1261 funcs = globals();
1262 for k,v in list(funcs.items()):
1263 if k.startswith("cmd_") and inspect.isfunction(v):
1264 sparser = subparsers.add_parser(k[4:].replace('_','-'),
1265 help=v.__doc__);
1266 sparser.required = True;
1267 funcs["args_" + k[4:]](sparser);
1268 sparser.set_defaults(func=v);
1269
1270 try:
1271 import argcomplete;
1272 argcomplete.autocomplete(parser);
1273 except ImportError:
1274 pass;
1275
1276 args = parser.parse_args();
1277 args.sudo = True;
1278
1279 # This script must always run from the top of the git tree, and a git
1280 # checkout is mandatory.
1281 git_top = subprocess.check_output(["git","rev-parse","--show-toplevel"]).strip();
1282 args.script_pwd = os.getcwd();
1283 os.chdir(git_top);
1284
1285 args.func(args);