lordgamez commented on code in PR #2212:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2212#discussion_r3542023205


##########
bootstrap/cli.py:
##########
@@ -28,24 +30,88 @@ def install_dependencies(minifi_options: MinifiOptions, 
package_manager: Package
     return res
 
 
+def export_custom_conan_recipes(minifi_options: MinifiOptions, 
package_manager: PackageManager) -> bool:
+    thirdparty_dir = minifi_options.source_dir / "thirdparty"
+    for root, _, files in os.walk(thirdparty_dir):
+        for file in files:
+            if file == "conanfile.py":
+                config_yaml = os.path.join(Path(root).parent, "config.yml")
+
+                with open(config_yaml) as f:
+                    data = yaml.safe_load(f)
+
+                version = next(iter(data["versions"]))
+
+                print(f"Exporting the custom Conan recipe {root} with version 
{version}")
+                if not package_manager.run_cmd(f"conan export {root} 
--version={version} --user=minifi --channel=develop"):
+                    print(f"Exporting the custom Conan recipe {root} failed")
+                    return False
+    return True
+
+
+def add_conan_options_from_cmake_options(extension_options: list[str], 
minifi_options: MinifiOptions) -> str:
+    conan_options = ""
+    for extension_option in extension_options:
+        if minifi_options.bool_options[extension_option.upper()].value not in 
(None, "OFF"):
+            conan_options += f' -o "&:{extension_option.lower()}=True"'
+    return conan_options
+
+
+def run_conan_install(minifi_options: MinifiOptions, package_manager: 
PackageManager) -> bool:
+    if not minifi_options.use_conan.value == "ON":
+        print("Conan install skipped because USE_CONAN is OFF")
+        return True
+    conan_options = add_conan_options_from_cmake_options(["ENABLE_ALL", 
"ENABLE_ROCKSDB", "ENABLE_SFTP", "ENABLE_PROMETHEUS", "ENABLE_BZIP2", 
"ENABLE_LZMA", "ENABLE_MQTT", "ENABLE_COUCHBASE",
+                                                          "ENABLE_KAFKA", 
"ENABLE_OPC", "SKIP_TESTS"], minifi_options)
+    if minifi_options.custom_malloc is not None and 
minifi_options.custom_malloc.value not in (None, "OFF"):
+        conan_options += f' -o 
"&:custom_malloc={minifi_options.custom_malloc.value}"'
+
+    if not package_manager.run_cmd("conan profile detect --exist-ok"):
+        print("Conan default profile detection failed")
+        return False
+
+    if not export_custom_conan_recipes(minifi_options, package_manager):
+        return False
+
+    compiler_settings = " --settings=compiler.cppstd=23"
+    generator_setting = " -c tools.cmake.cmaketoolchain:generator=Ninja" if 
minifi_options.use_ninja.value == "ON" else ""
+    conan_remote_add_cmd = "conan remote add nifi-conan 
https://apache.jfrog.io/artifactory/api/conan/nifi-conan --force"
+    if not package_manager.run_cmd(conan_remote_add_cmd):
+        print("Adding the nifi-conan remote failed")
+        return False
+    build_cmd = f"conan install {minifi_options.source_dir} 
--output-folder={minifi_options.build_dir} --build=missing {conan_options} " \
+                
f"--settings=build_type={minifi_options.build_type.value}{generator_setting}{compiler_settings}"
+    res = package_manager.run_cmd(build_cmd)
+    print("Conan install was successful" if res else "Conan install was 
unsuccessful")
+    return res
+
+
+def _conan_build_env_prefix(minifi_options: MinifiOptions) -> str:
+    if minifi_options.use_conan.value == "ON" and platform.system() == 
"Windows":
+        conanbuild = os.path.join(str(minifi_options.build_dir), 
"conanbuild.bat")
+        return f'call "{conanbuild}" && '
+    return ""

Review Comment:
   conanbuild.bat is generated by the virtualenv so it is guaranteed to be there



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to