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
This commit is contained in:
Amir Shalem
2019-09-10 08:15:12 -07:00
committed by Facebook Github Bot
parent e6e224ce48
commit 31de91bbac
10 changed files with 91 additions and 8 deletions

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.yoga.testutil">
</manifest>

View File

@@ -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)

View File

@@ -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.
*/
#pragma once
#include <yoga/event/event.h>
#include <functional>
namespace facebook {
namespace yoga {
namespace test {
struct TestUtil {
static void startCountingNodes();
static int nodeCount();
static int stopCountingNodes();
};
struct ScopedEventSubscription {
ScopedEventSubscription(std::function<Event::Subscriber>&&);
~ScopedEventSubscription();
};
} // namespace test
} // namespace yoga
} // namespace facebook

View File

@@ -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.
*/
#include <fbjni/fbjni.h>
#include <yoga/testutil/testutil.h>
using namespace facebook;
namespace {
void startCountingNodes(jni::alias_ref<jclass>) {
yoga::test::TestUtil::startCountingNodes();
}
jint nodeCount(jni::alias_ref<jclass>) {
return yoga::test::TestUtil::nodeCount();
}
jint stopCountingNodes(jni::alias_ref<jclass>) {
return yoga::test::TestUtil::stopCountingNodes();
}
} // namespace
jint JNI_OnLoad(JavaVM* vm, void*) {
return jni::initialize(vm, [] {
jni::registerNatives(
"com/facebook/yoga/TestUtil",
{
makeNativeMethod("startCountingNodes", startCountingNodes),
makeNativeMethod("nodeCount", nodeCount),
makeNativeMethod("stopCountingNodes", stopCountingNodes),
});
});
}

View File

@@ -0,0 +1,65 @@
/*
* 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.
*/
#include <yoga/testutil/testutil.h>
#include <yoga/YGNode.h>
#include <yoga/event/event.h>
namespace facebook {
namespace yoga {
namespace test {
int nodeInstanceCount = 0;
namespace {
void yogaEventSubscriber(
const YGNode& node,
Event::Type eventType,
const Event::Data& eventData) {
switch (eventType) {
case Event::NodeAllocation:
nodeInstanceCount++;
break;
case Event::NodeDeallocation:
nodeInstanceCount--;
break;
default:
break;
}
}
} // namespace
void TestUtil::startCountingNodes() {
nodeInstanceCount = 0;
Event::subscribe(yogaEventSubscriber);
}
int TestUtil::nodeCount() {
return nodeInstanceCount;
}
int TestUtil::stopCountingNodes() {
Event::reset();
auto prev = nodeInstanceCount;
nodeInstanceCount = 0;
return prev;
}
ScopedEventSubscription::ScopedEventSubscription(
std::function<Event::Subscriber>&& s) {
Event::subscribe(std::move(s));
}
ScopedEventSubscription::~ScopedEventSubscription() {
Event::reset();
}
} // namespace test
} // namespace yoga
} // namespace facebook

View File

@@ -0,0 +1,19 @@
/*
* 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.
*/
package com.facebook.yoga;
import com.facebook.soloader.SoLoader;
class TestUtil {
static {
SoLoader.loadLibrary("yoga_testutil_jni");
}
static native void startCountingNodes();
static native int nodeCount();
static native int stopCountingNodes();
}