martinzink commented on code in PR #1681:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1681#discussion_r1513040448


##########
bootstrap/package_manager.py:
##########
@@ -0,0 +1,259 @@
+# 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 os
+import platform
+import subprocess
+import sys
+from typing import Dict, Set
+
+from distro import distro
+
+
+def _query_yes_no(question: str, no_confirm: bool) -> bool:
+    valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
+
+    if no_confirm:
+        print("Running {} with noconfirm".format(question))
+        return True
+    while True:
+        print("{} [y/n]".format(question), end=' ', flush=True)
+        choice = input().lower()
+        if choice in valid:
+            return valid[choice]
+        else:
+            print("Please respond with 'yes' or 'no' " "(or 'y' or 'n').")
+
+
+def _run_command_with_confirm(command: str, no_confirm: bool) -> bool:
+    if _query_yes_no("Running {}".format(command), no_confirm):
+        return os.system(command) == 0
+
+
+class PackageManager(object):
+    def __init__(self, no_confirm):
+        self.no_confirm = no_confirm
+        pass
+
+    def install(self, dependencies: Dict[str, Set[str]]) -> bool:
+        raise Exception("NotImplementedException")
+
+    def install_compiler(self) -> str:
+        raise Exception("NotImplementedException")
+
+    def _install(self, dependencies: Dict[str, Set[str]], replace_dict: 
Dict[str, Set[str]], install_cmd: str) -> bool:
+        dependencies.update({k: v for k, v in replace_dict.items() if k in 
dependencies})
+        dependencies = self._filter_out_installed_packages(dependencies)
+        dependencies_str = " ".join(str(value) for value_set in 
dependencies.values() for value in value_set)
+        if not dependencies_str or dependencies_str.isspace():
+            return True
+        return _run_command_with_confirm(f"{install_cmd} {dependencies_str}", 
self.no_confirm)
+
+    def _get_installed_packages(self) -> Set[str]:
+        raise Exception("NotImplementedException")
+
+    def _filter_out_installed_packages(self, dependencies: Dict[str, 
Set[str]]):
+        installed_packages = self._get_installed_packages()
+        filtered_packages = {k: (v - installed_packages) for k, v in 
dependencies.items()}
+        for installed_package in installed_packages:
+            filtered_packages.pop(installed_package, None)
+        return filtered_packages
+
+    def run_cmd(self, cmd: str) -> bool:
+        result = subprocess.run(f"{cmd}", shell=True, text=True)
+        return result.returncode == 0
+
+
+class BrewPackageManager(PackageManager):
+    def __init__(self, no_confirm):
+        PackageManager.__init__(self, no_confirm)
+
+    def install(self, dependencies: Dict[str, Set[str]]) -> bool:
+        return self._install(dependencies=dependencies,
+                             install_cmd="brew install",
+                             replace_dict={"patch": set(),
+                                           "jni": {"maven"}})
+
+    def install_compiler(self) -> str:
+        self.install({"compiler": set()})
+        return ""
+
+    def _get_installed_packages(self) -> Set[str]:
+        result = subprocess.run(['brew', 'list'], text=True, 
capture_output=True, check=True)
+        lines = result.stdout.splitlines()
+        lines = [line.split('@', 1)[0] for line in lines]
+        return set(lines)
+
+
+class AptPackageManager(PackageManager):
+    def __init__(self, no_confirm):
+        PackageManager.__init__(self, no_confirm)
+
+    def install(self, dependencies: Dict[str, Set[str]]) -> bool:
+        return self._install(dependencies=dependencies,
+                             install_cmd="sudo apt install -y",
+                             replace_dict={"libarchive": {"liblzma-dev"},
+                                           "lua": {"liblua5.1-0-dev"},
+                                           "python": {"libpython3-dev"},
+                                           "libusb": {"libusb-1.0-0-dev", 
"libusb-dev"},
+                                           "libpng": {"libpng-dev"},
+                                           "libpcap": {"libpcap-dev"},
+                                           "jni": {"openjdk-8-jdk", 
"openjdk-8-source", "maven"},
+                                           "gpsd": {"libgps-dev"}})
+
+    def _get_installed_packages(self) -> Set[str]:
+        result = subprocess.run(['dpkg', '--get-selections'], text=True, 
capture_output=True, check=True)
+        lines = [line.split('\t')[0] for line in result.stdout.splitlines()]
+        lines = [line.rsplit(':', 1)[0] for line in lines]
+        return set(lines)
+
+    def install_compiler(self) -> str:
+        if distro.id() == "ubuntu" and int(distro.major_version()) < 22:
+            self.install({"compiler_prereq": {"apt-transport-https", 
"ca-certificates", "software-properties-common"}})
+            _run_command_with_confirm("sudo add-apt-repository -y 
ppa:ubuntu-toolchain-r/test",
+                                      no_confirm=self.no_confirm)
+            self.install({"compiler": {"build-essential", "g++-11"}})
+            return "-DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11"
+        self.install({"compiler": {"g++"}})
+        return ""
+
+
+class DnfPackageManager(PackageManager):
+    def __init__(self, no_confirm):
+        PackageManager.__init__(self, no_confirm)
+
+    def install(self, dependencies: Dict[str, Set[str]]) -> bool:
+        return self._install(dependencies=dependencies,
+                             install_cmd="sudo dnf --enablerepo=crb install -y 
epel-release",
+                             replace_dict={"gpsd": {"gpsd-devel"},
+                                           "libpcap": {"libpcap-devel"},
+                                           "lua": {"lua-devel"},
+                                           "python": {"python3-devel"},
+                                           "jni": {"java-1.8.0-openjdk", 
"java-1.8.0-openjdk-devel", "maven"},
+                                           "libpng": {"libpng-devel"},
+                                           "libusb": {"libusb-devel"}})
+
+    def _get_installed_packages(self) -> Set[str]:
+        result = subprocess.run(['dnf', 'list', 'installed'], text=True, 
capture_output=True, check=True)
+        lines = [line.split(' ')[0] for line in result.stdout.splitlines()]
+        lines = [line.rsplit('.', 1)[0] for line in lines]
+        return set(lines)
+
+    def install_compiler(self) -> str:
+        self.install({"compiler": {"gcc-c++"}})
+        return ""
+
+
+class PacmanPackageManager(PackageManager):
+    def __init__(self, no_confirm):
+        PackageManager.__init__(self, no_confirm)
+
+    def install(self, dependencies: Dict[str, Set[str]]) -> bool:
+        return self._install(dependencies=dependencies,
+                             install_cmd="sudo pacman --noconfirm -S",
+                             replace_dict={"jni": {"jdk8-openjdk", "maven"}})
+
+    def _get_installed_packages(self) -> Set[str]:
+        result = subprocess.run(['pacman', '-Qq'], text=True, 
capture_output=True, check=True)
+        return set(result.stdout.splitlines())
+
+    def install_compiler(self) -> str:
+        self.install({"compiler": {"gcc"}})
+        return ""
+
+
+def _get_vs_dev_cmd_path() -> str:
+    vswhere_results = subprocess.run(
+        "vswhere -products * -property installationPath -requires 
Microsoft.VisualStudio.Component.VC.ATL",
+        capture_output=True)

