• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2020 The Dagger Authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Macro for producing dejetified artifacts.
16"""
17
18# See: https://developer.android.com/studio/command-line/jetifier
19JETIFIER_STANDALONE = "https://dl.google.com/dl/android/studio/jetifier-zips/1.0.0-beta08/jetifier-standalone.zip"
20
21def dejetified_library(name, input, output):
22    _dejetify_library(name, input, output)
23
24def _dejetify_library(name, input, output):
25    """Generates a dejetified library artifact.
26
27    A dejetified artifact is one that has been transformed to migrate its
28    AndroidX APIs to the support equivalents.
29
30    Args:
31      name: The name of the target.
32      input: The android_library input, e.g. ":myLibrary.aar".
33      output: The name of the output artifact, e.g. "dejetified-myLibrary.aar".
34    """
35    native.genrule(
36        name = name,
37        srcs = [input],
38        outs = [output],
39        cmd = """
40            TEMP="$$(mktemp -d)"
41            curl {tool_link} --output $$TEMP/jetifier-standalone.zip
42            unzip $$TEMP/jetifier-standalone.zip -d $$TEMP/
43            $$TEMP/jetifier-standalone/bin/jetifier-standalone -r \
44              -l info -i $< -o $@
45        """.format(tool_link = JETIFIER_STANDALONE),
46        local = 1,
47    )
48