Fix termination when using R8 partial system properties

Change-Id: I785f7060460870c97b4bdd72386799d31fb1b67c
diff --git a/src/main/java/com/android/tools/r8/R8Command.java b/src/main/java/com/android/tools/r8/R8Command.java
index 627eb12..ff4834c 100644
--- a/src/main/java/com/android/tools/r8/R8Command.java
+++ b/src/main/java/com/android/tools/r8/R8Command.java
@@ -160,9 +160,7 @@
     private ResourceShrinkerConfiguration resourceShrinkerConfiguration =
         ResourceShrinkerConfiguration.DEFAULT_CONFIGURATION;
     private R8PartialCompilationConfiguration partialCompilationConfiguration =
-        R8PartialCompilationConfiguration.fromIncludeExcludePatterns(
-            System.getProperty("com.android.tools.r8.experimentalPartialShrinkingIncludePatterns"),
-            System.getProperty("com.android.tools.r8.experimentalPartialShrinkingExcludePatterns"));
+        R8PartialCompilationConfiguration.fromSystemProperties();
 
     private final ProguardConfigurationParserOptions.Builder parserOptionsBuilder =
         ProguardConfigurationParserOptions.builder().readEnvironment();
diff --git a/src/main/java/com/android/tools/r8/R8Partial.java b/src/main/java/com/android/tools/r8/R8Partial.java
index 2c8fd0c..2b104b9 100644
--- a/src/main/java/com/android/tools/r8/R8Partial.java
+++ b/src/main/java/com/android/tools/r8/R8Partial.java
@@ -11,6 +11,7 @@
 import com.android.tools.r8.graph.DirectMappedDexApplication;
 import com.android.tools.r8.graph.LazyLoadedDexApplication;
 import com.android.tools.r8.keepanno.ast.KeepDeclaration;
+import com.android.tools.r8.partial.R8PartialCompilationConfiguration;
 import com.android.tools.r8.partial.R8PartialD8Input;
 import com.android.tools.r8.partial.R8PartialD8Result;
 import com.android.tools.r8.partial.R8PartialProgramPartitioning;
@@ -181,6 +182,8 @@
                 options.apiModelingOptions().isApiModelingEnabled())
             .setMinApiLevel(options.getMinApiLevel().getLevel())
             .setMode(options.getCompilationMode())
+            .setPartialCompilationConfiguration(
+                R8PartialCompilationConfiguration.disabledConfiguration())
             .setProgramConsumer(options.programConsumer);
     // The program input that R8 must compile is provided above using an
     // InternalProgramClassProvider. This passes in the data resources that we must either rewrite
diff --git a/src/main/java/com/android/tools/r8/partial/R8PartialCompilationConfiguration.java b/src/main/java/com/android/tools/r8/partial/R8PartialCompilationConfiguration.java
index 4c33c1f..1bc3961 100644
--- a/src/main/java/com/android/tools/r8/partial/R8PartialCompilationConfiguration.java
+++ b/src/main/java/com/android/tools/r8/partial/R8PartialCompilationConfiguration.java
@@ -24,6 +24,11 @@
 
 public class R8PartialCompilationConfiguration {
 
+  public static final String INCLUDE_PROPERTY_NAME =
+      "com.android.tools.r8.experimentalPartialShrinkingIncludePatterns";
+  public static final String EXCLUDE_PROPERTY_NAME =
+      "com.android.tools.r8.experimentalPartialShrinkingExcludePatterns";
+
   private final boolean enabled;
   private final R8PartialPredicateCollection includePredicates;
   private final R8PartialPredicateCollection excludePredicates;
@@ -100,6 +105,11 @@
     return builder.build();
   }
 
+  public static R8PartialCompilationConfiguration fromSystemProperties() {
+    return fromIncludeExcludePatterns(
+        System.getProperty(INCLUDE_PROPERTY_NAME), System.getProperty(EXCLUDE_PROPERTY_NAME));
+  }
+
   public static Builder builder() {
     return new Builder();
   }
diff --git a/src/test/java/com/android/tools/r8/partial/PartialCompilationSystemPropertyTest.java b/src/test/java/com/android/tools/r8/partial/PartialCompilationSystemPropertyTest.java
new file mode 100644
index 0000000..1e5c8cc
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/partial/PartialCompilationSystemPropertyTest.java
@@ -0,0 +1,71 @@
+// Copyright (c) 2025, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.partial;
+
+import static com.android.tools.r8.utils.codeinspector.Matchers.isAbsent;
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.utils.codeinspector.ClassSubject;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class PartialCompilationSystemPropertyTest extends TestBase {
+
+  @Parameter(0)
+  public TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withNoneRuntime().build();
+  }
+
+  @Test
+  public void test() throws Exception {
+    System.setProperty(
+        R8PartialCompilationConfiguration.INCLUDE_PROPERTY_NAME, IncludedMain.class.getTypeName());
+    testForR8(Backend.DEX)
+        .addInnerClasses(getClass())
+        .addKeepMainRule(IncludedMain.class)
+        .setMinApi(apiLevelWithNativeMultiDexSupport())
+        .compile()
+        .inspect(
+            inspector -> {
+              ClassSubject includedClass = inspector.clazz(IncludedMain.class);
+              assertThat(includedClass, isPresent());
+              assertThat(includedClass.uniqueMethodWithOriginalName("test"), isAbsent());
+
+              ClassSubject excludedClass = inspector.clazz(ExcludedMain.class);
+              assertThat(excludedClass, isPresent());
+              assertThat(excludedClass.uniqueMethodWithOriginalName("test"), isPresent());
+            });
+  }
+
+  static class IncludedMain {
+
+    public static void main(String[] args) {
+      test();
+    }
+
+    // Should be inlined.
+    static void test() {}
+  }
+
+  static class ExcludedMain {
+
+    public static void main(String[] args) {
+      test();
+    }
+
+    // Should not be inlined.
+    static void test() {}
+  }
+}