Tobias Thierer | 878c77b | 2019-08-18 15:19:45 +0100 | [diff] [blame] | 1 | // Copyright (C) 2019 The Android Open Source Project |
| 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 | |
Tobias Thierer | adeea59 | 2019-09-27 20:27:29 +0100 | [diff] [blame] | 15 | |
Bob Badour | e539dba | 2021-02-12 17:07:05 -0800 | [diff] [blame] | 16 | package { |
| 17 | // See: http://go/android-license-faq |
| 18 | // A large-scale-change added 'default_applicable_licenses' to import |
| 19 | // all of the 'license_kinds' from "frameworks_base_license" |
| 20 | // to get the below license kinds: |
| 21 | // SPDX-license-identifier-Apache-2.0 |
| 22 | default_applicable_licenses: ["frameworks_base_license"], |
| 23 | } |
| 24 | |
Tobias Thierer | adeea59 | 2019-09-27 20:27:29 +0100 | [diff] [blame] | 25 | java_defaults { |
| 26 | name: "mimemap-defaults", |
| 27 | srcs: [ |
| 28 | "java/android/content/type/DefaultMimeMapFactory.java", |
| 29 | ], |
| 30 | sdk_version: "core_platform", |
| 31 | } |
| 32 | |
Tobias Thierer | 878c77b | 2019-08-18 15:19:45 +0100 | [diff] [blame] | 33 | java_library { |
| 34 | name: "mimemap", |
Tobias Thierer | adeea59 | 2019-09-27 20:27:29 +0100 | [diff] [blame] | 35 | defaults: ["mimemap-defaults"], |
| 36 | static_libs: ["mimemap-res.jar"], |
| 37 | visibility: [ |
| 38 | "//frameworks/base:__subpackages__", |
| 39 | ], |
| 40 | } |
| 41 | |
| 42 | java_library { |
| 43 | name: "mimemap-testing", |
| 44 | defaults: ["mimemap-defaults"], |
| 45 | static_libs: ["mimemap-testing-res.jar"], |
| 46 | jarjar_rules: "jarjar-rules.txt", |
Tobias Thierer | 878c77b | 2019-08-18 15:19:45 +0100 | [diff] [blame] | 47 | visibility: [ |
| 48 | "//cts/tests/tests/mimemap:__subpackages__", |
| 49 | "//frameworks/base:__subpackages__", |
| 50 | ], |
Tobias Thierer | adeea59 | 2019-09-27 20:27:29 +0100 | [diff] [blame] | 51 | } |
Tobias Thierer | 878c77b | 2019-08-18 15:19:45 +0100 | [diff] [blame] | 52 | |
Tobias Thierer | adeea59 | 2019-09-27 20:27:29 +0100 | [diff] [blame] | 53 | // The mimemap-res.jar and mimemap-testing-res.jar genrules produce a .jar that |
| 54 | // has the resource file in a subdirectory res/ and testres/, respectively. |
Tobias Thierer | 9a3c443 | 2019-10-02 20:54:35 +0100 | [diff] [blame] | 55 | // They need to be in different paths because one of them ends up in a |
| 56 | // bootclasspath jar whereas the other one ends up in a test jar. Bootclasspath |
| 57 | // resources hide test or application resources under the same path because |
| 58 | // ClassLoader.getResource(String) consults the parent ClassLoader first. |
Tobias Thierer | adeea59 | 2019-09-27 20:27:29 +0100 | [diff] [blame] | 59 | // |
| 60 | // Further notes: |
| 61 | // - the "cp" command will flatten any directory paths that occur in $(in), |
| 62 | // but here they happen to already be in the root directory. If we needed |
| 63 | // to preserve sub paths then we might want to zip the files first and then |
| 64 | // unzip them below the new parent directory. |
| 65 | // - the path names "res/" and "testres/" and duplicated in .java source files |
| 66 | // (DefaultMimeMapFactory.java and MimeMapTest.java, as of October 2019). |
| 67 | java_genrule { |
| 68 | name: "mimemap-res.jar", |
| 69 | tools: [ |
| 70 | "soong_zip", |
Tobias Thierer | 878c77b | 2019-08-18 15:19:45 +0100 | [diff] [blame] | 71 | ], |
Tobias Thierer | 8e1c1f4 | 2019-10-08 16:27:35 +0100 | [diff] [blame] | 72 | srcs: [":mime.types.minimized"], |
Tobias Thierer | adeea59 | 2019-09-27 20:27:29 +0100 | [diff] [blame] | 73 | out: ["mimemap-res.jar"], |
| 74 | cmd: "mkdir $(genDir)/res/ && cp $(in) $(genDir)/res/ && $(location soong_zip) -C $(genDir) -o $(out) -D $(genDir)/res/", |
| 75 | } |
Tobias Thierer | 878c77b | 2019-08-18 15:19:45 +0100 | [diff] [blame] | 76 | |
Tobias Thierer | adeea59 | 2019-09-27 20:27:29 +0100 | [diff] [blame] | 77 | // The same as mimemap-res.jar except that the resources are placed in a different directory. |
| 78 | // They get bundled with CTS so that CTS can compare a device's MimeMap implementation vs. |
| 79 | // the stock Android one from when CTS was built. |
| 80 | java_genrule { |
| 81 | name: "mimemap-testing-res.jar", |
| 82 | tools: [ |
| 83 | "soong_zip", |
| 84 | ], |
Tobias Thierer | 8e1c1f4 | 2019-10-08 16:27:35 +0100 | [diff] [blame] | 85 | srcs: [":mime.types.minimized"], |
Tobias Thierer | adeea59 | 2019-09-27 20:27:29 +0100 | [diff] [blame] | 86 | out: ["mimemap-testing-res.jar"], |
| 87 | cmd: "mkdir $(genDir)/testres/ && cp $(in) $(genDir)/testres/ && $(location soong_zip) -C $(genDir) -o $(out) -D $(genDir)/testres/", |
| 88 | } |
| 89 | |
Tobias Thierer | 8e1c1f4 | 2019-10-08 16:27:35 +0100 | [diff] [blame] | 90 | // Combination of all *mime.types.minimized resources. |
Tobias Thierer | adeea59 | 2019-09-27 20:27:29 +0100 | [diff] [blame] | 91 | filegroup { |
Tobias Thierer | 8e1c1f4 | 2019-10-08 16:27:35 +0100 | [diff] [blame] | 92 | name: "mime.types.minimized", |
Tobias Thierer | adeea59 | 2019-09-27 20:27:29 +0100 | [diff] [blame] | 93 | visibility: [ |
| 94 | "//visibility:private", |
| 95 | ], |
| 96 | srcs: [ |
Tobias Thierer | 8e1c1f4 | 2019-10-08 16:27:35 +0100 | [diff] [blame] | 97 | ":debian.mime.types.minimized", |
| 98 | ":android.mime.types.minimized", |
| 99 | ":vendor.mime.types.minimized", |
Tobias Thierer | 878c77b | 2019-08-18 15:19:45 +0100 | [diff] [blame] | 100 | ], |
Tobias Thierer | 878c77b | 2019-08-18 15:19:45 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Tobias Thierer | 8e1c1f4 | 2019-10-08 16:27:35 +0100 | [diff] [blame] | 103 | java_genrule { |
| 104 | name: "android.mime.types.minimized", |
Tobias Thierer | 878c77b | 2019-08-18 15:19:45 +0100 | [diff] [blame] | 105 | visibility: [ |
| 106 | "//visibility:private", |
| 107 | ], |
Tobias Thierer | 8e1c1f4 | 2019-10-08 16:27:35 +0100 | [diff] [blame] | 108 | out: ["android.mime.types"], |
Tobias Thierer | 878c77b | 2019-08-18 15:19:45 +0100 | [diff] [blame] | 109 | srcs: [ |
| 110 | "java-res/android.mime.types", |
| 111 | ], |
Tobias Thierer | 8e1c1f4 | 2019-10-08 16:27:35 +0100 | [diff] [blame] | 112 | // strip comments normalize whitepace drop empty lines |
| 113 | cmd: "awk '{gsub(/#.*$$/,\"\"); $$1=$$1; print;}' $(in) | grep ' ' > $(out)", |
Tobias Thierer | 878c77b | 2019-08-18 15:19:45 +0100 | [diff] [blame] | 114 | } |
Tobias Thierer | 3243491 | 2019-09-27 19:22:39 +0100 | [diff] [blame] | 115 | |
Tobias Thierer | 8e1c1f4 | 2019-10-08 16:27:35 +0100 | [diff] [blame] | 116 | // Unlike the other *mime.types files, vendor.mime.types gets '?' prepended to |
| 117 | // every field so that its mappings will never overwrite earlier mappings by |
| 118 | // the other resource files. http://b/141842825 |
| 119 | java_genrule { |
| 120 | name: "vendor.mime.types.minimized", |
Tobias Thierer | 3243491 | 2019-09-27 19:22:39 +0100 | [diff] [blame] | 121 | visibility: [ |
| 122 | "//visibility:private", |
| 123 | ], |
Tobias Thierer | 8e1c1f4 | 2019-10-08 16:27:35 +0100 | [diff] [blame] | 124 | out: ["vendor.mime.types"], |
Tobias Thierer | 3243491 | 2019-09-27 19:22:39 +0100 | [diff] [blame] | 125 | srcs: [ |
| 126 | "java-res/vendor.mime.types", |
| 127 | ], |
Tobias Thierer | 8e1c1f4 | 2019-10-08 16:27:35 +0100 | [diff] [blame] | 128 | // strip comments normalize whitepace drop empty lines prepend ? to fields that are missing it |
| 129 | cmd: "awk '{gsub(/#.*$$/,\"\"); $$1=$$1; print;}' $(in) | grep ' ' | awk '{for(i=1;i<=NF;i++) { sub(/^\\??/, \"?\", $$i); }; print}' > $(out)", |
Tobias Thierer | 3243491 | 2019-09-27 19:22:39 +0100 | [diff] [blame] | 130 | } |