1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7import os
8import shutil
9import tempfile
10
11from oeqa.selftest.case import OESelftestTestCase
12from oeqa.utils.commands import get_bb_var, runCmd
13
14class ExternalSrc(OESelftestTestCase):
15    # test that srctree_hash_files does not crash
16    # we should be actually checking do_compile[file-checksums] but oeqa currently does not support it
17    #     so we check only that a recipe with externalsrc can be parsed
18    def test_externalsrc_srctree_hash_files(self):
19        test_recipe = "git-submodule-test"
20        git_url = "git://git.yoctoproject.org/git-submodule-test"
21        externalsrc_dir = tempfile.TemporaryDirectory(prefix="externalsrc").name
22
23        self.write_config(
24            """
25INHERIT += "externalsrc"
26EXTERNALSRC:pn-%s = "%s"
27""" % (test_recipe, externalsrc_dir)
28        )
29
30        # test with git without submodules
31        runCmd('git clone %s %s' % (git_url, externalsrc_dir))
32        os.unlink(externalsrc_dir + "/.gitmodules")
33        open(".gitmodules", 'w').close()  # local file .gitmodules in cwd should not affect externalsrc parsing
34        self.assertEqual(get_bb_var("S", test_recipe), externalsrc_dir, msg = "S does not equal to EXTERNALSRC")
35        os.unlink(".gitmodules")
36
37        # test with git with submodules
38        runCmd('git checkout .gitmodules', cwd=externalsrc_dir)
39        runCmd('git submodule update --init --recursive', cwd=externalsrc_dir)
40        self.assertEqual(get_bb_var("S", test_recipe), externalsrc_dir, msg = "S does not equal to EXTERNALSRC")
41
42        # test without git
43        shutil.rmtree(os.path.join(externalsrc_dir, ".git"))
44        self.assertEqual(get_bb_var("S", test_recipe), externalsrc_dir, msg = "S does not equal to EXTERNALSRC")
45