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