Jingwen Chen | c34d6ee | 2018-06-08 13:09:31 -0700 | [diff] [blame^] | 1 | # Copyright 2018 The Bazel Authors. All rights reserved. |
| 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 | """Rules for importing external Android Archives (AARs). |
| 15 | |
| 16 | Usage: |
| 17 | |
| 18 | # In WORKSPACE |
| 19 | load("@bazel_tools//tools/build_defs/repo:android.bzl", "aar_import_external", "aar_maven_import_external") |
| 20 | |
| 21 | # Specify the URL directly: |
| 22 | aar_import_external( |
| 23 | name = "com_android_support_preference_v14_25_1_0", # required |
| 24 | licenses = ["notice"], # required |
| 25 | aar_urls = [ # required |
| 26 | "https://dl.google.com/dl/android/maven2/com/android/support/preference-v14/25.1.0/preference-v14-25.1.0.aar" |
| 27 | ], |
| 28 | aar_sha256 = "442473fe5c395ebef26c14eb01d17ceda33ad207a4cc23a32a2ad95b87edfabb", # optional or empty string |
| 29 | deps = [ # optional or empty list |
| 30 | "@com_android_support_recyclerview_v7_25_1_0//aar", |
| 31 | "@com_android_support_appcompat_v7_25_1_0//aar", |
| 32 | "@com_android_support_preference_v7_25_1_0//aar", |
| 33 | "@com_android_support_support_v4_25_1_0//aar", |
| 34 | ], |
| 35 | ) |
| 36 | |
| 37 | # Or, specify the artifact coordinate: |
| 38 | aar_maven_import_external( |
| 39 | name = "com_android_support_preference_v14_25_1_0", # required |
| 40 | artifact = "com.android.support.test:preference-v14:25.1.0", # required |
| 41 | sha256 = "442473fe5c395ebef26c14eb01d17ceda33ad207a4cc23a32a2ad95b87edfabb" # optional or empty string |
| 42 | licenses = ["notice"], # required |
| 43 | server_urls = ["https://maven.google.com"], # required |
| 44 | deps = [ # optional or empty list |
| 45 | "@com_android_support_recyclerview_v7_25_1_0//aar", |
| 46 | "@com_android_support_appcompat_v7_25_1_0//aar", |
| 47 | "@com_android_support_preference_v7_25_1_0//aar", |
| 48 | "@com_android_support_support_v4_25_1_0//aar", |
| 49 | ], |
| 50 | ) |
| 51 | |
| 52 | # In BUILD.bazel |
| 53 | android_library( |
| 54 | name = "foo", |
| 55 | srcs = [...], |
| 56 | deps = [ |
| 57 | "@com_android_support_preference_v14_25_1_0//aar", |
| 58 | ], |
| 59 | ) |
| 60 | """ |
| 61 | |
| 62 | load(":jvm.bzl", "convert_artifact_coordinate_to_urls", "jvm_import_external") |
| 63 | |
| 64 | def aar_import_external(aar_sha256, aar_urls, **kwargs): |
| 65 | jvm_import_external( |
| 66 | rule_name = "aar_import", |
| 67 | rule_metadata = { |
| 68 | "extension": "aar", |
| 69 | "import_attr": "aar = %s", |
| 70 | }, |
| 71 | artifact_sha256 = aar_sha256, |
| 72 | artifact_urls = aar_urls, |
| 73 | **kwargs |
| 74 | ) |
| 75 | |
| 76 | def aar_maven_import_external(artifact, server_urls, aar_sha256 = "", **kwargs): |
| 77 | aar_import_external( |
| 78 | aar_sha256 = aar_sha256, |
| 79 | aar_urls = convert_artifact_coordinate_to_urls( |
| 80 | artifact, |
| 81 | server_urls, |
| 82 | "aar", |
| 83 | ), |
| 84 | **kwargs |
| 85 | ) |