All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.java.com.debughelper.tools.r8.PrintSeeds Maven / Gradle / Ivy

The newest version!
// Copyright (c) 2018, 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.debughelper.tools.r8;

import com.debughelper.tools.r8.ArchiveClassFileProvider;
import com.debughelper.tools.r8.ClassFileConsumer;
import com.debughelper.tools.r8.PrintUses;
import com.debughelper.tools.r8.dex.ApplicationReader;
import com.debughelper.tools.r8.graph.AppInfoWithSubtyping;
import com.debughelper.tools.r8.graph.DexApplication;
import com.debughelper.tools.r8.shaking.Enqueuer;
import com.debughelper.tools.r8.shaking.RootSetBuilder;
import com.debughelper.tools.r8.shaking.RootSetBuilder.RootSet;
import com.debughelper.tools.r8.utils.ExceptionUtils;
import com.debughelper.tools.r8.utils.InternalOptions;
import com.debughelper.tools.r8.utils.ThreadUtils;
import com.debughelper.tools.r8.utils.Timing;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;

/**
 * PrintSeeds prints the classes, interfaces, methods and fields selected by a given ProGuard
 * configuration <pg-conf.txt> when compiling a given program <r8.jar> alongside a given
 * library <rt.jar>.
 *
 * 

The output format is identical to what is printed when {@code -printseeds} is specified in * <pg-conf.txt>, but running PrintSeeds can be faster than running R8 with {@code * -printseeds}. See also the {@link com.debughelper.tools.r8.PrintUses} program in R8. */ public class PrintSeeds { private static final String USAGE = "Arguments: \n" + "\n" + "PrintSeeds prints the classes, interfaces, methods and fields selected by\n" + " when compiling alongside .\n" + "\n" + "The output format is identical to what is printed when -printseeds is specified in\n" + ", but running PrintSeeds can be faster than running R8 with \n" + "-printseeds. See also the " + PrintUses.class.getSimpleName() + " program in R8."; public static void main(String[] args) throws Exception { if (args.length != 3) { System.out.println(USAGE.replace("\n", System.lineSeparator())); System.exit(1); } Path rtJar = Paths.get(args[0]); Path r8Jar = Paths.get(args[1]); Path pgConf = Paths.get(args[2]); R8Command command = R8Command.builder() .addLibraryFiles(rtJar) .addProgramFiles(r8Jar) .addProguardConfigurationFiles(pgConf) .setProgramConsumer(ClassFileConsumer.emptyConsumer()) .build(); Set descriptors = new ArchiveClassFileProvider(r8Jar).getClassDescriptors(); InternalOptions options = command.getInternalOptions(); ExecutorService executorService = ThreadUtils.getExecutorService(options); ExceptionUtils.withR8CompilationHandler( command.getReporter(), () -> { try { run(command, descriptors, options, executorService); } finally { executorService.shutdown(); } }); } private static void run( R8Command command, Set descriptors, InternalOptions options, ExecutorService executor) throws IOException { Timing timing = new Timing("PrintSeeds"); try { DexApplication application = new ApplicationReader(command.getInputApp(), options, timing).read(executor).toDirect(); AppInfoWithSubtyping appInfo = new AppInfoWithSubtyping(application); RootSet rootSet = new RootSetBuilder( appInfo, application, options.proguardConfiguration.getRules(), options) .run(executor); Enqueuer enqueuer = new Enqueuer(appInfo, options, false); appInfo = enqueuer.traceApplication(rootSet, executor, timing); RootSetBuilder.writeSeeds( appInfo.withLiveness(), System.out, type -> descriptors.contains(type.toDescriptorString())); } catch (ExecutionException e) { R8.unwrapExecutionException(e); throw new AssertionError(e); // unwrapping method should have thrown } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy