Repository: mesos
Updated Branches:
  refs/heads/master ddab02d76 -> bffa9f3c5


Added options to build the Python CLI and run unit tests.

An update of the discarded review /r/52543.

Works with Autotools and CMake.

Review: https://reviews.apache.org/r/64211/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/bffa9f3c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/bffa9f3c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/bffa9f3c

Branch: refs/heads/master
Commit: bffa9f3c5b8dc5ed27fc4f079c0376c2a64ea042
Parents: ddab02d
Author: Armand Grillet <agril...@mesosphere.io>
Authored: Thu Apr 12 06:10:28 2018 -0700
Committer: Kevin Klues <klue...@gmail.com>
Committed: Thu Apr 12 06:10:28 2018 -0700

----------------------------------------------------------------------
 CMakeLists.txt                          |  8 ++-
 cmake/CompilationConfigure.cmake        | 54 +++++++++++++++++-
 configure.ac                            | 38 +++++++++++++
 docs/configuration/cmake.md             |  8 +++
 src/CMakeLists.txt                      |  3 +-
 src/Makefile.am                         | 42 ++++++++++++--
 src/python/cli_new/CMakeLists.txt       | 83 ++++++++++++++++++++++++++++
 src/python/cli_new/tests/CMakeLists.txt | 32 +++++++++++
 8 files changed, 260 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/bffa9f3c/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6702f02..7167b5e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -57,7 +57,13 @@ add_subdirectory(src)
 # TESTS.
 ########
 add_custom_target(check COMMAND ctest -V -C $<CONFIG> DEPENDS tests)
-add_custom_target(tests DEPENDS stout-tests libprocess-tests mesos-tests)
+add_custom_target(
+  tests
+  DEPENDS stout-tests libprocess-tests mesos-tests)
+
+if (ENABLE_NEW_CLI)
+  add_dependencies(tests cli-tests)
+endif ()
 
 # PACKAGING.
 ############

http://git-wip-us.apache.org/repos/asf/mesos/blob/bffa9f3c/cmake/CompilationConfigure.cmake
----------------------------------------------------------------------
diff --git a/cmake/CompilationConfigure.cmake b/cmake/CompilationConfigure.cmake
index 3cb072d..1c327ac 100644
--- a/cmake/CompilationConfigure.cmake
+++ b/cmake/CompilationConfigure.cmake
@@ -99,7 +99,59 @@ option(
   "Build libprocess with LIFO fixed size semaphore."
   FALSE)
 
-option(ENABLE_JAVA
+option(
+  ENABLE_NEW_CLI
+  "Build the new CLI instead of the old one."
+  FALSE)
+
+if (ENABLE_NEW_CLI)
+  find_package(PythonInterp)
+  find_package(PythonLibs)
+
+  if (NOT PYTHON_LIBRARY)
+    message(
+      FATAL_ERROR
+      "Python not found.\n"
+      "The new CLI requires Python version 2.6 or 2.7 in order to build.\n"
+      "Your Python version is ${PYTHONLIBS_VERSION_STRING}.\n"
+      "You may wish to set the PYTHON environment variable to an "
+      "appropriate value if Python is not installed in your PATH.")
+  endif ()
+
+  if (${PYTHONLIBS_VERSION_STRING} VERSION_LESS "2.6.0")
+    message(
+      FATAL_ERROR
+      "Python version too old.\n"
+      "The new CLI requires Python version 2.6 or 2.7 in order to build.\n"
+      "Your Python version is ${PYTHONLIBS_VERSION_STRING}.\n"
+      "You may wish to set the PYTHON environment variable to an "
+      "appropriate value to assure the right Python executable is found.")
+  endif ()
+
+  if (${PYTHONLIBS_VERSION_STRING} VERSION_EQUAL "3.0.0" OR
+      ${PYTHONLIBS_VERSION_STRING} VERSION_GREATER "3.0.0")
+    message(
+      FATAL_ERROR
+      "Python version too new.\n"
+      "The new CLI requires Python version 2.6 or 2.7 in order to build.\n"
+      "Your Python version is ${PYTHONLIBS_VERSION_STRING}.\n"
+      "You may wish to set the PYTHON environment variable to an "
+      "appropriate value to assure the right Python executable is found.")
+  endif ()
+
+  find_program(VIRTUALENV virtualenv)
+  if (NOT VIRTUALENV)
+    message(
+      FATAL_ERROR
+      "Cannot find virtualenv.\n"
+      "The new CLI requires 'virtualenv' be installed as part of your "
+      "Python ${PYTHONLIBS_VERSION_STRING} installation.\n"
+      "You may wish to install it via 'pip install virtualenv'.")
+  endif ()
+endif ()
+
+option(
+  ENABLE_JAVA
   "Build Java components. Warning: this is SLOW."
   FALSE)
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/bffa9f3c/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index f0f901f..4c4085c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -237,6 +237,11 @@ AC_ARG_ENABLE([lock_free_run_queue],
                              [enables the lock-free run queue in libprocess]),
                              [], [enable_lock_free_run_queue=no])
 
