1- import os
21import shutil
32import subprocess
43import sys
54from collections .abc import Mapping
65from pathlib import Path
76
87
9- def run_command (command : str , cwd : Path , env : Mapping [str , str ]) -> None :
8+ def run_command (command : str , cwd : Path , env : Mapping [str , str ] | None = None ) -> None :
109 result = subprocess .run (command , cwd = cwd , env = env , shell = True , check = True , text = True )
1110 if result .returncode != 0 :
1211 sys .exit (result .returncode )
1312
1413
15- def check_env () -> Mapping [str , str ]:
16- # print the path environment variable
17- PATH : str = os .getenv ("PATH" , "" )
18- LD_LIBRARY_PATH : str = os .getenv ("LD_LIBRARY_PATH" , "" )
19- JAVA_HOME : str | None = os .getenv ("JAVA_HOME" ) or os .getenv ("GRAALVM_HOME" )
20- GRAALVM_HOME : str | None = os .getenv ("GRAALVM_HOME" ) or os .getenv ("JAVA_HOME" )
21- MAVEN_HOME : str | None = os .getenv ("MAVEN_HOME" )
22- if JAVA_HOME is None and GRAALVM_HOME is None :
23- print ("JAVA_HOME or GRAALVM_HOME environment variable must be set" )
24- sys .exit (1 )
25- print (f"PATH={ PATH } " )
26- print (f"JAVA_HOME={ JAVA_HOME } " )
27- print (f"GRAALVM_HOME={ GRAALVM_HOME } " )
28- print (f"MAVEN_HOME={ MAVEN_HOME } " )
29-
30- # find path to mvn
31- mvn_path : str | None = shutil .which ("mvn" )
32- if mvn_path is None :
33- print ("mvn could not be found" )
34- sys .exit (1 )
35- mvn_install_dir = Path (mvn_path ).parent
36-
37- # find path to poetry
38- poetry_path : str | None = shutil .which ("poetry" )
39- if poetry_path is None :
40- print ("poetry could not be found" )
41- sys .exit (1 )
42- poetry_install_dir = Path (poetry_path ).parent
43-
44- # Check if native-image is installed
45- native_image_path : str | None = shutil .which ("native-image" )
46- if native_image_path is None :
47- print ("native-image could not be found" )
48- sys .exit (1 )
49- native_image_install_dir = Path (native_image_path ).parent
50- native_image_agent_dir = Path (GRAALVM_HOME ) / "lib"
51- graalvm_bin_dir = Path (GRAALVM_HOME ) / "bin"
52-
53- # get PATH and append mvn and poetry install directories
54- NEW_PATH = f"{ mvn_install_dir } :{ poetry_install_dir } :{ native_image_install_dir } :{ graalvm_bin_dir } :{ PATH } "
55-
56- if LD_LIBRARY_PATH == "" :
57- LD_LIBRARY_PATH = f"{ native_image_agent_dir } "
58- else :
59- LD_LIBRARY_PATH = f"{ native_image_agent_dir } /{ LD_LIBRARY_PATH } "
60-
61- new_env = os .environ .copy ()
62- new_env ["PATH" ] = NEW_PATH
63- new_env ["LD_LIBRARY_PATH" ] = LD_LIBRARY_PATH
64- if JAVA_HOME is not None :
65- new_env ["JAVA_HOME" ] = JAVA_HOME
66- if GRAALVM_HOME is not None :
67- new_env ["GRAALVM_HOME" ] = GRAALVM_HOME
68- if MAVEN_HOME is not None :
69- new_env ["MAVEN_HOME" ] = MAVEN_HOME
70-
71- return new_env
72-
73-
7414def main () -> None :
7515 root_dir = Path (__file__ ).resolve ().parent
7616 vcell_submodule_dir = root_dir / "vcell_submodule"
@@ -80,14 +20,11 @@ def main() -> None:
8020 # Ensure the libvcell/lib directory exists
8121 libvcell_lib_dir .mkdir (parents = True , exist_ok = True )
8222
83- # Check the environment variables and pass them to the subprocess
84- new_env = check_env ()
85-
8623 # Build VCell Java project from submodule
87- run_command ("mvn --batch-mode clean install -DskipTests" , cwd = vcell_submodule_dir , env = new_env )
24+ run_command ("mvn --batch-mode clean install -DskipTests" , cwd = vcell_submodule_dir )
8825
8926 # Build vcell-native as Java
90- run_command ("mvn --batch-mode clean install" , cwd = vcell_native_dir , env = new_env )
27+ run_command ("mvn --batch-mode clean install" , cwd = vcell_native_dir )
9128
9229 # Run with native-image-agent to record configuration for native-image
9330 run_command (
@@ -96,11 +33,10 @@ def main() -> None:
9633 "src/test/resources/TinySpacialProject_Application0.xml "
9734 "target/sbml-input" ,
9835 cwd = vcell_native_dir ,
99- env = new_env ,
10036 )
10137
10238 # Build vcell-native as native shared object library
103- run_command ("mvn package -P shared-dll" , cwd = vcell_native_dir , env = new_env )
39+ run_command ("mvn package -P shared-dll" , cwd = vcell_native_dir )
10440
10541 # Copy the shared library to libvcell/lib
10642 for ext in ["so" , "dylib" , "dll" ]:
0 commit comments