UPSTREAM: Reapply "config: Don't directly modify FEATURES"

This reverts commit b150419d28bd7afb98404a829c639584d34efc03.

It turns out we need to keep the open coded version to avoid creating
a persistent setting.
See https://github.com/gentoo/portage/pull/1098#issuecomment-1761638611

This change just adds a sorted() so we get deterministic ordering.

Bug: https://bugs.gentoo.org/914441
Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Closes: https://github.com/gentoo/portage/pull/1312
Signed-off-by: Zac Medico <zmedico@gentoo.org>
(cherry picked from commit 72f41d07b5396195a98691fafeb3e5b207a76564)

BUG=b:281732865
TEST=CQ

Change-Id: Ica2874c17711dbf3f9cc2380c58dd06acfe8c876
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/portage_tool/+/5485147
Auto-Submit: Raul Rangel <rrangel@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Raul Rangel <rrangel@chromium.org>
Tested-by: Raul Rangel <rrangel@chromium.org>
diff --git a/lib/portage/package/ebuild/config.py b/lib/portage/package/ebuild/config.py
index 29155a4..663d959 100644
--- a/lib/portage/package/ebuild/config.py
+++ b/lib/portage/package/ebuild/config.py
@@ -1800,8 +1800,9 @@
 				# "test" is in IUSE and USE=test is masked, so execution
 				# of src_test() probably is not reliable. Therefore,
 				# temporarily disable FEATURES=test just for this package.
-				self["FEATURES"] = " ".join(x for x in self.features \
-					if x != "test")
+				self["FEATURES"] = " ".join(
+					x for x in sorted(self.features) if x != "test"
+				)
 
 		if eapi_attrs.feature_flag_targetroot and \
 			("targetroot" in explicit_iuse or iuse_implicit_match("targetroot")):