Skip to content

Commit

Permalink
Fix CI. Format run_conan.py with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Feb 6, 2024
1 parent da940c7 commit 9a2890c
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions run_conan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,82 @@
import subprocess as sp
import shutil
import os
import sys


def find_conan():
conan = shutil.which("conan")
if conan is None:
raise RuntimeError("Unable to find conan in your PATH.\n"
"Please install conan: https://conan.io/downloads")
raise RuntimeError(
"Unable to find conan in your PATH.\n"
"Please install conan: https://conan.io/downloads"
)

return conan


def run_conan_profile_detect(conan):
def run_conan_profile_detect(conan, env):
sp.run([conan, "profile", "detect"], stdout=sp.DEVNULL, env=env)

sp.run([conan, "profile", "detect"], stderr=sp.DEVNULL, stdout=sp.DEVNULL)


def run_conan_install(conan):
sp.check_call([conan, "install", os.path.join("..", "conanfile.txt"), "--settings=build_type=Release",
"--settings=compiler.cppstd=17", "--output-folder=conan-staging",
"--build=missing", "--update"], stdout=sp.DEVNULL)
def run_conan_install(conan, env):
sp.check_call(
[
conan,
"install",
os.path.join("..", "conanfile.txt"),
"--settings=build_type=Release",
"--settings=compiler.cppstd=17",
"--output-folder=conan-staging",
"--build=missing",
"--update",
],
stdout=sp.DEVNULL,
env=env,
)


def main():
conan = find_conan()
pwd = os.getcwd()

env = os.environ.copy()

conandeps_mk = os.path.join(pwd, "conan-staging", "conandeps.mk")

if os.path.exists(conandeps_mk):
print(conandeps_mk)
return

conan_home = os.getenv("CONAN_HOME")
conan_home = env.get("CONAN_HOME")
if conan_home is not None:
os.makedirs(conan_home, exist_ok=True)

cc = os.getenv("CC")
cc = env.get("CC")

new_cc = os.path.join(conan_home, "gcc")
try:
os.symlink(cc, new_cc)
except FileExistsError:
pass
os.environ["CC"] = new_cc
env["CC"] = new_cc

cxx = os.getenv("CXX")
cxx = env.get("CXX")
if cxx is not None:
new_cxx = os.path.join(conan_home, "g++")

try:
os.symlink(cxx, new_cxx)
except FileExistsError:
pass
os.environ["CXX"] = new_cxx
env["CXX"] = new_cxx

print("CONAN_HOME=" + env.get("CONAN_HOME", ""), file=sys.stderr)
print("CC=" + env.get("CC", ""), file=sys.stderr)
print("CXX=" + env.get("CXX", ""), file=sys.stderr)

run_conan_profile_detect(conan)
run_conan_install(conan)
run_conan_profile_detect(conan, env)
run_conan_install(conan, env)
print(conandeps_mk)


Expand Down

0 comments on commit 9a2890c

Please sign in to comment.