diff options
author | corysmith <corysmith@google.com> | 2017-08-11 21:44:55 +0200 |
---|---|---|
committer | Irina Iancu <elenairina@google.com> | 2017-08-14 14:15:48 +0200 |
commit | e8dd11a99f5772c8bc57b27fb81af010ad9ffca6 (patch) | |
tree | f7afc857608cf21eb36b97a3e0e14d20ab018023 /src/tools/android/java/com/google/devtools/build/android/ValidateAndLinkResourcesAction.java | |
parent | 8306d437ab758c8a45468c77635417a586eecad7 (diff) |
Validate and Link libraries action for aapt2
RELNOTES: None
PiperOrigin-RevId: 165012084
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/ValidateAndLinkResourcesAction.java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/ValidateAndLinkResourcesAction.java | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/ValidateAndLinkResourcesAction.java b/src/tools/android/java/com/google/devtools/build/android/ValidateAndLinkResourcesAction.java new file mode 100644 index 0000000000..bca1bc9a63 --- /dev/null +++ b/src/tools/android/java/com/google/devtools/build/android/ValidateAndLinkResourcesAction.java @@ -0,0 +1,114 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// Copyright 2017 The Bazel Authors. All rights reserved. +package com.google.devtools.build.android; + +import com.google.devtools.build.android.aapt2.Aapt2ConfigOptions; +import com.google.devtools.build.android.aapt2.CompiledResources; +import com.google.devtools.build.android.aapt2.ResourceLinker; +import com.google.devtools.build.android.aapt2.StaticLibrary; +import com.google.devtools.common.options.Option; +import com.google.devtools.common.options.OptionDocumentationCategory; +import com.google.devtools.common.options.OptionEffectTag; +import com.google.devtools.common.options.OptionsBase; +import com.google.devtools.common.options.OptionsParser; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; + +/** Performs resource validation and static linking for compiled android resources. */ +public class ValidateAndLinkResourcesAction { + + /** Action configuration options. */ + public static class Options extends OptionsBase { + @Option( + name = "resources", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + defaultValue = "null", + converter = Converters.CompiledResourcesConverter.class, + category = "input", + help = "Compiled resources to link." + ) + public CompiledResources resources; + + // TODO(b/64570523): remove this flag when it is no longer used. + @Option( + name = "libraries", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + defaultValue = "null", + converter = Converters.StaticLibraryListConverter.class, + category = "input", + help = "Static libraries to link against. Deprecated, use --library" + ) + public List<StaticLibrary> deprecatedLibraries; + + @Option( + name = "library", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + defaultValue = "null", + converter = Converters.StaticLibraryConverter.class, + category = "input", + allowMultiple = true, + help = "Static libraries to link against." + ) + public List<StaticLibrary> libraries; + + @Option( + name = "staticLibraryOut", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + defaultValue = "null", + converter = Converters.PathConverter.class, + category = "output", + help = "Static library produced." + ) + public Path staticLibraryOut; + + @Option( + name = "rTxtOut", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + defaultValue = "null", + converter = Converters.PathConverter.class, + category = "output", + help = "R.txt out." + ) + public Path rTxtOut; + } + + public static void main(String[] args) throws Exception { + final OptionsParser optionsParser = + OptionsParser.newOptionsParser(Options.class, Aapt2ConfigOptions.class); + optionsParser.enableParamsFileSupport(FileSystems.getDefault()); + optionsParser.parse(args); + + Options options = optionsParser.getOptions(Options.class); + final Aapt2ConfigOptions aapt2Options = optionsParser.getOptions(Aapt2ConfigOptions.class); + + try (ScopedTemporaryDirectory scopedTmp = + new ScopedTemporaryDirectory("android_resources_tmp")) { + + ResourceLinker.create(aapt2Options.aapt2, scopedTmp.getPath()) + .dependencies(Optional.ofNullable(options.deprecatedLibraries).orElse(options.libraries)) + .buildVersion(aapt2Options.buildToolsVersion) + .linkStatically(options.resources) + .copyLibraryTo(options.staticLibraryOut) + .copyRTxtTo(options.rTxtOut); + } + } +} |