From 31de91bbac22df7a7e03271e98f730e50c0d36d1 Mon Sep 17 00:00:00 2001 From: Amir Shalem Date: Tue, 10 Sep 2019 08:15:12 -0700 Subject: [PATCH] fix gradle compliation (#925) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/925 Gradle is failing to compile yoga for two reasons: 1. Ever since `YogaNodeJNIPhantomRefs` was introduced which uses `DestructorThread.Destructor` from fbjni which was the first direct Java dependency from yoga java to fbjni java code. 2. Adding a missing gradle endpoint for `testutil` since it is now required for yoga unit-tests Reviewed By: SidharthGuglani Differential Revision: D17274226 fbshipit-source-id: 3df9648321162d34f81fd3675ca1474e8a1c6d3a --- java/build.gradle | 2 + settings.gradle | 3 +- testutil/BUCK | 12 +++--- testutil/build.gradle | 38 +++++++++++++++++++ testutil/src/main/AndroidManifest.xml | 12 ++++++ testutil/src/main/cpp/CMakeLists.txt | 30 +++++++++++++++ .../cpp/include/yoga/testutil}/testutil.h | 0 testutil/{ => src/main/cpp/jni}/jni.cpp | 0 .../{ => src/main/cpp/testutil}/testutil.cpp | 2 +- .../java/com/facebook/yoga}/TestUtil.java | 0 10 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 testutil/build.gradle create mode 100644 testutil/src/main/AndroidManifest.xml create mode 100644 testutil/src/main/cpp/CMakeLists.txt rename testutil/{ => src/main/cpp/include/yoga/testutil}/testutil.h (100%) rename testutil/{ => src/main/cpp/jni}/jni.cpp (100%) rename testutil/{ => src/main/cpp/testutil}/testutil.cpp (97%) rename testutil/{ => src/main/java/com/facebook/yoga}/TestUtil.java (100%) diff --git a/java/build.gradle b/java/build.gradle index 8cded209..e4494ddc 100644 --- a/java/build.gradle +++ b/java/build.gradle @@ -60,8 +60,10 @@ android { dependencies { compileOnly 'com.google.code.findbugs:jsr305:3.0.1' compileOnly project(':yoga:proguard-annotations') + compile project(':libfb') implementation 'com.facebook.soloader:soloader:0.5.1' testImplementation 'junit:junit:4.12' + testCompile project(':testutil') } task sourcesJar(type: Jar) { diff --git a/settings.gradle b/settings.gradle index 1c136f10..573bc583 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,8 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -include ':yoga', ':yogacore', ':yoga-layout', ':yoga:proguard-annotations', ':libfb' +include ':yoga', ':yogacore', ':yoga-layout', ':yoga:proguard-annotations', ':libfb', ':testutil' project(':yoga').projectDir = file('java') project(':yoga:proguard-annotations').projectDir = file('java/proguard-annotations') project(':yoga-layout').projectDir = file('android') project(':libfb').projectDir = file('lib/fb') +project(':testutil').projectDir = file('testutil') diff --git a/testutil/BUCK b/testutil/BUCK index 421ffb30..56ee97fe 100644 --- a/testutil/BUCK +++ b/testutil/BUCK @@ -1,10 +1,10 @@ -load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID", "FBJNI_TARGET", "LIBRARY_COMPILER_FLAGS", "SOLOADER_TARGET", "yoga_cxx_library", "yoga_dep", "yoga_java_library") +load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID", "FBJNI_TARGET", "LIBRARY_COMPILER_FLAGS", "SOLOADER_TARGET", "subdir_glob", "yoga_cxx_library", "yoga_dep", "yoga_java_library") yoga_cxx_library( name = "testutil", - srcs = ["testutil.cpp"], - header_namespace = "yoga/testutil", - exported_headers = ["testutil.h"], + srcs = ["src/main/cpp/testutil/testutil.cpp"], + header_namespace = "", + exported_headers = subdir_glob([("src/main/cpp/include", "yoga/testutil/testutil.h")]), compiler_flags = LIBRARY_COMPILER_FLAGS, soname = "libyoga_testutil.$(ext)", visibility = ["PUBLIC"], @@ -13,7 +13,7 @@ yoga_cxx_library( yoga_java_library( name = "java", - srcs = ["TestUtil.java"], + srcs = ["src/main/java/com/facebook/yoga/TestUtil.java"], source = "1.7", target = "1.7", visibility = ["PUBLIC"], @@ -25,7 +25,7 @@ yoga_java_library( yoga_cxx_library( name = "jni", - srcs = ["jni.cpp"], + srcs = ["src/main/cpp/jni/jni.cpp"], allow_jni_merging = False, compiler_flags = LIBRARY_COMPILER_FLAGS, platforms = ANDROID, diff --git a/testutil/build.gradle b/testutil/build.gradle new file mode 100644 index 00000000..47074284 --- /dev/null +++ b/testutil/build.gradle @@ -0,0 +1,38 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +apply plugin: 'com.android.library' + +android { + compileSdkVersion rootProject.compileSdkVersion + buildToolsVersion rootProject.buildToolsVersion + + defaultConfig { + minSdkVersion rootProject.minSdkVersion + targetSdkVersion rootProject.targetSdkVersion + + ndk { + abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' + } + + externalNativeBuild { + cmake { + arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static' + } + } + } + + externalNativeBuild { + cmake { + path 'src/main/cpp/CMakeLists.txt' + } + } + + dependencies { + implementation 'com.facebook.soloader:soloader:0.5.1' + } +} diff --git a/testutil/src/main/AndroidManifest.xml b/testutil/src/main/AndroidManifest.xml new file mode 100644 index 00000000..7d6f3e5c --- /dev/null +++ b/testutil/src/main/AndroidManifest.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/testutil/src/main/cpp/CMakeLists.txt b/testutil/src/main/cpp/CMakeLists.txt new file mode 100644 index 00000000..2330f8e3 --- /dev/null +++ b/testutil/src/main/cpp/CMakeLists.txt @@ -0,0 +1,30 @@ +# +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. +# + +cmake_minimum_required(VERSION 3.4.1) + +set(CMAKE_VERBOSE_MAKEFILE on) + +add_compile_options( + -fno-omit-frame-pointer + -fexceptions + -Wall + -std=c++11 + -DDISABLE_CPUCAP + -DDISABLE_XPLAT) + +file(GLOB testutil_SRC + jni/*.cpp + testutil/*.cpp) + +add_library(testutil SHARED + ${testutil_SRC}) + +target_include_directories(testutil PRIVATE + include) + +target_link_libraries(testutil android log) diff --git a/testutil/testutil.h b/testutil/src/main/cpp/include/yoga/testutil/testutil.h similarity index 100% rename from testutil/testutil.h rename to testutil/src/main/cpp/include/yoga/testutil/testutil.h diff --git a/testutil/jni.cpp b/testutil/src/main/cpp/jni/jni.cpp similarity index 100% rename from testutil/jni.cpp rename to testutil/src/main/cpp/jni/jni.cpp diff --git a/testutil/testutil.cpp b/testutil/src/main/cpp/testutil/testutil.cpp similarity index 97% rename from testutil/testutil.cpp rename to testutil/src/main/cpp/testutil/testutil.cpp index c8f9e32c..09061fb7 100644 --- a/testutil/testutil.cpp +++ b/testutil/src/main/cpp/testutil/testutil.cpp @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the LICENSE * file in the root directory of this source tree. */ -#include "testutil.h" +#include #include #include diff --git a/testutil/TestUtil.java b/testutil/src/main/java/com/facebook/yoga/TestUtil.java similarity index 100% rename from testutil/TestUtil.java rename to testutil/src/main/java/com/facebook/yoga/TestUtil.java