You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by GitBox <gi...@apache.org> on 2022/07/12 02:43:58 UTC

[GitHub] [incubator-kvrocks] tisonkun commented on a diff in pull request #725: replace shell scripts with x.py

tisonkun commented on code in PR #725:
URL: https://github.com/apache/incubator-kvrocks/pull/725#discussion_r918498320


##########
x.py:
##########
@@ -0,0 +1,146 @@
+#!/usr/bin/env python3
+
+# 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.
+
+import glob
+import os
+import pathlib
+import click
+import semver
+import subprocess
+import sys
+
+CMAKE_REQUIRE_VERSION = "3.13.0"
+CONTEXT_SETTINGS = {
+    "help_option_names": ['-h', '--help'],
+}
+
+def run(args, msg=None, **kwargs):
+    sys.stdout.flush()
+    p = subprocess.Popen(args, **kwargs)
+    code = p.wait()
+    if code != 0:
+        err = f"""
+failed to run: {args}
+exit with code: {code}
+error message: {msg}
+"""
+        raise RuntimeError(err)
+    else:
+        return p.stdout
+
+def find_command(command, msg=None):
+    output = run(["bash", "-c", f"command -v {command}"], stdout=subprocess.PIPE)
+    path = output.read().decode().strip()
+    run(["test", "-x", path], msg=msg)
+    return path
+
+@click.group(context_settings=CONTEXT_SETTINGS)
+def cli():
+    pass
+
+@click.command()
+@click.argument('dir', default='build', metavar='BUILD_DIR')
+@click.option('-j', '--jobs', default=4, show_default=True, metavar='N', help='execute N build jobs concurrently')
+@click.option('--ghproxy', default=False, help='use https://ghproxy.com to fetch dependencies', is_flag=True)
+@click.option('--ninja', default=False, help='use Ninja to build kvrocks', is_flag=True)
+@click.option('--unittest', default=False, help='build unittest target', is_flag=True)
+@click.option('--compiler', default='auto', show_default=True, type=click.Choice(('auto', 'gcc', 'clang')), help='compiler used to build kvrocks')
+@click.option('-D', multiple=True, metavar='key=value', help='extra CMake definitions')
+def build(dir, jobs, ghproxy, ninja, unittest, compiler, d):
+    """
+    Build executables to BUILD_DIR [default: build]
+    """
+
+    basedir = pathlib.Path(__file__).parent.absolute()
+
+    find_command("autoconf", msg="autoconf is required to build jemalloc")
+    cmake = find_command("cmake", msg="CMake is required")
+
+    output = run([cmake, "-version"], stdout=subprocess.PIPE)
+    output = run(["head", "-n", "1"], stdin=output, stdout=subprocess.PIPE)
+    output = run(["sed", "s/[^0-9.]*//g"], stdin=output, stdout=subprocess.PIPE)
+    cmake_version = output.read().decode().strip()
+    if semver.compare(cmake_version, CMAKE_REQUIRE_VERSION) < 0:
+        raise RuntimeError(f"CMake {CMAKE_REQUIRE_VERSION} or higher is required, got: {cmake_version}")

Review Comment:
   I don't download CMake here if it's missing. Since it causes issue like https://github.com/apache/incubator-kvrocks/discussions/712 and I'd prefer to let the user explicit download such significant and complex configurable dependency.
   
   Anyway, if we don't automatically download autoconf, why CMake?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org