You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2017/09/03 12:51:45 UTC
[23/42] mesos git commit: CMake: Refactored `MesosProtobuf` helper.
CMake: Refactored `MesosProtobuf` helper.
This adds some CMake-style option parsing to eliminate some duplicate
code in the MesosProtobuf helper (and associated usage).
And adds Java protobuf generation.
Review: https://reviews.apache.org/r/61301/
Review: https://reviews.apache.org/r/61307/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/44b64487
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/44b64487
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/44b64487
Branch: refs/heads/master
Commit: 44b64487cdf0ccae2e5eaa28bf12320788e64431
Parents: 7c6837c
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Sat Sep 2 15:59:21 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Sun Sep 3 05:51:07 2017 -0700
----------------------------------------------------------------------
src/CMakeLists.txt | 140 +++++++++++++-----------------------
src/cmake/MesosProtobuf.cmake | 143 ++++++++++++++++++++-----------------
2 files changed, 128 insertions(+), 155 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/44b64487/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 58b24a7..10acb12 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -19,95 +19,57 @@
include(MesosProtobuf)
# Build the protobuf structs.
-PROTOC_TO_INCLUDE_DIR(ACLS mesos/authorizer/acls)
-PROTOC_TO_INCLUDE_DIR(AGENT mesos/agent/agent)
-PROTOC_TO_INCLUDE_DIR(ALLOCATOR mesos/allocator/allocator)
-PROTOC_TO_INCLUDE_DIR(APPC_SPEC mesos/appc/spec)
-PROTOC_TO_INCLUDE_DIR(AUTHENTICATION mesos/authentication/authentication)
-PROTOC_TO_INCLUDE_DIR(AUTHORIZATION mesos/authorizer/authorizer)
-PROTOC_TO_INCLUDE_DIR(CONTAINERIZER mesos/slave/containerizer)
-PROTOC_TO_INCLUDE_DIR(DOCKER_SPEC mesos/docker/spec)
-PROTOC_TO_INCLUDE_DIR(DOCKER_V1 mesos/docker/v1)
-PROTOC_TO_INCLUDE_DIR(DOCKER_V2 mesos/docker/v2)
-PROTOC_TO_INCLUDE_DIR(EXECUTOR mesos/executor/executor)
-PROTOC_TO_INCLUDE_DIR(FETCHER mesos/fetcher/fetcher)
-PROTOC_TO_INCLUDE_DIR(HOOK mesos/module/hook)
-PROTOC_TO_INCLUDE_DIR(MAINTENANCE mesos/maintenance/maintenance)
-PROTOC_TO_INCLUDE_DIR(MASTER mesos/master/master)
-PROTOC_TO_INCLUDE_DIR(MESOS mesos/mesos)
-PROTOC_TO_INCLUDE_DIR(MODULE mesos/module/module)
-PROTOC_TO_INCLUDE_DIR(OVERSUBSCRIPTION mesos/slave/oversubscription)
-PROTOC_TO_INCLUDE_DIR(OCI_SPEC mesos/oci/spec)
-PROTOC_TO_INCLUDE_DIR(QUOTA mesos/quota/quota)
-PROTOC_TO_INCLUDE_DIR(RESOURCE_PROVIDER mesos/resource_provider/resource_provider)
-PROTOC_TO_INCLUDE_DIR(SCHEDULER mesos/scheduler/scheduler)
-PROTOC_TO_INCLUDE_DIR(STATE mesos/state/state)
-PROTOC_TO_INCLUDE_DIR(URI mesos/uri/uri)
-PROTOC_TO_INCLUDE_DIR(V1_AGENT mesos/v1/agent/agent)
-PROTOC_TO_INCLUDE_DIR(V1_ALLOCATOR mesos/v1/allocator/allocator)
-PROTOC_TO_INCLUDE_DIR(V1_EXECUTOR mesos/v1/executor/executor)
-PROTOC_TO_INCLUDE_DIR(V1_MAINTENANCE mesos/v1/maintenance/maintenance)
-PROTOC_TO_INCLUDE_DIR(V1_MASTER mesos/v1/master/master)
-PROTOC_TO_INCLUDE_DIR(V1_MESOS mesos/v1/mesos)
-PROTOC_TO_INCLUDE_DIR(V1_QUOTA mesos/v1/quota/quota)
-PROTOC_TO_INCLUDE_DIR(V1_RESOURCE_PROVIDER mesos/v1/resource_provider/resource_provider)
-PROTOC_TO_INCLUDE_DIR(V1_SCHEDULER mesos/v1/scheduler/scheduler)
-
-PROTOC_TO_SRC_DIR(INTERNAL_FLAGS messages/flags)
-PROTOC_TO_SRC_DIR(INTERNAL_LOG messages/log)
-PROTOC_TO_SRC_DIR(INTERNAL_MESSAGES messages/messages)
-PROTOC_TO_SRC_DIR(INTERNAL_STATE messages/state)
-PROTOC_TO_SRC_DIR(ISOLATOR_CNI_SPEC slave/containerizer/mesos/isolators/network/cni/spec)
-PROTOC_TO_SRC_DIR(ISOLATOR_DOCKER_VOLUME_STATE slave/containerizer/mesos/isolators/docker/volume/state)
-PROTOC_TO_SRC_DIR(PROVISIONER_DOCKER slave/containerizer/mesos/provisioner/docker/message)
-PROTOC_TO_SRC_DIR(REGISTRY master/registry)
-
-set(PUBLIC_PROTOBUF_SRC
- ${ACLS_PROTO_CC}
- ${AGENT_PROTO_CC}
- ${ALLOCATOR_PROTO_CC}
- ${APPC_SPEC_PROTO_CC}
- ${AUTHENTICATION_PROTO_CC}
- ${AUTHORIZATION_PROTO_CC}
- ${CONTAINERIZER_PROTO_CC}
- ${DOCKER_SPEC_PROTO_CC}
- ${DOCKER_V1_PROTO_CC}
- ${DOCKER_V2_PROTO_CC}
- ${EXECUTOR_PROTO_CC}
- ${FETCHER_PROTO_CC}
- ${HOOK_PROTO_CC}
- ${MAINTENANCE_PROTO_CC}
- ${MASTER_PROTO_CC}
- ${MESOS_PROTO_CC}
- ${MODULE_PROTO_CC}
- ${OCI_SPEC_PROTO_CC}
- ${OVERSUBSCRIPTION_PROTO_CC}
- ${QUOTA_PROTO_CC}
- ${RESOURCE_PROVIDER_PROTO_CC}
- ${SCHEDULER_PROTO_CC}
- ${STATE_PROTO_CC}
- ${URI_PROTO_CC}
- ${V1_AGENT_PROTO_CC}
- ${V1_ALLOCATOR_PROTO_CC}
- ${V1_EXECUTOR_PROTO_CC}
- ${V1_MAINTENANCE_PROTO_CC}
- ${V1_MASTER_PROTO_CC}
- ${V1_MESOS_PROTO_CC}
- ${V1_QUOTA_PROTO_CC}
- ${V1_RESOURCE_PROVIDER_PROTO_CC}
- ${V1_SCHEDULER_PROTO_CC}
- )
-
-set(INTERNAL_PROTOBUF_SRC
- ${INTERNAL_FLAGS_PROTO_CC}
- ${INTERNAL_LOG_PROTO_CC}
- ${INTERNAL_MESSAGES_PROTO_CC}
- ${INTERNAL_STATE_PROTO_CC}
- ${ISOLATOR_CNI_SPEC_PROTO_CC}
- ${ISOLATOR_DOCKER_VOLUME_STATE_PROTO_CC}
- ${PROVISIONER_DOCKER_PROTO_CC}
- ${REGISTRY_PROTO_CC}
- )
+#
+# NOTE: `PROTOC_GENERATE` will list append to `PUBLIC_PROTOBUF_SRC`,
+# `INTERNAL_PROTOBUF_SRC`, and/or `JAVA_PROTOBUF_SRC` depending on the
+# `INTERNAL` and `JAVA` options.
+set(PUBLIC_PROTOBUF_SRC "")
+PROTOC_GENERATE(TARGET mesos/agent/agent)
+PROTOC_GENERATE(TARGET mesos/allocator/allocator)
+PROTOC_GENERATE(TARGET mesos/appc/spec)
+PROTOC_GENERATE(TARGET mesos/authentication/authentication)
+PROTOC_GENERATE(TARGET mesos/authorizer/acls)
+PROTOC_GENERATE(TARGET mesos/authorizer/authorizer)
+PROTOC_GENERATE(TARGET mesos/docker/spec)
+PROTOC_GENERATE(TARGET mesos/docker/v1)
+PROTOC_GENERATE(TARGET mesos/docker/v2)
+PROTOC_GENERATE(TARGET mesos/maintenance/maintenance)
+PROTOC_GENERATE(TARGET mesos/master/master)
+PROTOC_GENERATE(TARGET mesos/module/hook)
+PROTOC_GENERATE(TARGET mesos/module/module)
+PROTOC_GENERATE(TARGET mesos/oci/spec)
+PROTOC_GENERATE(TARGET mesos/quota/quota)
+PROTOC_GENERATE(TARGET mesos/resource_provider/resource_provider)
+PROTOC_GENERATE(TARGET mesos/slave/containerizer)
+PROTOC_GENERATE(TARGET mesos/slave/oversubscription)
+PROTOC_GENERATE(TARGET mesos/state/state)
+PROTOC_GENERATE(TARGET mesos/uri/uri)
+
+# NOTE: The JAVA option is a noop if Java is disabled.
+set(JAVA_PROTOBUF_SRC "")
+PROTOC_GENERATE(JAVA TARGET mesos/executor/executor)
+PROTOC_GENERATE(JAVA TARGET mesos/fetcher/fetcher)
+PROTOC_GENERATE(JAVA TARGET mesos/mesos)
+PROTOC_GENERATE(JAVA TARGET mesos/scheduler/scheduler)
+PROTOC_GENERATE(JAVA TARGET mesos/v1/agent/agent)
+PROTOC_GENERATE(JAVA TARGET mesos/v1/allocator/allocator)
+PROTOC_GENERATE(JAVA TARGET mesos/v1/executor/executor)
+PROTOC_GENERATE(JAVA TARGET mesos/v1/maintenance/maintenance)
+PROTOC_GENERATE(JAVA TARGET mesos/v1/master/master)
+PROTOC_GENERATE(JAVA TARGET mesos/v1/mesos)
+PROTOC_GENERATE(JAVA TARGET mesos/v1/quota/quota)
+PROTOC_GENERATE(JAVA TARGET mesos/v1/resource_provider/resource_provider)
+PROTOC_GENERATE(JAVA TARGET mesos/v1/scheduler/scheduler)
+
+set(INTERNAL_PROTOBUF_SRC "")
+PROTOC_GENERATE(INTERNAL TARGET messages/flags)
+PROTOC_GENERATE(INTERNAL TARGET messages/log)
+PROTOC_GENERATE(INTERNAL TARGET messages/messages)
+PROTOC_GENERATE(INTERNAL TARGET messages/state)
+PROTOC_GENERATE(INTERNAL TARGET slave/containerizer/mesos/isolators/network/cni/spec)
+PROTOC_GENERATE(INTERNAL TARGET slave/containerizer/mesos/isolators/docker/volume/state)
+PROTOC_GENERATE(INTERNAL TARGET slave/containerizer/mesos/provisioner/docker/message)
+PROTOC_GENERATE(INTERNAL TARGET master/registry)
# BUILD PROTOBUFS.
http://git-wip-us.apache.org/repos/asf/mesos/blob/44b64487/src/cmake/MesosProtobuf.cmake
----------------------------------------------------------------------
diff --git a/src/cmake/MesosProtobuf.cmake b/src/cmake/MesosProtobuf.cmake
index e30ad84..533455e 100644
--- a/src/cmake/MesosProtobuf.cmake
+++ b/src/cmake/MesosProtobuf.cmake
@@ -14,89 +14,100 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# PROTO_TO_INCLUDE_DIR is a convenience function that will: (1) compile .proto
-# files found in the Mesos public-facing `include/` directory, (2) place the
-# generated files in the build folder, but with an identical directory
-# structure, and (3) export variables holding the fully qualified path to the
-# generated files, based on a name structure the user specifies with the
-# `BASE_NAME` and `BASE_DIR_STRUCTURE` parameters.
+# PROTOC_GENERATE is a convenience function that will:
+# (1) Compile .proto files found in the Mesos public-facing `include/`
+# directory, or with the option `INTERNAL` the Mesos `src/` directory.
+# The `JAVA` option flag will generate the Java Protobuf files to
+# `src/java/generated`.
+# (2) Place the generated files in the build folder, but with an identical
+# directory structure.
+# (3) Append to list variables `PUBLIC_PROTOBUF_SRC`, `INTERNAL_PROTOBUF_SRC`,
+# and `JAVA_PROTOBUF_SRC` (depending on options passed in) the fully
+# qualified path to the generated files. This export is a *side effect*
+# and modifies the variables in the parent scope.
#
-# For example, if suppose wish to compile `include/mesos/mesos.proto`. We might
-# pass in the following values for the parameters:
+# For example, if suppose wish to compile `include/mesos/mesos.proto`,
+# we might pass in the following values for the parameters:
#
-# BASE_NAME: MESOS (i.e., basis for the exported var names)
-# BASE_DIR_STRUCTURE: mesos/mesos (i.e., where `mesos/mesos.proto` would be
-# the relative path to the .proto file, we'd
-# use this "root name" to generate files
-# like `mesos/mesos.pb.cc`
+# PROTOC_GENERATE(TARGET mesos/mesos)
+#
+# Where `mesos/mesos.proto` would be the relative path to the .proto file,
+# we'd use this "root name" to generate files like `mesos/mesos.pb.cc`
#
# In this case, this function would:
#
-# (1) compile the `include/mesos/mesos.proto`, which would generate the files
-# `build/include/mesos/mesos.pb.h` and `build/include/mesos/mesos.pb.cc`
-# (2) export the following variables, based on the `BASE_NAME` parameter
-# (a) MESOS_PROTO: ${MESOS_ROOT}/include/mesos/mesos.proto
-# (b) MESOS_PROTO_CC: ${MESOS_ROOT}/build/include/mesos/mesos.pb.cc
-# (a) MESOS_PROTO_H: ${MESOS_ROOT}/build/include/mesos/mesos.pb.h
-function(PROTOC_TO_INCLUDE_DIR BASE_NAME BASE_DIR_STRUCTURE)
+# (1) Compile the `include/mesos/mesos.proto`, which would generate the files
+# `build/include/mesos/mesos.pb.h` and `build/include/mesos/mesos.pb.cc`.
+# (2) Append the path `${MESOS_ROOT}/build/include/mesos/mesos.pb.cc` to
+# the parent scope variable `PUBLIC_PROTOBUF_SRC`.
+#
+# NOTE: The `protoc` binary used here is an imported executable target from
+# `3rdparty/CMakeLists.txt`. However, this is not strictly necessary, and
+# `protoc` could be supplied in `PATH`.
+function(PROTOC_GENERATE)
+ set(options OPTIONAL INTERNAL JAVA)
+ set(oneValueArgs TARGET)
+ cmake_parse_arguments(PROTOC "${options}" "${oneValueArgs}" "" ${ARGN})
+
+ if (PROTOC_INTERNAL)
+ set(CPP_OUT ${MESOS_BIN_SRC_DIR})
+ else ()
+ set(CPP_OUT ${MESOS_BIN_INCLUDE_DIR})
+ endif ()
- set(TO_INCLUDE_DIR
+ set(PROTOC_OPTIONS
-I${MESOS_PUBLIC_INCLUDE_DIR}
-I${MESOS_SRC_DIR}
- --cpp_out=${MESOS_BIN_INCLUDE_DIR})
+ --cpp_out=${CPP_OUT})
- # Names of variables we will be publicly exporting.
- set(PROTO_VAR ${BASE_NAME}_PROTO) # e.g., MESOS_PROTO
- set(CC_VAR ${BASE_NAME}_PROTO_CC) # e.g., MESOS_PROTO_CC
- set(H_VAR ${BASE_NAME}_PROTO_H) # e.g., MESOS_PROTO_H
+ if (PROTOC_JAVA AND HAS_JAVA)
+ list(APPEND PROTOC_OPTIONS
+ --java_out=${MESOS_BIN_SRC_DIR}/java/generated)
+ endif ()
- # Fully qualified paths for the input .proto files and the output C files.
- set(PROTO ${MESOS_PUBLIC_INCLUDE_DIR}/${BASE_DIR_STRUCTURE}.proto)
- set(CC ${MESOS_BIN_INCLUDE_DIR}/${BASE_DIR_STRUCTURE}.pb.cc)
- set(H ${MESOS_BIN_INCLUDE_DIR}/${BASE_DIR_STRUCTURE}.pb.h)
+ # Fully qualified paths for the input .proto files and the output C file.
+ if (PROTOC_INTERNAL) # to src dir
+ set(PROTO ${MESOS_SRC_DIR}/${PROTOC_TARGET}.proto)
+ else () # to public include dir
+ set(PROTO ${MESOS_PUBLIC_INCLUDE_DIR}/${PROTOC_TARGET}.proto)
+ endif ()
- # Export variables holding the target filenames.
- set(${PROTO_VAR} ${PROTO} PARENT_SCOPE) # e.g., mesos/mesos.proto
- set(${CC_VAR} ${CC} PARENT_SCOPE) # e.g., mesos/mesos.pb.cc
- set(${H_VAR} ${H} PARENT_SCOPE) # e.g., mesos/mesos.pb.h
-
- # Compile the .proto file.
- ADD_CUSTOM_COMMAND(
- OUTPUT ${CC} ${H}
- COMMAND ${PROTOC} ${TO_INCLUDE_DIR} ${PROTO}
- DEPENDS make_bin_include_dir ${PROTO}
- WORKING_DIRECTORY ${MESOS_BIN})
-endfunction()
+ set(CC ${CPP_OUT}/${PROTOC_TARGET}.pb.cc)
-# PROTO_TO_SRC_DIR is similar to `PROTO_TO_INCLUDE_DIR`, except it acts on the
-# Mesos `src/` directory instead of the public-facing `include/` directory (see
-# documentation for `PROTO_TO_INCLUDE_DIR` for details).
-function(PROTOC_TO_SRC_DIR BASE_NAME BASE_DIR_STRUCTURE)
+ # Fully qualified path for the Java file.
+ if (PROTOC_JAVA AND HAS_JAVA)
+ get_filename_component(PROTOC_JAVA_DIR ${PROTOC_TARGET} DIRECTORY)
+ set(JAVA ${MESOS_BIN_SRC_DIR}/java/generated/org/apache/${PROTOC_JAVA_DIR}/Protos.java)
+ endif ()
- set(TO_SRC_DIR
- -I${MESOS_PUBLIC_INCLUDE_DIR}
- -I${MESOS_SRC_DIR}
- --cpp_out=${MESOS_BIN_SRC_DIR})
+ # Export variables holding the target filenames.
+ if (PROTOC_INTERNAL)
+ list(APPEND INTERNAL_PROTOBUF_SRC ${CC})
+ set(INTERNAL_PROTOBUF_SRC ${INTERNAL_PROTOBUF_SRC} PARENT_SCOPE)
+ else ()
+ list(APPEND PUBLIC_PROTOBUF_SRC ${CC})
+ set(PUBLIC_PROTOBUF_SRC ${PUBLIC_PROTOBUF_SRC} PARENT_SCOPE)
+ endif ()
- # Names of variables we will be publicly exporting.
- set(PROTO_VAR ${BASE_NAME}_PROTO) # e.g., MESOS_PROTO
- set(CC_VAR ${BASE_NAME}_PROTO_CC) # e.g., MESOS_PROTO_CC
- set(H_VAR ${BASE_NAME}_PROTO_H) # e.g., MESOS_PROTO_H
+ if (PROTOC_JAVA AND HAS_JAVA)
+ list(APPEND JAVA_PROTOBUF_SRC ${JAVA})
+ set(JAVA_PROTOBUF_SRC ${JAVA_PROTOBUF_SRC} PARENT_SCOPE)
+ endif ()
- # Fully qualified paths for the input .proto files and the output C files.
- set(PROTO ${MESOS_SRC_DIR}/${BASE_DIR_STRUCTURE}.proto)
- set(CC ${MESOS_BIN_SRC_DIR}/${BASE_DIR_STRUCTURE}.pb.cc)
- set(H ${MESOS_BIN_SRC_DIR}/${BASE_DIR_STRUCTURE}.pb.h)
+ if (PROTOC_INTERNAL)
+ set(PROTOC_DEPENDS make_bin_src_dir)
+ else ()
+ set(PROTOC_DEPENDS make_bin_include_dir)
+ endif ()
- # Export variables holding the target filenames.
- set(${PROTO_VAR} ${PROTO} PARENT_SCOPE) # e.g., mesos/mesos.proto
- set(${CC_VAR} ${CC} PARENT_SCOPE) # e.g., mesos/mesos.pb.cc
- set(${H_VAR} ${H} PARENT_SCOPE) # e.g., mesos/mesos.pb.h
+ if (PROTOC_JAVA AND HAS_JAVA)
+ list(APPEND PROTOC_DEPENDS make_bin_java_dir)
+ endif ()
# Compile the .proto file.
- ADD_CUSTOM_COMMAND(
- OUTPUT ${CC} ${H}
- COMMAND ${PROTOC} ${TO_SRC_DIR} ${PROTO}
- DEPENDS make_bin_src_dir ${PROTO}
+ add_custom_command(
+ OUTPUT ${CC} ${H} ${JAVA}
+ COMMAND protoc ${PROTOC_OPTIONS} ${PROTO}
+ DEPENDS ${PROTOC_DEPENDS} ${PROTO}
WORKING_DIRECTORY ${MESOS_BIN})
endfunction()