diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Android.bp | 101 | ||||
-rw-r--r-- | CMakeLists.txt | 133 | ||||
-rw-r--r-- | OWNERS | 1 | ||||
-rw-r--r-- | TEST_MAPPING | 12 | ||||
-rw-r--r-- | build.gradle | 113 | ||||
-rw-r--r-- | icing/jni.lds | 10 | ||||
-rw-r--r-- | jarjar-rules.txt | 1 | ||||
-rw-r--r-- | java/Android.bp | 22 | ||||
-rw-r--r-- | java/tests/instrumentation/Android.bp | 42 | ||||
-rw-r--r-- | nativeLib/build.gradle | 19 |
11 files changed, 454 insertions, 1 deletions
@@ -3,3 +3,4 @@ # Files *.iml +*.cmake.gen
\ No newline at end of file diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..7982c4f --- /dev/null +++ b/Android.bp @@ -0,0 +1,101 @@ +// Copyright (C) 2019 The Android Open Source Project +// +// 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. + +java_library { + name: "icing-java-proto-lite", + proto: { + // If you change the proto type, also update jarjar-rules.txt to match + // the corresponding proto lib's package path. + type: "lite", + include_dirs: ["external/protobuf/src"], + canonical_path_from_root: false, + }, + srcs: ["icing/proto/*.proto"], + jarjar_rules: "jarjar-rules.txt", + sdk_version: "core_current", +} + +cc_defaults { + name: "libicing_defaults", + + // For debug / treemap purposes. + //strip: { + // keep_symbols: true, + //}, + + cflags: [ + "-Wall", + "-Werror", + "-Wextra", + "-Wno-deprecated-declarations", + "-Wno-ignored-qualifiers", + "-Wno-missing-field-initializers", + "-Wno-sign-compare", + "-Wno-tautological-constant-out-of-range-compare", + "-Wno-undefined-var-template", + "-Wno-unused-function", + "-Wno-unused-parameter", + "-Wno-extern-c-compat", + + "-funsigned-char", + "-fvisibility=hidden", + ], +} + +cc_library_static { + name: "icing-c-proto", + defaults: ["libicing_defaults"], + proto: { + type: "lite", + // Find protos relative from where they're specified (useful for external protos) + canonical_path_from_root: false, + // Need to be able to see the .pb.h files that are generated + export_proto_headers: true, + }, + srcs: ["icing/**/*.proto"], +} + +cc_library_shared { + name: "libicing_jni", + defaults: ["libicing_defaults"], + srcs: [ + "icing/**/*.cc", + ], + exclude_srcs: [ + // Tests + "icing/**/*_test.cc", + // Benchmarks + "icing/**/*_benchmark.cc", + // Test-only related files (i.e. utils) + "icing/testing/**/*", + // Tools for manual debugging/investigating + "icing/tools/**/*", + ], + static_libs: [ + "icing-c-proto", + "libutf", + ], + shared_libs: [ + "libandroidicu", + "liblog", + // TODO(b/147509515): We only need the full version for GzipStream. If we can remove + // that dependency, then we can just use libprotobuf-cpp-lite + "libprotobuf-cpp-full", + "libz", + ], + + version_script: "icing/jni.lds", +} + +// TODO(cassiewang): Add build rules and a TEST_MAPPING for cc_tests diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..48a63d4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,133 @@ +# Copyright 2020 The Android Open Source Project +# +# 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. + +cmake_minimum_required(VERSION 3.10.2) + +project(icing) + +add_definitions("-DICING_REVERSE_JNI_SEGMENTATION=1") +set(VERSION_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/icing/jni.lds") +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_SHARED_LINKER_FLAGS + "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--version-script=${VERSION_SCRIPT}") + +set( + Protobuf_PREBUILTS_DIR + "${CMAKE_CURRENT_SOURCE_DIR}/../../prebuilts/protobuf") +set(Protobuf_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../protobuf") +set(Protobuf_TARGET_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/protobuf-target") +set(Icing_PROTO_GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/icing-protobuf-gen") + +## Configure libprotobuf ## +# Find the right protoc to compile our proto files +if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin") + set(Protobuf_PROTOC_PATH "${Protobuf_PREBUILTS_DIR}/darwin-x86_64/protoc") +elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux") + set(Protobuf_PROTOC_PATH "${Protobuf_PREBUILTS_DIR}/linux-x86_64/protoc") +elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") + set(Protobuf_PROTOC_PATH "${Protobuf_PREBUILTS_DIR}/windows-x86/protoc.exe") +else() + message( + FATAL_ERROR + "No protoc prebuilt found for host OS ${CMAKE_HOST_SYSTEM_NAME}") +endif() +message(STATUS "Using prebuilt protoc at: ${Protobuf_PROTOC_PATH}") + +# Compile libprotobuf +set(protobuf_BUILD_TESTS OFF CACHE BOOL "") +add_subdirectory("${Protobuf_SOURCE_DIR}/cmake" ${Protobuf_TARGET_BINARY_DIR}) + +# Compile libandroidicu +set(ICU_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../icu/libandroidicu") +set(ICU_TARGET_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/icu-target") +add_subdirectory("${ICU_SOURCE_DIR}/static_shim" ${ICU_TARGET_BINARY_DIR}) + +# Glob Icing proto sources. Results look like this: icing/proto/document.proto +file( + GLOB_RECURSE + Icing_PROTO_FILES + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/proto" + "*.proto") +message(STATUS "Icing_PROTO_FILES=${Icing_PROTO_FILES}") + + +# Run protoc on Icing_PROTO_FILES to generate pb.cc and pb.h files +# The DEPENDS section of add_custom_command could trigger a remake if any proto +# source file has been updated. +file(MAKE_DIRECTORY ${Icing_PROTO_GEN_DIR}) +foreach(FILE ${Icing_PROTO_FILES}) + # Find the name of the proto file without the .proto extension + string(REGEX REPLACE "\.proto$" "" FILE_NOEXT ${FILE}) + list(APPEND Icing_PROTO_SOURCES + "${Icing_PROTO_GEN_DIR}/${FILE_NOEXT}.pb.cc" + "${Icing_PROTO_GEN_DIR}/${FILE_NOEXT}.pb.h") + add_custom_command( + OUTPUT "${Icing_PROTO_GEN_DIR}/${FILE_NOEXT}.pb.cc" + "${Icing_PROTO_GEN_DIR}/${FILE_NOEXT}.pb.h" + COMMAND ${Protobuf_PROTOC_PATH} + --proto_path "${CMAKE_CURRENT_SOURCE_DIR}/proto" + --cpp_out "lite:${Icing_PROTO_GEN_DIR}" + ${FILE} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/proto/${FILE} + ) +endforeach() +message(STATUS "Icing_PROTO_SOURCES=${Icing_PROTO_SOURCES}") + +# Glob Icing C++ sources +# TODO: When supporting cmake v3.12 or higher, use CONFIGURE_DEPENDS in the glob +# below so that cmake knows when to re-generate the makefiles. +file( + # List files recursively + GLOB_RECURSE + # Store into a variable of this name + Icing_CC_SOURCES + # Return paths that are relative to the project root + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + # Glob expressions + icing/*.cc icing/*.h +) + +# TODO(b/170611579): When supporting cmake v3.12 or higher, use CONFIGURE_DEPENDS +# in the glob and remove this section. +include(synced_AOSP_CL_number.txt) + +# Exclude the same types of files as Android.bp. See the comments there. +list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/.*[^a-zA-Z0-9]test[^a-zA-Z0-9].*$") +list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/.*_benchmark\.cc$") +list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/helpers/icu/.*$") +list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/testing/.*$") +list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/tokenization/icu/.*$") +list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/tokenization/simple/.*$") +list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/tools/.*$") +list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/transform/icu/.*$") +list(FILTER Icing_CC_SOURCES EXCLUDE REGEX "^icing/transform/simple/.*$") +message(STATUS "Icing_CC_SOURCES=${Icing_CC_SOURCES}") + +add_library( + # .so name + icing + + # Shared or static + SHARED + + # Provides a relative path to your source file(s). + ${Icing_CC_SOURCES} + ${Icing_PROTO_SOURCES} +) +target_include_directories(icing PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(icing PRIVATE ${Icing_PROTO_GEN_DIR}) +target_include_directories(icing PRIVATE "${Protobuf_SOURCE_DIR}/src") +target_include_directories(icing PRIVATE "${ICU_SOURCE_DIR}/include") +target_link_libraries(icing protobuf::libprotobuf-lite libandroidicu log z) @@ -1,3 +1,2 @@ adorokhine@google.com tjbarron@google.com -dsaadati@google.com diff --git a/TEST_MAPPING b/TEST_MAPPING new file mode 100644 index 0000000..37cb5fc --- /dev/null +++ b/TEST_MAPPING @@ -0,0 +1,12 @@ +{ + "presubmit": [ + { + "name": "IcingSearchEngineTest" + } + ], + "imports": [ + { + "path": "frameworks/base/apex/appsearch/service/java/com/android/server/appsearch" + } + ] +} diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..62e6e73 --- /dev/null +++ b/build.gradle @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * 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. + */ + +import static androidx.build.SupportConfig.* + +buildscript { + dependencies { + classpath('gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.13') + } +} + +plugins { + id('com.android.library') + id('com.google.protobuf') +} + +android { + buildToolsVersion BUILD_TOOLS_VERSION + compileSdkVersion COMPILE_SDK_VERSION + defaultConfig { + minSdkVersion DEFAULT_MIN_SDK_VERSION + targetSdkVersion TARGET_SDK_VERSION + testInstrumentationRunner INSTRUMENTATION_RUNNER + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + sourceSets { + main { + java.srcDir 'java/src/' + proto.srcDir 'proto/' + } + // TODO(b/161205849): Re-enable this test once icing nativeLib is no longer being built + // inside appsearch:appsearch. + //androidTest.java.srcDir 'java/tests/instrumentation/' + } + namespace "com.google.android.icing" +} + +// This project has no device tests, skip building it +androidComponents { + beforeVariants(selector().withName("debug"), { variantBuilder -> + variantBuilder.enableAndroidTest = false + }) +} + +dependencies { + api('androidx.annotation:annotation:1.1.0') + + implementation('com.google.protobuf:protobuf-javalite:3.10.0') + + androidTestImplementation(libs.testCore) + androidTestImplementation(libs.testRules) + androidTestImplementation(libs.truth) + androidTestImplementation(libs.kotlinBom) +} + +protobuf { + protoc { + artifact = libs.protobufCompiler.get() + } + + generateProtoTasks { + all().each { task -> + project.tasks.named("extractReleaseAnnotations").configure { + it.dependsOn(task) + } + task.builtins { + java { + option 'lite' + } + } + } + } +} + +// Create export artifact for all variants (debug/release) for JarJaring +android.libraryVariants.all { variant -> + def variantName = variant.name + def suffix = variantName.capitalize() + def exportJarTask = tasks.register("exportJar${suffix}", Jar) { + archiveBaseName.set("icing-${variantName}") + + // The proto-lite dependency includes .proto files, which are not used by icing. When apps + // depend on appsearch as well as proto-lite directly, these files conflict since jarjar + // only renames the java classes. Remove them here since they are unused. + // Expand the jar and remove any .proto files. + from(zipTree(configurations.detachedConfiguration( + dependencies.create(libs.protobufLite.get())).getSingleFile())) { + exclude("**/*.proto") + } + + from files(variant.javaCompileProvider.get().destinationDir) + dependsOn variant.javaCompileProvider.get() + } + + def exportConfiguration = configurations.register("export${suffix}") + artifacts.add(exportConfiguration.name, exportJarTask.flatMap { it.archiveFile }) +} diff --git a/icing/jni.lds b/icing/jni.lds new file mode 100644 index 0000000..401682a --- /dev/null +++ b/icing/jni.lds @@ -0,0 +1,10 @@ +VERS_1.0 { + # Export JNI symbols. + global: + Java_*; + JNI_OnLoad; + + # Hide everything else + local: + *; +}; diff --git a/jarjar-rules.txt b/jarjar-rules.txt new file mode 100644 index 0000000..0f4292e --- /dev/null +++ b/jarjar-rules.txt @@ -0,0 +1 @@ +rule com.google.protobuf.** com.google.android.icing.protobuf.@1 diff --git a/java/Android.bp b/java/Android.bp new file mode 100644 index 0000000..6bc8836 --- /dev/null +++ b/java/Android.bp @@ -0,0 +1,22 @@ +// Copyright (C) 2020 The Android Open Source Project +// +// 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. + +java_library { + name: "libicing-java", + srcs: ["src/**/*.java"], + static_libs: [ + "icing-java-proto-lite", + "libprotobuf-java-lite", + ], +} diff --git a/java/tests/instrumentation/Android.bp b/java/tests/instrumentation/Android.bp new file mode 100644 index 0000000..c941acf --- /dev/null +++ b/java/tests/instrumentation/Android.bp @@ -0,0 +1,42 @@ +// Copyright (C) 2019 The Android Open Source Project +// +// 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. + +android_test { + name: "IcingSearchEngineTest", + + manifest: "AndroidManifest.xml", + + srcs: [ + "src/**/*.java", + ], + + static_libs: [ + "androidx.test.ext.junit", + "androidx.test.rules", + "androidx.test.ext.truth", + "libicing-java", + "icing-java-proto-lite", + ], + + jni_libs: [ + "libicing_jni", + ], + + test_suites: [ + "device-tests", + ], + + platform_apis: true, + use_embedded_native_libs: true, +} diff --git a/nativeLib/build.gradle b/nativeLib/build.gradle new file mode 100644 index 0000000..6b30451 --- /dev/null +++ b/nativeLib/build.gradle @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * 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. + */ + +// TODO(b/161205849): We've had to move libicing.so compilation into appsearch:appsearch to get +// it included into the exported aar. Find a proper solution for bundling libicing.so into +// appsearch-release.aar and move compilation of libicing.so back into the external/icing tree. |