diff options
Diffstat (limited to 'meta')
| -rw-r--r-- | meta/lib/oeqa/selftest/cases/devtool.py | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/devtool.py b/meta/lib/oeqa/selftest/cases/devtool.py index 81d02017c1..94873fd19f 100644 --- a/meta/lib/oeqa/selftest/cases/devtool.py +++ b/meta/lib/oeqa/selftest/cases/devtool.py | |||
| @@ -848,6 +848,99 @@ class DevtoolModifyTests(DevtoolBase): | |||
| 848 | # Try building | 848 | # Try building |
| 849 | bitbake(testrecipe) | 849 | bitbake(testrecipe) |
| 850 | 850 | ||
| 851 | def test_devtool_modify_git_crates_subpath(self): | ||
| 852 | # This tests two things in devtool context: | ||
| 853 | # - that we support local git dependencies for cargo based recipe | ||
| 854 | # - that we support patches in SRC_URI when git url contains subpath parameter | ||
| 855 | |||
| 856 | # Check preconditions: | ||
| 857 | # recipe inherits cargo | ||
| 858 | # git:// uri with a subpath as the main package | ||
| 859 | # some crate:// in SRC_URI | ||
| 860 | # others git:// in SRC_URI | ||
| 861 | # cointains a patch | ||
| 862 | testrecipe = 'zvariant' | ||
| 863 | bb_vars = get_bb_vars(['SRC_URI', 'FILE', 'WORKDIR', 'CARGO_HOME'], testrecipe) | ||
| 864 | recipefile = bb_vars['FILE'] | ||
| 865 | workdir = bb_vars['WORKDIR'] | ||
| 866 | cargo_home = bb_vars['CARGO_HOME'] | ||
| 867 | src_uri = bb_vars['SRC_URI'].split() | ||
| 868 | self.assertTrue(src_uri[0].startswith('git://'), | ||
| 869 | 'This test expects the %s recipe to have a git repo has its main uri' % testrecipe) | ||
| 870 | self.assertIn(';subpath=', src_uri[0], | ||
| 871 | 'This test expects the %s recipe to have a git uri with subpath' % testrecipe) | ||
| 872 | self.assertTrue(any([uri.startswith('crate://') for uri in src_uri]), | ||
| 873 | 'This test expects the %s recipe to have some crates in its src uris' % testrecipe) | ||
| 874 | self.assertGreater(sum(map(lambda x:x.startswith('git://'), src_uri)), 2, | ||
| 875 | 'This test expects the %s recipe to have several git:// uris' % testrecipe) | ||
| 876 | self.assertTrue(any([uri.startswith('file://') and '.patch' in uri for uri in src_uri]), | ||
| 877 | 'This test expects the %s recipe to have a patch in its src uris' % testrecipe) | ||
| 878 | |||
| 879 | self._test_recipe_contents(recipefile, {}, ['cargo']) | ||
| 880 | |||
| 881 | # Clean up anything in the workdir/sysroot/sstate cache | ||
| 882 | bitbake('%s -c cleansstate' % testrecipe) | ||
| 883 | # Try modifying a recipe | ||
| 884 | tempdir = tempfile.mkdtemp(prefix='devtoolqa') | ||
| 885 | self.track_for_cleanup(tempdir) | ||
| 886 | self.track_for_cleanup(self.workspacedir) | ||
| 887 | self.add_command_to_tearDown('bitbake -c clean %s' % testrecipe) | ||
| 888 | self.add_command_to_tearDown('bitbake-layers remove-layer */workspace') | ||
| 889 | result = runCmd('devtool modify %s -x %s' % (testrecipe, tempdir)) | ||
| 890 | self.assertExists(os.path.join(tempdir, 'Cargo.toml'), 'Extracted source could not be found') | ||
| 891 | self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created. devtool output: %s' % result.output) | ||
| 892 | matches = glob.glob(os.path.join(self.workspacedir, 'appends', 'zvariant_*.bbappend')) | ||
| 893 | self.assertTrue(matches, 'bbappend not created') | ||
| 894 | # Test devtool status | ||
| 895 | result = runCmd('devtool status') | ||
| 896 | self.assertIn(testrecipe, result.output) | ||
| 897 | self.assertIn(tempdir, result.output) | ||
| 898 | # Check git repo | ||
| 899 | self._check_src_repo(tempdir) | ||
| 900 | # Check that the patch is correctly applied | ||
| 901 | # last commit message in the tree must contain | ||
| 902 | # %% original patch: <patchname> | ||
| 903 | # .. | ||
| 904 | patchname = None | ||
| 905 | for uri in src_uri: | ||
| 906 | if uri.startswith('file://') and '.patch' in uri: | ||
| 907 | patchname = uri.replace("file://", "").partition('.patch')[0] + '.patch' | ||
| 908 | self.assertIsNotNone(patchname) | ||
| 909 | result = runCmd('git -C %s log -1' % tempdir) | ||
| 910 | self.assertIn("%%%% original patch: %s" % patchname, result.output) | ||
| 911 | |||
| 912 | # Configure the recipe to check that the git dependencies are correctly patched in cargo config | ||
| 913 | bitbake('-c configure %s' % testrecipe) | ||
| 914 | |||
| 915 | cargo_config_path = os.path.join(cargo_home, 'config') | ||
| 916 | with open(cargo_config_path, "r") as f: | ||
| 917 | cargo_config_contents = [line.strip('\n') for line in f.readlines()] | ||
| 918 | |||
| 919 | # Get back git dependencies of the recipe (ignoring the main one) | ||
| 920 | # and check that they are all correctly patched to be fetched locally | ||
| 921 | git_deps = [uri for uri in src_uri if uri.startswith("git://")][1:] | ||
| 922 | for git_dep in git_deps: | ||
| 923 | raw_url, _, raw_parms = git_dep.partition(";") | ||
| 924 | parms = {} | ||
| 925 | for parm in raw_parms.split(";"): | ||
| 926 | name_parm, _, value_parm = parm.partition('=') | ||
| 927 | parms[name_parm]=value_parm | ||
| 928 | self.assertIn('protocol', parms, 'git dependencies uri should contain the "protocol" parameter') | ||
| 929 | self.assertIn('name', parms, 'git dependencies uri should contain the "name" parameter') | ||
| 930 | self.assertIn('destsuffix', parms, 'git dependencies uri should contain the "destsuffix" parameter') | ||
| 931 | self.assertIn('type', parms, 'git dependencies uri should contain the "type" parameter') | ||
| 932 | self.assertEqual(parms['type'], 'git-dependency', 'git dependencies uri should have "type=git-dependency"') | ||
| 933 | raw_url = raw_url.replace("git://", '%s://' % parms['protocol']) | ||
| 934 | patch_line = '[patch."%s"]' % raw_url | ||
| 935 | path_patched = os.path.join(workdir, parms['destsuffix']) | ||
| 936 | path_override_line = '%s = { path = "%s" }' % (parms['name'], path_patched) | ||
| 937 | # Would have been better to use tomllib to read this file :/ | ||
| 938 | self.assertIn(patch_line, cargo_config_contents) | ||
| 939 | self.assertIn(path_override_line, cargo_config_contents) | ||
| 940 | |||
| 941 | # Try to package the recipe | ||
| 942 | bitbake('-c package_qa %s' % testrecipe) | ||
| 943 | |||
| 851 | def test_devtool_modify_localfiles(self): | 944 | def test_devtool_modify_localfiles(self): |
| 852 | # Check preconditions | 945 | # Check preconditions |
| 853 | testrecipe = 'lighttpd' | 946 | testrecipe = 'lighttpd' |
