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;
}
}
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)));
}
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]));
}
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)));
}
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);
}
Aggregations