Review Comment:
   Yeah the script uses the package manager to tell if a required 
package/lib/exe is installed or not.
   Maybe instead of the package manager we could use where.exe to tell if 
vswhere is installed or not. Probably this is the only instance where this 
would be useful (and vswhere is a tiny exe), so not sure if it worth the hassle 
to add more complication to the code. What do you think?



##########
bootstrap/py_bootstrap.bat:
##########
@@ -0,0 +1,29 @@
+@echo off
+
+REM Check if Python is installed
+where python > nul 2>&1
+if %errorlevel% neq 0 (
+    echo Python is not installed
+    exit /b 1
+)
+
+REM Check if venv module is available
+python -m venv --help > nul 2>&1
+if %errorlevel% neq 0 (
+    echo venv module is not available
+    exit /b 1
+)
+
+set "SCRIPT_DIR=%~dp0"
+set "VENV_DIR=%SCRIPT_DIR%venv"
+
+if exist "%VENV_DIR%" (
+    call "%VENV_DIR%\Scripts\activate"
+) else (
+    echo Creating virtualenv
+    python -m venv "%VENV_DIR%"
+    call "%VENV_DIR%\Scripts\activate"

Review Comment:
   Windows allows referencing files without explicit extensions in some 
scenarios. Made it explicit in [replace activate with 
activate.bat](https://github.com/apache/nifi-minifi-cpp/pull/1681/commits/833065382bd84716d239c0f2b7871ae8a66dd5da)



##########
Windows.md:
##########
@@ -120,7 +120,7 @@ A basic working CMake configuration can be inferred from 
the `win_build_vs.bat`.
 ```
 mkdir build
 cd build
-cmake -G "Visual Studio 17 2022" -A x64 -DINSTALLER_MERGE_MODULES=OFF 
-DTEST_CUSTOM_WEL_PROVIDER=OFF -DENABLE_SQL=OFF -DUSE_REAL_ODBC_TEST_DRIVER=OFF 
-DCMAKE_BUILD_TYPE_INIT=Release -DCMAKE_BUILD_TYPE=Release -DWIN32=WIN32 
-DENABLE_LIBRDKAFKA=OFF -DENABLE_JNI=OFF -DOPENSSL_OFF=OFF -DENABLE_COAP=OFF 
-DENABLE_AWS=OFF -DENABLE_PDH= -DENABLE_AZURE=OFF -DENABLE_SFTP=OFF 
-DENABLE_SPLUNK= -DENABLE_GCP= -DENABLE_NANOFI=OFF -DENABLE_OPENCV=OFF 
-DENABLE_PROMETHEUS=OFF -DENABLE_ELASTICSEARCH= -DUSE_SHARED_LIBS=OFF 
-DENABLE_CONTROLLER=ON -DENABLE_BUSTACHE=OFF -DENABLE_COAP=OFF 
-DENABLE_ENCRYPT_CONFIG=OFF -DENABLE_GPS=OFF -DENABLE_LUA_SCRIPTING=OFF 
-DENABLE_MQTT=OFF -DENABLE_OPC=OFF -DENABLE_OPENWSMAN=OFF -DENABLE_OPS=OFF 
-DENABLE_PCAP=OFF -DENABLE_PYTHON_SCRIPTING= -DENABLE_SENSORS=OFF 
-DENABLE_USB_CAMERA=OFF -DBUILD_ROCKSDB=ON -DFORCE_WINDOWS=ON 
-DUSE_SYSTEM_UUID=OFF -DDISABLE_LIBARCHIVE=OFF -DENABLE_WEL=ON 
-DFAIL_ON_WARNINGS=OFF -DSKIP_TESTS=OFF ..
+cmake -G "Visual Studio 16 2022" -A x64 -DINSTALLER_MERGE_MODULES=OFF 
-DTEST_CUSTOM_WEL_PROVIDER=OFF -DENABLE_SQL=OFF 
-DMINIFI_USE_REAL_ODBC_TEST_DRIVER=OFF -DCMAKE_BUILD_TYPE_INIT=Release 
-DCMAKE_BUILD_TYPE=Release -DWIN32=WIN32 -DENABLE_LIBRDKAFKA=OFF 
-DENABLE_JNI=OFF -DMINIFI_OPENSSL=ON -DENABLE_COAP=OFF -DENABLE_AWS=OFF 
-DENABLE_PDH= -DENABLE_AZURE=OFF -DENABLE_SFTP=OFF -DENABLE_SPLUNK= 
-DENABLE_GCP= -DENABLE_NANOFI=OFF -DENABLE_OPENCV=OFF -DENABLE_PROMETHEUS=OFF 
-DENABLE_ELASTICSEARCH= -DUSE_SHARED_LIBS=OFF -DENABLE_CONTROLLER=ON 
-DENABLE_BUSTACHE=OFF -DENABLE_COAP=OFF -DENABLE_ENCRYPT_CONFIG=OFF 
-DENABLE_GPS=OFF -DENABLE_LUA_SCRIPTING=OFF -DENABLE_MQTT=OFF -DENABLE_OPC=OFF 
-DENABLE_OPENWSMAN=OFF -DENABLE_OPS=OFF -DENABLE_PCAP=OFF 
-DENABLE_PYTHON_SCRIPTING= -DENABLE_SENSORS=OFF -DENABLE_USB_CAMERA=OFF 
-DBUILD_ROCKSDB=ON -DUSE_SYSTEM_UUID=OFF -DENABLE_LIBARCHIVE=ON -DENABLE_WEL=ON 
-DMINIFI_FAIL_ON_WARNINGS=OFF -DSKIP_TESTS=OFF ..

Review Comment:
   This seems like an accident 👍 thanks for catching. fixed it in [fix typo in 
Windows.md](https://github.com/apache/nifi-minifi-cpp/pull/1681/commits/7fa5e96d59a62cf5bfc10d57d4168da5503f46d3)



-- 
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-unsubscr...@nifi.apache.org

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

Reply via email to