This is an automated email from the ASF dual-hosted git repository.

granthenke pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 2d858f66a0ac91a56128e4e2a90b6c81db05df41
Author: Grant Henke <[email protected]>
AuthorDate: Wed Mar 4 08:35:30 2020 -0600

    [build] Use Gradle to build the hms-plugin jar
    
    In an effort to unify how we build Java from cmake/make, this
    patch converts the `hms-plugin.jar` compilation from using
    `add_jar` to using `add_custom_command` calling a Gradle
    command.
    
    In order to ensure mutliple calls to Gradle don’t try and
    download the `gradle-wrapper.jar` at the same time, I added an
    `init-gradle` target that all Gradle commands should depend on.
    
    I also added `--quiet --console=plain` command line flags to
    the Gradle commands to prevent weird Gradle logging within the
    make build.
    
    Change-Id: I3312b1605c4f050380264688f9d1b78038608257
    Reviewed-on: http://gerrit.cloudera.org:8080/15360
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <[email protected]>
---
 CMakeLists.txt                     | 18 +++++++++++++++++-
 build-support/run_dist_test.py     |  8 ++++++--
 src/kudu/hms/CMakeLists.txt        | 19 ++++++++++---------
 src/kudu/subprocess/CMakeLists.txt |  9 +++------
 4 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b3207f8..3a56fb5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -76,7 +76,6 @@ if (SLASH_POS EQUAL -1)
   endfunction()
 endif()
 
-# TODO: can we somehow pass this into the java build?
 file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" KUDU_VERSION_NUMBER)
 
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
@@ -94,6 +93,23 @@ set(THIRDPARTY_INSTALL_TSAN_DIR 
${THIRDPARTY_INSTALL_DIR}/tsan)
 # This can be useful to, e.g. spawn a Java subprocess.
 set(JAVA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/java)
 
+# Adds the EXTRA_GRADLE_FLAGS environment variable to a cmake list and calls 
`separate_arguments`.
+# This solves the problem of escaped spaces in the EXTRA_GRADLE_FLAGS 
environment variable.
+list(APPEND GRADLE_FLAGS $ENV{EXTRA_GRADLE_FLAGS})
+separate_arguments(GRADLE_FLAGS)
+# We always want Gradle to use the plain console and quiet flag when called 
from cmake.
+list(APPEND GRADLE_FLAGS --quiet --console=plain)
+list(REMOVE_DUPLICATES GRADLE_FLAGS)
+
+# Initialize Gradle to ensure the wrapper is downloaded.
+# This is important so that multiple calls to Gradle don't try and
+# download the gradle-wrapper.jar at the same time.
+set(GRADLE_WRAPPER_JAR ${JAVA_DIR}/gradle/wrapper/gradle-wrapper.jar)
+add_custom_command(OUTPUT ${GRADLE_WRAPPER_JAR}
+  COMMAND ./gradlew --version ${GRADLE_FLAGS}
+  WORKING_DIRECTORY "${JAVA_DIR}")
+add_custom_target(init_gradle DEPENDS ${GRADLE_WRAPPER_JAR})
+
 # Allow "make install" to not depend on all targets.
 #
 # Must be declared in the top-level CMakeLists.txt.
diff --git a/build-support/run_dist_test.py b/build-support/run_dist_test.py
index d613b44..99b3a78 100755
--- a/build-support/run_dist_test.py
+++ b/build-support/run_dist_test.py
@@ -153,8 +153,8 @@ def main():
   env['SENTRY_HOME'] = glob.glob(os.path.join(ROOT, 
"thirdparty/src/sentry-*"))[0]
   env['JAVA_HOME'] = glob.glob("/usr/lib/jvm/java-1.8.0-*")[0]
 
-  # Restore the symlinks to the chrony and subprocess binaries; tests expect to
-  # find them in same directory as the test binaries themselves.
+  # Restore the symlinks to the chrony, hms-plugin, and subprocess binaries;
+  # tests expect to find them in same directory as the test binaries 
themselves.
   for bin_path in glob.glob(os.path.join(ROOT, "build/*/bin")):
     os.symlink(os.path.join(ROOT, "thirdparty/installed/common/bin/chronyc"),
                os.path.join(bin_path, "chronyc"))
