Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 7 | import glob |
| 8 | import os |
| 9 | import shutil |
| 10 | import tempfile |
| 11 | from oeqa.selftest.case import OESelftestTestCase |
| 12 | from oeqa.utils.commands import runCmd, bitbake, get_bb_vars |
| 13 | |
| 14 | |
| 15 | class oeGoToolchainSelfTest(OESelftestTestCase): |
| 16 | """ |
| 17 | Test cases for OE's Go toolchain |
| 18 | """ |
| 19 | |
| 20 | @staticmethod |
| 21 | def get_sdk_environment(tmpdir_SDKQA): |
| 22 | pattern = os.path.join(tmpdir_SDKQA, "environment-setup-*") |
| 23 | # FIXME: this is a very naive implementation |
| 24 | return glob.glob(pattern)[0] |
| 25 | |
| 26 | @staticmethod |
| 27 | def get_sdk_toolchain(): |
| 28 | bb_vars = get_bb_vars(['SDK_DEPLOY', 'TOOLCHAIN_OUTPUTNAME'], |
| 29 | "meta-go-toolchain") |
| 30 | sdk_deploy = bb_vars['SDK_DEPLOY'] |
| 31 | toolchain_name = bb_vars['TOOLCHAIN_OUTPUTNAME'] |
| 32 | return os.path.join(sdk_deploy, toolchain_name + ".sh") |
| 33 | |
| 34 | @classmethod |
| 35 | def setUpClass(cls): |
| 36 | super(oeGoToolchainSelfTest, cls).setUpClass() |
| 37 | cls.tmpdir_SDKQA = tempfile.mkdtemp(prefix='SDKQA') |
| 38 | cls.go_path = os.path.join(cls.tmpdir_SDKQA, "go") |
| 39 | # Build the SDK and locate it in DEPLOYDIR |
| 40 | bitbake("meta-go-toolchain") |
| 41 | cls.sdk_path = oeGoToolchainSelfTest.get_sdk_toolchain() |
| 42 | # Install the SDK into the tmpdir |
| 43 | runCmd("sh %s -y -d \"%s\"" % (cls.sdk_path, cls.tmpdir_SDKQA)) |
| 44 | cls.env_SDK = oeGoToolchainSelfTest.get_sdk_environment(cls.tmpdir_SDKQA) |
| 45 | |
| 46 | @classmethod |
| 47 | def tearDownClass(cls): |
| 48 | shutil.rmtree(cls.tmpdir_SDKQA, ignore_errors=True) |
| 49 | super(oeGoToolchainSelfTest, cls).tearDownClass() |
| 50 | |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 51 | def run_sdk_go_command(self, gocmd, proj, name): |
| 52 | cmd = "cd %s/src/%s/%s; " % (self.go_path, proj, name) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 53 | cmd = cmd + ". %s; " % self.env_SDK |
| 54 | cmd = cmd + "export GOPATH=%s; " % self.go_path |
Patrick Williams | db4c27e | 2022-08-05 08:10:29 -0500 | [diff] [blame] | 55 | cmd = cmd + "export GOFLAGS=-modcacherw; " |
| 56 | cmd = cmd + "export CGO_ENABLED=1; " |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 57 | cmd = cmd + "${CROSS_COMPILE}go %s" % gocmd |
| 58 | return runCmd(cmd).status |
| 59 | |
| 60 | def test_go_dep_build(self): |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 61 | proj = "github.com/direnv" |
| 62 | name = "direnv" |
| 63 | ver = "v2.27.0" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 64 | archive = ".tar.gz" |
| 65 | url = "https://%s/%s/archive/%s%s" % (proj, name, ver, archive) |
| 66 | |
| 67 | runCmd("cd %s; wget %s" % (self.tmpdir_SDKQA, url)) |
| 68 | runCmd("cd %s; tar -xf %s" % (self.tmpdir_SDKQA, ver+archive)) |
| 69 | runCmd("mkdir -p %s/src/%s" % (self.go_path, proj)) |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 70 | runCmd("mv %s/direnv-2.27.0 %s/src/%s/%s" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 71 | % (self.tmpdir_SDKQA, self.go_path, proj, name)) |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 72 | retv = self.run_sdk_go_command('build', proj, name) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 73 | self.assertEqual(retv, 0, |
| 74 | msg="Running go build failed for %s" % name) |