+AC_ARG_ENABLE([new_cli],
+              AS_HELP_STRING([--enable-new-cli],
+                             [Build the new CLI instead of the old one, 
default:
+              [], [enable_new_cli=no]]))
+
 AC_ARG_ENABLE([libtool-wrappers],
               AS_HELP_STRING([--disable-libtool-wrappers],
                              [Directly create binaries instead of libtool
@@ -2439,6 +2444,39 @@ correct if you're already doing this.
   has_python=yes
 fi
 
+AS_IF([test "x$enable_new_cli" = "xyes"], [
+  AM_PATH_PYTHON([2.6])
+
+  AX_COMPARE_VERSION([$PYTHON_VERSION], [gt], [2.7],
+    AC_MSG_ERROR([Python version too new
+-------------------------------------------------------------------
+The new CLI requires Python version 2.6 or 2.7 in order to build.
+Your Python version is $PYTHON_VERSION.
+
+You may wish to set the PYTHON environment variable to an
+appropriate value to assure the right Python executable is found.
+-------------------------------------------------------------------
+  ]))
+
+  AC_CHECK_PROG([VIRTUALENV_CHECK], [virtualenv], [yes])
+  AS_IF([test "x$VIRTUALENV_CHECK" = "xyes"],, [
+     AC_MSG_ERROR([Cannot find virtualenv
+-------------------------------------------------------------------
+The new CLI requires 'virtualenv' be installed as part of your
+Python $PYTHON_VERSION installation.
+
+You may wish to install it via 'pip install virtualenv'.
+-------------------------------------------------------------------
+  ])])
+])
+
+AC_MSG_CHECKING([whether to enable new CLI])
+AS_IF([test "x$enable_new_cli" = "xyes"],
+      [AC_MSG_RESULT([yes])],
+      [AC_MSG_RESULT([no])])
+
+AM_CONDITIONAL([ENABLE_NEW_CLI], [test "x$enable_new_cli" = "xyes"])
+
 AM_CONDITIONAL([HAS_PYTHON], [test "x$has_python" = "xyes"])
 
 AM_CONDITIONAL([WITH_BUNDLED_SETUPTOOLS],

http://git-wip-us.apache.org/repos/asf/mesos/blob/bffa9f3c/docs/configuration/cmake.md
----------------------------------------------------------------------
diff --git a/docs/configuration/cmake.md b/docs/configuration/cmake.md
index 1e34657..74abe65 100644
--- a/docs/configuration/cmake.md
+++ b/docs/configuration/cmake.md
@@ -141,6 +141,14 @@ See more information in the [CMake 
documentation](../cmake.md).
   </tr>
   <tr>
     <td>
+      -DENABLE_NEW_CLI=(TRUE|FALSE)
+    </td>
+    <td>
+      Build the new CLI instead of the old one. [default=FALSE]
+    </td>
+  </tr>
+  <tr>
+    <td>
       -D3RDPARTY_DEPENDENCIES=[path_or_url]
     </td>
     <td>

http://git-wip-us.apache.org/repos/asf/mesos/blob/bffa9f3c/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6fc45db..ac176d1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -523,7 +523,6 @@ if (ENABLE_PRECOMPILED_HEADERS)
   cotire(mesos)
 endif ()
 
-
 # BUILD THE MESOS EXECUTABLES.
 ##############################
 add_subdirectory(checks)
@@ -534,6 +533,7 @@ add_subdirectory(launcher)
 add_subdirectory(local)
 add_subdirectory(log)
 add_subdirectory(master)
+add_subdirectory(python/cli_new)
 add_subdirectory(slave)
 add_subdirectory(slave/containerizer/mesos)
 add_subdirectory(usage)
@@ -542,3 +542,4 @@ add_subdirectory(usage)
 # BUILD THE MESOS TESTS.
 ########################
 add_subdirectory(tests)
+add_subdirectory(python/cli_new/tests)

http://git-wip-us.apache.org/repos/asf/mesos/blob/bffa9f3c/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 257ff0e..b590928 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1749,11 +1749,6 @@ mesos_log_SOURCES = log/main.cpp
 mesos_log_CPPFLAGS = $(MESOS_CPPFLAGS)
 mesos_log_LDADD = libmesos.la $(LDADD)
 
-bin_PROGRAMS += mesos
-mesos_SOURCES = cli/mesos.cpp
-mesos_CPPFLAGS = $(MESOS_CPPFLAGS)
-mesos_LDADD = libmesos.la $(LDADD)
-
 bin_PROGRAMS += mesos-execute
 mesos_execute_SOURCES = cli/execute.cpp
 mesos_execute_CPPFLAGS = $(MESOS_CPPFLAGS)
@@ -1764,12 +1759,45 @@ mesos_resolve_SOURCES = cli/resolve.cpp
 mesos_resolve_CPPFLAGS = $(MESOS_CPPFLAGS)
 mesos_resolve_LDADD = libmesos.la $(LDADD)
 
+bin_PROGRAMS += mesos
+if ENABLE_NEW_CLI
+MESOS_CLI_SRCDIR = $(srcdir)/python/cli_new
+MESOS_CLI_BUILDDIR = $(builddir)/cli
+MESOS_CLI_HIDDEN_IMPORTS =                                     \
+       $(patsubst %, --hidden-import cli.plugins.%,            \
+               $(notdir $(shell find                           \
+                          $(MESOS_CLI_SRCDIR)/lib/cli/plugins  \
+                            -mindepth 1 -maxdepth 1 -type d)))
+
+mesos: $(shell find $(MESOS_CLI_SRCDIR) | grep -v .virtualenv)
+       @echo "Building the CLI ..."
+       VIRTUALENV_DIRECTORY=$(builddir)/.virtualenv    \
+       $(MESOS_CLI_SRCDIR)/bootstrap &&                \
+       echo "VERSION = \"$(PACKAGE_VERSION)\""         \
+               > $(MESOS_CLI_BUILDDIR)/version.py &&   \
+       source $(builddir)/.virtualenv/bin/activate &&  \
+       python -m PyInstaller -p $(MESOS_CLI_SRCDIR)/lib\
+               $(MESOS_CLI_HIDDEN_IMPORTS)             \
+               --specpath $(MESOS_CLI_BUILDDIR)        \
+               --workpath $(MESOS_CLI_BUILDDIR)/work   \
+               --distpath $(builddir)                  \
+               --name $(@)                             \
+               --noconfirm                             \
+               --onefile                               \
+               $(MESOS_CLI_SRCDIR)/bin/main.py
+check_PROGRAMS += mesos
+else
+mesos_SOURCES = cli/mesos.cpp
+mesos_CPPFLAGS = $(MESOS_CPPFLAGS)
+mesos_LDADD = libmesos.la $(LDADD)
+
 # Need to distribute and install mesos-*.
 dist_bin_SCRIPTS +=                                                    \
   cli/mesos-cat                                                                
\
   cli/mesos-ps                                                         \
   cli/mesos-scp                                                                
\
   cli/mesos-tail
+endif
 
 # Need to distribute/install webui javascript. We use 'pkgdatadir'
 # instead of 'datadir' as the install directory so we get the
@@ -2788,6 +2816,10 @@ uninstall-hook:
 # http://lists.gnu.org/archive/html/automake/2013-01/msg00051.html
 check-local: tests
        $(TEST_DRIVER) ./mesos-tests
+if ENABLE_NEW_CLI
+       @source $(builddir)/.virtualenv/bin/activate;   \
+        $(MESOS_CLI_SRCDIR)/bin/mesos-cli-tests
+endif
 
 if INSTALL_TESTS
 # If we enabled test installation, we can run the tests from the

http://git-wip-us.apache.org/repos/asf/mesos/blob/bffa9f3c/src/python/cli_new/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/python/cli_new/CMakeLists.txt 
b/src/python/cli_new/CMakeLists.txt
new file mode 100644
index 0000000..ef8da70
--- /dev/null
+++ b/src/python/cli_new/CMakeLists.txt
@@ -0,0 +1,83 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+# THE PYTHON CLI EXECUTABLE.
+#################################
+
+if (ENABLE_NEW_CLI)
+  set(CLI_FILES
+    bin/main.py
+    bin/settings.py
+    lib/cli/__init__.py
+    lib/cli/config.py
+    lib/cli/constants.py
+    lib/cli/docopt.py
+    lib/cli/exceptions.py
+    lib/cli/http.py
+    lib/cli/util.py
+    lib/cli/plugins/__init__.py
+    lib/cli/plugins/base.py
+    lib/cli/plugins/agent/__init__.py
+    lib/cli/plugins/agent/main.py
+    lib/cli/plugins/config/__init__.py
+    lib/cli/plugins/config/main.py
+    lib/cli/plugins/task/__init__.py
+    lib/cli/plugins/task/main.py)
+
+  # We find the hidden imports in the CLI and save them in a file.
+  add_custom_command(
+    OUTPUT cli_hidden_imports.txt
+    COMMAND find ${CMAKE_CURRENT_SOURCE_DIR}/lib/cli/plugins
+      -mindepth 1 -maxdepth 1 -type d | xargs -I{} basename {}
+      > cli_hidden_imports.txt
+    COMMAND sed -i -e 's/^/--hidden-import cli.plugins./' 
cli_hidden_imports.txt
+    DEPENDS lib/cli/plugins/)
+
+  add_custom_target(cli_hidden_imports DEPENDS cli_hidden_imports.txt)
+
+  # Creating the virtual environment required by the CLI.
+  add_custom_command(
+    OUTPUT .virtualenv/bin/activate
+    COMMAND VIRTUALENV_DIRECTORY=${CMAKE_CURRENT_BINARY_DIR}/.virtualenv
+      ${CMAKE_CURRENT_SOURCE_DIR}/bootstrap
+    DEPENDS bootstrap pip-requirements.txt)
+
+  add_custom_target(cli_virtualenv DEPENDS .virtualenv/bin/activate)
+
+  # We create a file to make sure that the commands run in the same 
environment.
+  # The commands run are running the bootstrap script for the CLI, loading the
+  # CLI hidden imports, creating a version file, activating the virtual
+  # environment, and using pyinstaller to create the binary.
+  file(
+    WRITE ${CMAKE_CURRENT_BINARY_DIR}/build_cli.sh
+    "set -e
+    MESOS_CLI_HIDDEN_IMPORTS=`cat cli_hidden_imports.txt`
+    echo \"VERSION = \\\"${PACKAGE_VERSION}\\\"\"                           \
+      > ${CMAKE_BINARY_DIR}/src/cli/version.py
+    source .virtualenv/bin/activate
+    python -m PyInstaller -p ${CMAKE_CURRENT_SOURCE_DIR}/lib                \
+      $MESOS_CLI_HIDDEN_IMPORTS --specpath ${CMAKE_BINARY_DIR}/src/cli      \
+      --workpath ${CMAKE_BINARY_DIR}/src/cli/work                           \
+      --distpath ${CMAKE_BINARY_DIR}/src\ --name mesos --noconfirm --onefile\
+      ${CMAKE_CURRENT_SOURCE_DIR}/bin/main.py")
+
+  add_custom_command(
+    OUTPUT ${CMAKE_BINARY_DIR}/src/mesos
+    COMMAND bash build_cli.sh
+    DEPENDS cli_hidden_imports cli_virtualenv ${CLI_FILES})
+
+  add_custom_target(cli ALL DEPENDS ${CMAKE_BINARY_DIR}/src/mesos)
+endif ()

http://git-wip-us.apache.org/repos/asf/mesos/blob/bffa9f3c/src/python/cli_new/tests/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/python/cli_new/tests/CMakeLists.txt 
b/src/python/cli_new/tests/CMakeLists.txt
new file mode 100644
index 0000000..19119d1
--- /dev/null
+++ b/src/python/cli_new/tests/CMakeLists.txt
@@ -0,0 +1,32 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+# THE PYTHON CLI TESTS.
+#################################
+if (ENABLE_NEW_CLI)
+  # We create a file so that the commands will run in the same environment.
+  file(
+    WRITE ${CMAKE_CURRENT_BINARY_DIR}/run_cli_tests.sh
+    "set -e
+    source ${CMAKE_CURRENT_BINARY_DIR}/../.virtualenv/bin/activate
+    ${CMAKE_CURRENT_SOURCE_DIR}/../bin/mesos-cli-tests")
+
+    add_custom_target(
+      cli-tests
+      DEPENDS mesos-agent mesos-execute mesos-master cli_virtualenv)
+
+    add_test(NAME CLITests COMMAND bash run_cli_tests.sh)
+endif ()

Reply via email to