@@ -162,6 +162,10 @@ def main():
                os.path.join(bin_path, "chronyd"))
     os.symlink(
         glob.glob(os.path.join(ROOT,
+                               "java/kudu-hive/build/libs/kudu-hive*"))[0],
+        os.path.join(bin_path, "hms-plugin.jar"))
+    os.symlink(
+        glob.glob(os.path.join(ROOT,
                                
"java/kudu-subprocess/build/libs/kudu-subprocess*"))[0],
         os.path.join(bin_path, "kudu-subprocess.jar"))
 
diff --git a/src/kudu/hms/CMakeLists.txt b/src/kudu/hms/CMakeLists.txt
index 62a764b..2815f83 100644
--- a/src/kudu/hms/CMakeLists.txt
+++ b/src/kudu/hms/CMakeLists.txt
@@ -63,15 +63,16 @@ execute_process(COMMAND ln -nsf
                 "${JAVA_HOME}"
                 "${EXECUTABLE_OUTPUT_PATH}/java-home")
 
-file(GLOB DEPENDENCY_JARS
-  "${CMAKE_SOURCE_DIR}/thirdparty/installed/common/opt/hive/lib/*"
-  
"${CMAKE_SOURCE_DIR}/thirdparty/installed/common/opt/hadoop/share/hadoop/common/*"
-  
"${CMAKE_SOURCE_DIR}/thirdparty/installed/common/opt/hadoop/share/hadoop/common/lib/*")
+set(HMS_PLUGIN_JAR ${EXECUTABLE_OUTPUT_PATH}/hms-plugin.jar)
 
-add_jar(hms-plugin
-  
"${CMAKE_SOURCE_DIR}/java/kudu-hive/src/main/java/org/apache/kudu/hive/metastore/KuduMetastorePlugin.java"
-  INCLUDE_JARS "${DEPENDENCY_JARS}"
-  OUTPUT_DIR "${EXECUTABLE_OUTPUT_PATH}")
+add_custom_command(OUTPUT ${HMS_PLUGIN_JAR}
+  COMMAND ./gradlew :kudu-hive:jar ${GRADLE_FLAGS}
+  COMMAND ln -nsf
+    "${JAVA_DIR}/kudu-hive/build/libs/kudu-hive-${KUDU_VERSION_NUMBER}.jar"
+    "${HMS_PLUGIN_JAR}"
+  WORKING_DIRECTORY "${JAVA_DIR}"
+  DEPENDS init_gradle)
+add_custom_target(hms_plugin_jar DEPENDS ${HMS_PLUGIN_JAR})
 
 set(MINI_HMS_SRCS
   mini_hms.cc)
@@ -82,7 +83,7 @@ target_link_libraries(mini_hms
   krpc
   kudu_test_util
   kudu_util)
-add_dependencies(mini_hms hms-plugin)
+add_dependencies(mini_hms hms_plugin_jar)
 
 ##############################
 # hms tests
diff --git a/src/kudu/subprocess/CMakeLists.txt 
b/src/kudu/subprocess/CMakeLists.txt
index 8f284f5..a7514a4 100644
--- a/src/kudu/subprocess/CMakeLists.txt
+++ b/src/kudu/subprocess/CMakeLists.txt
@@ -37,16 +37,13 @@ target_link_libraries(subprocess_proto
 #######################################
 set(SUBPROCESS_JAR ${EXECUTABLE_OUTPUT_PATH}/kudu-subprocess.jar)
 
-# Add the EXTRA_GRADLE_FLAGS environment variable to a cmake list and calls 
`separate_arguments`.
-# This solves the problem of escaped spaces in the EXTRA_GRADLE_FLAGS 
environment variable.
-list(APPEND EXTRA_GRADLE_FLAGS $ENV{EXTRA_GRADLE_FLAGS})
-separate_arguments(EXTRA_GRADLE_FLAGS)
 add_custom_command(OUTPUT ${SUBPROCESS_JAR}
-  COMMAND ./gradlew :kudu-subprocess:jar ${EXTRA_GRADLE_FLAGS}
+  COMMAND ./gradlew :kudu-subprocess:jar ${GRADLE_FLAGS}
   COMMAND ln -nsf
     
"${JAVA_DIR}/kudu-subprocess/build/libs/kudu-subprocess-${KUDU_VERSION_NUMBER}.jar"
     "${SUBPROCESS_JAR}"
-  WORKING_DIRECTORY "${JAVA_DIR}")
+  WORKING_DIRECTORY "${JAVA_DIR}"
+  DEPENDS init_gradle)
 add_custom_target(subprocess_jar DEPENDS ${SUBPROCESS_JAR})
 
 add_library(kudu_subprocess

Reply via email to