Add USE_D8_DESUGAR option in build/core

Add an option to use D8's desugar instead of the standalone version.

USE_D8_DESUGAR=true m would trigger DCHECK in dex2oat unless
https://android-review.googlesource.com/c/platform/art/+/562595 is
patched in as well.

Bug: 69329508
Test: m && USE_D8_DESUGAR=false m

Change-Id: I601dada44c361e45bbc0e2227ae1544a7d9efa90
diff --git a/core/definitions.mk b/core/definitions.mk
index 96a6663..e350bd0 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -2411,6 +2411,19 @@
     $<
 endef
 
+
+define transform-classes-d8.jar-to-dex
+@echo "target Dex: $(PRIVATE_MODULE)"
+@mkdir -p $(dir $@)
+$(hide) rm -f $(dir $@)classes*.dex
+$(hide) $(DX_COMMAND) \
+    --output $(dir $@) \
+    --min-api $(PRIVATE_MIN_SDK_VERSION) \
+    $(subst --no-locals, --release, \
+        $(filter-out --core-library --multi-dex,$(PRIVATE_DX_FLAGS))) \
+    $<
+endef
+
 # Create a mostly-empty .jar file that we'll add to later.
 # The MacOS jar tool doesn't like creating empty jar files,
 # so we need to give it something.