Search in sources :

Example 16 with OptionsParser

use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.

the class LibraryRClassGeneratorAction method main.

public static void main(String[] args) throws Exception {
    final Stopwatch timer = Stopwatch.createStarted();
    OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class, AaptConfigOptions.class);
    optionsParser.enableParamsFileSupport(FileSystems.getDefault());
    optionsParser.parseAndExitUponError(args);
    AaptConfigOptions aaptConfigOptions = optionsParser.getOptions(AaptConfigOptions.class);
    Options options = optionsParser.getOptions(Options.class);
    logger.fine(String.format("Option parsing finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
    try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("android_resource_generated")) {
        AndroidResourceClassWriter resourceClassWriter = AndroidResourceClassWriter.createWith(aaptConfigOptions.androidJar, scopedTmp.getPath(), Strings.nullToEmpty(options.packageForR));
        resourceClassWriter.setIncludeClassFile(true);
        resourceClassWriter.setIncludeJavaFile(false);
        final AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(stdLogger);
        logger.fine(String.format("Setup finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
        final ParsedAndroidData data = resourceProcessor.deserializeSymbolsToData(options.symbols);
        logger.fine(String.format("Deserialization finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
        data.writeResourcesTo(resourceClassWriter);
        resourceClassWriter.flush();
        logger.fine(String.format("R writing finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
        AndroidResourceOutputs.createClassJar(scopedTmp.getPath(), options.classJarOutput);
        logger.fine(String.format("Creating class jar finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
    } catch (IOException | MergingException | DeserializationException e) {
        logger.log(Level.SEVERE, "Errors during R generation.", e);
        throw e;
    }
}
Also used : AaptConfigOptions(com.google.devtools.build.android.AndroidResourceProcessor.AaptConfigOptions) MergingException(com.android.ide.common.res2.MergingException) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) OptionsParser(com.google.devtools.common.options.OptionsParser) AaptConfigOptions(com.google.devtools.build.android.AndroidResourceProcessor.AaptConfigOptions)

Example 17 with OptionsParser

use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.

the class RClassGeneratorAction method main.

public static void main(String[] args) throws Exception {
    final Stopwatch timer = Stopwatch.createStarted();
    OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
    optionsParser.enableParamsFileSupport(FileSystems.getDefault());
    if (args.length == 1 && args[0].startsWith("@")) {
        args = Files.readAllLines(Paths.get(args[0].substring(1)), StandardCharsets.UTF_8).toArray(new String[0]);
    }
    optionsParser.parseAndExitUponError(args);
    Options options = optionsParser.getOptions(Options.class);
    Preconditions.checkNotNull(options.classJarOutput);
    final AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(STD_LOGGER);
    try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("android_res_compile_tmp")) {
        Path tmp = scopedTmp.getPath();
        Path classOutPath = tmp.resolve("compiled_classes");
        logger.fine(String.format("Setup finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
        List<SymbolFileProvider> libraries = new ArrayList<>();
        for (DependencySymbolFileProvider library : options.libraries) {
            libraries.add(library);
        }
        // are no libraries).
        if (options.primaryRTxt != null) {
            String appPackageName = options.packageForR;
            if (appPackageName == null) {
                appPackageName = VariantConfiguration.getManifestPackage(options.primaryManifest.toFile());
            }
            Multimap<String, SymbolLoader> libSymbolMap = ArrayListMultimap.create();
            SymbolLoader fullSymbolValues = resourceProcessor.loadResourceSymbolTable(libraries, appPackageName, options.primaryRTxt, libSymbolMap);
            logger.fine(String.format("Load symbols finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
            // For now, assuming not used for libraries and setting final access for fields.
            if (fullSymbolValues != null) {
                resourceProcessor.writePackageRClasses(libSymbolMap, fullSymbolValues, appPackageName, classOutPath, true);
                logger.fine(String.format("Finished R.class at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
            }
        } else {
            Files.createDirectories(classOutPath);
        }
        // We write .class files to temp, then jar them up after (we create a dummy jar, even if
        // there are no class files).
        AndroidResourceOutputs.createClassJar(classOutPath, options.classJarOutput);
        logger.fine(String.format("createClassJar finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
    } finally {
        resourceProcessor.shutdown();
    }
    logger.fine(String.format("Compile action done in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
Also used : Path(java.nio.file.Path) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) OptionsParser(com.google.devtools.common.options.OptionsParser) SymbolLoader(com.android.builder.internal.SymbolLoader) SymbolFileProvider(com.android.builder.dependency.SymbolFileProvider)

Example 18 with OptionsParser

use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.

the class ResourceProcessorBusyBox method main.

public static void main(String[] args) throws Exception {
    OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
    optionsParser.setAllowResidue(true);
    optionsParser.enableParamsFileSupport(FileSystems.getDefault());
    optionsParser.parse(args);
    Options options = optionsParser.getOptions(Options.class);
    options.tool.call(optionsParser.getResidue().toArray(new String[0]));
}
Also used : OptionsParser(com.google.devtools.common.options.OptionsParser)

Example 19 with OptionsParser

use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.

the class AndroidResourceParsingAction method main.

public static void main(String[] args) throws Exception {
    OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
    optionsParser.enableParamsFileSupport(FileSystems.getDefault());
    optionsParser.parseAndExitUponError(args);
    Options options = optionsParser.getOptions(Options.class);
    Preconditions.checkNotNull(options.primaryData);
    Preconditions.checkNotNull(options.output);
    final Stopwatch timer = Stopwatch.createStarted();
    ParsedAndroidData parsedPrimary = ParsedAndroidData.from(options.primaryData);
    logger.fine(String.format("Walked XML tree at %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
    UnwrittenMergedAndroidData unwrittenData = UnwrittenMergedAndroidData.of(null, parsedPrimary, ParsedAndroidData.from(ImmutableList.<DependencyAndroidData>of()));
    AndroidDataSerializer serializer = AndroidDataSerializer.create();
    unwrittenData.serializeTo(serializer);
    serializer.flushTo(options.output);
    logger.fine(String.format("Finished parse + serialize in %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
Also used : Stopwatch(com.google.common.base.Stopwatch) OptionsParser(com.google.devtools.common.options.OptionsParser)

Example 20 with OptionsParser

use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.

the class AarGeneratorAction method main.

public static void main(String[] args) {
    Stopwatch timer = Stopwatch.createStarted();
    OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
    optionsParser.parseAndExitUponError(args);
    Options options = optionsParser.getOptions(Options.class);
    checkFlags(options);
    AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(new StdLogger(com.android.utils.StdLogger.Level.VERBOSE));
    try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("aar_gen_tmp")) {
        Path tmp = scopedTmp.getPath();
        Path resourcesOut = tmp.resolve("merged_resources");
        Files.createDirectories(resourcesOut);
        Path assetsOut = tmp.resolve("merged_assets");
        Files.createDirectories(assetsOut);
        logger.fine(String.format("Setup finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
        // There aren't any dependencies, but we merge to combine primary resources from different
        // res/assets directories into a single res and single assets directory.
        MergedAndroidData mergedData = AndroidResourceMerger.mergeData(options.mainData, ImmutableList.<DependencyAndroidData>of(), ImmutableList.<DependencyAndroidData>of(), resourcesOut, assetsOut, null, VariantType.LIBRARY, null);
        logger.fine(String.format("Merging finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
        writeAar(options.aarOutput, mergedData, options.manifest, options.rtxt, options.classes);
        logger.fine(String.format("Packaging finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
    } catch (IOException | MergingException e) {
        logger.log(Level.SEVERE, "Error during merging resources", e);
        System.exit(1);
    }
    System.exit(0);
}
Also used : Path(java.nio.file.Path) MergingException(com.android.ide.common.res2.MergingException) StdLogger(com.android.utils.StdLogger) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) OptionsParser(com.google.devtools.common.options.OptionsParser)

Aggregations

OptionsParser (com.google.devtools.common.options.OptionsParser)50 Path (java.nio.file.Path)11 IOException (java.io.IOException)10 Stopwatch (com.google.common.base.Stopwatch)8 Test (org.junit.Test)7 InvocationPolicyEnforcer (com.google.devtools.build.lib.flags.InvocationPolicyEnforcer)6 OptionsParsingException (com.google.devtools.common.options.OptionsParsingException)6 AaptConfigOptions (com.google.devtools.build.android.AndroidResourceProcessor.AaptConfigOptions)5 OptionsBase (com.google.devtools.common.options.OptionsBase)5 MergingException (com.android.ide.common.res2.MergingException)4 Path (com.google.devtools.build.lib.vfs.Path)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 EventBus (com.google.common.eventbus.EventBus)3 FlagAaptOptions (com.google.devtools.build.android.AndroidResourceProcessor.FlagAaptOptions)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 VariantType (com.android.builder.core.VariantType)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 DexingOptions (com.google.devtools.build.android.dexer.Dexing.DexingOptions)2 SpawnActionContext (com.google.devtools.build.lib.actions.SpawnActionContext)2