github.com/rigado/snapd@v2.42.5-go-mod+incompatible/parts/plugins/x_builddeb.py (about) 1 # Copyright (C) 2018 Canonical Ltd 2 # 3 # This program is free software: you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License version 3 as 5 # published by the Free Software Foundation. 6 # 7 # This program is distributed in the hope that it will be useful, 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # GNU General Public License for more details. 11 # 12 # You should have received a copy of the GNU General Public License 13 # along with this program. If not, see <http://www.gnu.org/licenses/>. 14 15 import glob 16 import os 17 18 import snapcraft 19 20 # cowboy baby :( 21 # see https://bugs.launchpad.net/snapcraft/+bug/1772584 22 # and https://bugs.launchpad.net/snapcraft/+bug/1791871 23 # 24 # This will be fixed by snapcraft - the agreement is that they 25 # will look for a .snap/ directory with "snapcraft" in it and 26 # use that when available. 27 def patch_snapcraft(): 28 import snapcraft.internal.common 29 import snapcraft.internal.sources._local 30 # very hacky but gets the job done for now, right now 31 # SNAPCRAFT_FILES is only used to know what to exclude 32 snapcraft.internal.common.SNAPCRAFT_FILES.remove("snap") 33 def _patched_check(self, target): 34 return False 35 snapcraft.internal.sources._local.Local._check = _patched_check 36 patch_snapcraft() 37 38 39 40 class XBuildDeb(snapcraft.BasePlugin): 41 42 def build(self): 43 super().build() 44 self.run(["sudo", "apt-get", "build-dep", "-y", "./"]) 45 # ensure we have go in our PATH 46 env=os.environ.copy() 47 # ensure build with go-1.10 if available 48 if os.path.exists("/usr/lib/go-1.10/bin"): 49 env["PATH"] = "/usr/lib/go-1.10/bin:{}".format(env["PATH"]) 50 # XXX: get this from "debian/gbp.conf:postexport" 51 self.run(["./get-deps.sh", "--skip-unused-check"], env=env) 52 if os.getuid() == 0: 53 # disable running the tests during the build when run as root 54 # because quite a few of them will break 55 env["DEB_BUILD_OPTIONS"] = "nocheck" 56 # run the real build 57 self.run(["dpkg-buildpackage"], env=env) 58 # and "install" into the right place 59 snapd_deb = glob.glob(os.path.join(self.partdir, "snapd_*.deb"))[0] 60 self.run(["dpkg-deb", "-x", os.path.abspath(snapd_deb), self.installdir]) 61