1515import sysconfig
1616import shutil
1717
18+ try :
19+ from os import cpu_count
20+ except ImportError :
21+ def cpu_count ():
22+ pass # undetermined
23+
1824logger = logging .getLogger (__name__ )
1925
2026# Keep track of all files we write/append for later logging
@@ -141,7 +147,10 @@ def detect_context():
141147 ci ['cachedir' ] = os .environ ['CACHEDIR' ]
142148
143149 if 'CHOCO' in os .environ :
144- ci ['choco' ].extend (os .environ ['CHOCO' ].split ())
150+ if os .environ ['CHOCO' ] == 'NO' :
151+ ci ['choco' ] = []
152+ else :
153+ ci ['choco' ].extend (os .environ ['CHOCO' ].split ())
145154
146155 if 'APT' in os .environ :
147156 ci ['apt' ].extend (os .environ ['APT' ].split ())
@@ -153,7 +162,7 @@ def detect_context():
153162 if 'TEST' in os .environ and os .environ ['TEST' ].lower () == 'no' :
154163 ci ['test' ] = False
155164
156- ci ['parallel_make' ] = 2
165+ ci ['parallel_make' ] = cpu_count () or 2
157166 if 'PARALLEL_MAKE' in os .environ :
158167 ci ['parallel_make' ] = int (os .environ ['PARALLEL_MAKE' ])
159168
@@ -433,9 +442,11 @@ def update_release_local(var, location):
433442def set_setup_from_env (dep ):
434443 for postf in ['' , '_DIRNAME' , '_REPONAME' , '_REPOOWNER' , '_REPOURL' ,
435444 '_VARNAME' , '_RECURSIVE' , '_DEPTH' , '_HOOK' ]:
436- if dep + postf in os .environ :
437- setup [dep + postf ] = os .environ [dep + postf ]
438- logger .debug ('ENV assignment: %s = %s' , dep + postf , setup [dep + postf ])
445+ env = dep + postf
446+ val = os .environ .get (env )
447+ if val :
448+ setup [env ] = val
449+ logger .debug ('ENV assignment: %s = %s' , env , setup [env ])
439450
440451
441452def call_git (args , ** kws ):
@@ -612,6 +623,13 @@ def add_dependency(dep):
612623 sys .stdout .flush ()
613624 sp .check_call (['patch' , '-p1' , '-i' , os .path .join (ci ['scriptsdir' ], 'add-msi-to-314.patch' )],
614625 cwd = place )
626+
627+ # Post 3.14 we have checks for readline.h
628+ print ('Patching COMMANDLINE_LIBRARY to EPICS' )
629+ sys .stdout .flush ()
630+ sp .check_call (['patch' , '-p1' , '-i' , os .path .join (ci ['scriptsdir' ], 'dont_use_readline_314.patch' )],
631+ cwd = place )
632+
615633 else :
616634 # force including RELEASE.local for non-base modules by overwriting their configure/RELEASE
617635 release = os .path .join (place , "configure" , "RELEASE" )
@@ -771,17 +789,33 @@ def setup_for_build(args):
771789
772790 # apparently %CD% is handled automagically, so use getcwd() instead
773791 os .environ ['TOP' ] = os .getcwd ()
792+ os .environ ['MAKE' ] = 'make'
793+ os .environ ['EPICS_BASE' ] = places ['EPICS_BASE' ]
774794
775- addpaths = []
776- for path in args .paths :
795+ changed_vars = set ()
796+
797+ for extra_env_var in args .extra_env_vars :
777798 try :
778- addpaths .append (path .format (** os .environ ))
799+ key_value = extra_env_var .split ('=' )
800+ key = key_value [0 ]
801+ value = key_value [1 ]
802+ expanded_value = value .format (** os .environ )
803+
804+ # Update the environment right now so later variables have access
805+ if key in os .environ :
806+ old_value = [os .environ [key ]]
807+ else :
808+ old_value = []
809+
810+ os .environ [key ] = os .pathsep .join (old_value + [expanded_value ])
811+ changed_vars .add (key )
779812 except KeyError :
780813 print ('Environment' )
781814 [print (' ' , K , '=' , repr (V )) for K , V in os .environ .items ()]
782815 raise
783816
784- os .environ ['PATH' ] = os .pathsep .join ([os .environ ['PATH' ]] + addpaths )
817+ for key in changed_vars :
818+ print ("{0}{2} = {3}{1}" .format (ANSI_CYAN , ANSI_RESET , key , os .environ [key ]))
785819
786820 # os.environ completely updated at this point
787821
@@ -849,9 +883,8 @@ def handle_old_cross_variables():
849883 os .environ ["CI_CROSS_TARGETS" ] = ""
850884
851885 if "RTEMS" in os .environ :
852- if 'RTEMS_TARGET' in os .environ :
853- rtems_target = os .environ ['RTEMS_TARGET' ]
854- else :
886+ rtems_target = os .environ .get ('RTEMS_TARGET' )
887+ if not rtems_target :
855888 if os .environ ['RTEMS' ] == '5' :
856889 rtems_target = 'RTEMS-pc686-qemu'
857890 else :
@@ -875,8 +908,10 @@ def handle_old_cross_variables():
875908 if "WINE" in os .environ :
876909 if os .environ ['WINE' ] == '32' :
877910 new_cross_target = ":win32-x86-mingw"
878- else :
911+ elif os . environ [ 'WINE' ] == '64' :
879912 new_cross_target = ":windows-x64-mingw"
913+ else :
914+ raise RuntimeError ("Invalid $WINE, must be 32/64" )
880915 os .environ ["CI_CROSS_TARGETS" ] += new_cross_target
881916
882917 print (
@@ -1359,8 +1394,6 @@ def test_results(args):
13591394def doExec (args ):
13601395 'exec user command with vcvars'
13611396 setup_for_build (args )
1362- os .environ ['MAKE' ] = 'make'
1363- os .environ ['EPICS_BASE' ] = places ['EPICS_BASE' ]
13641397 fold_start ('exec.command' , 'Execute command {}' .format (args .cmd ))
13651398 sp .check_call (' ' .join (args .cmd ), shell = True )
13661399 fold_end ('exec.command' , 'Execute command {}' .format (args .cmd ))
@@ -1430,8 +1463,10 @@ def timespec(s):
14301463 p = ArgumentParser ()
14311464 p .add_argument ('--no-vcvars' , dest = 'vcvars' , default = True , action = 'store_false' ,
14321465 help = 'Assume vcvarsall.bat has already been run' )
1433- p .add_argument ('--add-path' , dest = 'paths' , default = [], action = 'append' ,
1434- help = 'Append directory to $PATH or %%PATH%%. Expands {ENVVAR}' )
1466+ p .add_argument ('--add-path' , dest = 'extra_env_vars' , type = lambda x : "PATH={}" .format (x ), default = [], action = 'append' ,
1467+ help = 'Append directory to $PATH or %%PATH%%. Expands {ENVVAR}. Equivalent to: "--add-env PATH=<PATHS>"' )
1468+ p .add_argument ('--add-env' , dest = 'extra_env_vars' , default = [], action = 'append' ,
1469+ help = 'Append directory to the specified $ENVVAR or %%ENVVAR%%. Expands {OTHER_ENVVAR}. Example: "--add-env \' LD_LIBRARY_PATH={EPICS_BASE}/lib/{EPICS_HOST_ARCH}\' "' )
14351470 p .add_argument ('-T' , '--timeout' , type = timespec , metavar = 'DLY' ,
14361471 help = 'Terminate make after delay. DLY interpreted as second, or may be qualified with "S", "M", or "H". (default no timeout)' )
14371472 subp = p .add_subparsers ()
0 commit comments