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