[entropy.core] implement "drop all USE" in the new dep. rewrite

This commit is contained in:
Sławomir Nizio
2018-02-24 19:52:12 +01:00
parent 0a56ec74b8
commit cbcbf7495f
3 changed files with 41 additions and 6 deletions

View File

@@ -78,7 +78,8 @@
# If present in rule, ::use_to_remove:: will be removed if dependency contains it.
#
# ::dep_atom:: and ::new_dep_atom:: are category/package names, without version, slot etc.
# ::use_to_remove:: can be an asterisk (*) which means to remove all USE flags.
#
# Examples:
# EXAMPLE
# rewrite foo/bar from-dep=app-crypt/pinentry to-dep=app-crypt/pinentry-gtk2 if-dep-has-use=gtk drop-use=gtk
# will change foo/bar's dependency "app-crypt/pinentry[gtk,qt5]" to "app-crypt/pinentry-gtk2[qt5]".

View File

@@ -1299,11 +1299,18 @@ class DependencyRewriter(object):
dep_has_use_func = lambda _: True
if 'drop-use' in self._rule_dict:
modify_use_func = lambda dep_postfix, use_flags_list, clean_use_flags_list: \
DependencyRewriter._use_in_depstring_re.sub(
self._filter_use(use_flags_list, clean_use_flags_list, self._rule_dict['drop-use']),
dep_postfix,
count=1)
if self._rule_dict['drop-use'] == "*":
modify_use_func = lambda dep_postfix, use_flags_list, clean_use_flags_list: \
DependencyRewriter._use_in_depstring_re.sub(
"",
dep_postfix,
count=1)
else:
modify_use_func = lambda dep_postfix, use_flags_list, clean_use_flags_list: \
DependencyRewriter._use_in_depstring_re.sub(
self._filter_use(use_flags_list, clean_use_flags_list, self._rule_dict['drop-use']),
dep_postfix,
count=1)
else:
modify_use_func = lambda dep_postfix, _1, _2: dep_postfix

View File

@@ -442,6 +442,18 @@ class DependencyRewriterTests(unittest.TestCase, DepsRewriteTestsMixin):
self._expected_deps = ["x11-misc/lightdm-qt5"]
self._validate()
def test_with_drop_use_asterisk(self):
self._rule = "from-dep=x11-misc/lightdm to-dep=x11-misc/lightdm-qt5 drop-use=*"
self._deps = ["x11-misc/lightdm[qt4?,qt5]"]
self._expected_deps = ["x11-misc/lightdm-qt5"]
self._validate()
def test_with_drop_use_asterisk_and_no_use_in_dep(self):
self._rule = "from-dep=x11-misc/lightdm to-dep=x11-misc/lightdm-qt5 drop-use=*"
self._deps = ["x11-misc/lightdm"]
self._expected_deps = ["x11-misc/lightdm-qt5"]
self._validate()
def test_raises_on_unknown_key(self):
rule = "from-dep=x11-misc/lightdm to-dep=x11-misc/lightdm-qt4 haha=true"
deps = ["x11-misc/lightdm"]
@@ -508,6 +520,21 @@ class DependencyRewriterBasicAttrsTests(unittest.TestCase, MatchedChangedTestsMi
self._expected_changed = False
self._validate()
def test_matched_and_changed_with_use_asterisk(self):
self._rule = "from-dep=x11-misc/lightdm to-dep=x11-misc/lightdm drop-use=*"
self._deps = ["x11-misc/lightdm[gtk]"]
self._expected_matched = True
self._expected_changed = True
self._validate()
def test_matched_and_not_changed_with_use_asterisk(self):
self._rule = "from-dep=x11-misc/lightdm to-dep=x11-misc/lightdm drop-use=*"
self._deps = ["x11-misc/lightdm"]
self._expected_matched = True
self._expected_changed = False
self._validate()
if __name__ == '__main__':
unittest.main()
raise SystemExit(0)