1// 2// Copyright (C) 2022 The Android Open Source Project 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15// 16 17// Build NullAway from sources for the platform 18// 19// Note: this is only intended to be used for the platform development. This is *not* intended 20// to be used in the SDK where apps can use the official jacoco release. 21package { 22 default_applicable_licenses: ["external_nullaway_license"], 23} 24 25// See: http://go/android-license-faq 26license { 27 name: "external_nullaway_license", 28 visibility: [":__subpackages__"], 29 license_kinds: [ 30 "SPDX-license-identifier-Apache-2.0", 31 "SPDX-license-identifier-GPL-2.0-with-classpath-exception", 32 "SPDX-license-identifier-MIT", 33 ], 34 license_text: [ 35 "LICENSE.txt", 36 "LICENSE", 37 "NOTICE", 38 ], 39} 40 41java_plugin { 42 name: "nullaway_plugin", 43 44 static_libs: [ 45 "nullaway_lib", 46 ], 47} 48 49java_library_host { 50 name: "nullaway_lib", 51 52 srcs: [ 53 "nullaway/src/**/*.java", 54 ":nullaway_fake_contract_annotation", 55 ], 56 57 exclude_srcs: ["nullaway/src/test/**/*.java"], 58 59 static_libs: [ 60 "guava", 61 "//external/error_prone:error_prone_checkerframework_dataflow_nullaway", 62 "//external/error_prone:error_prone_core", 63 "nullaway_annotations", 64 ], 65 66 libs: [ 67 "auto_service_annotations", 68 "auto_value_annotations", 69 ], 70 71 plugins: [ 72 "auto_service_plugin", 73 "auto_value_plugin", 74 ], 75 76 javacflags: [ 77 "--add-modules=jdk.compiler", 78 "--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", 79 "--add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", 80 "--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", 81 "--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", 82 "--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", 83 "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", 84 "--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", 85 "--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", 86 ], 87} 88 89// Nullaway depends on the Contract annotation, but we don't have it imported into android. 90// Create a fake stub annotation to use instead. 91genrule { 92 name: "nullaway_fake_contract_annotation", 93 out: ["org/jetbrains/annotations/Contract.java"], 94 cmd: "echo 'package org.jetbrains.annotations;' >> $(out) && " + 95 "echo 'import java.lang.annotation.*;' >> $(out) && " + 96 "echo '@Retention(RetentionPolicy.CLASS)' >> $(out) && " + 97 "echo '@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})' >> $(out) && " + 98 "echo 'public @interface Contract {' >> $(out) && " + 99 "echo ' String value() default \"\";' >> $(out) && " + 100 "echo '}' >> $(out)", 101 visibility: ["//visibility:private"], 102} 103 104java_library { 105 name: "nullaway_annotations", 106 host_supported: true, 107 108 srcs: [ 109 "annotations/src/**/*.java" 110 ], 111} 112