@@ -107,15 +107,25 @@ def run_conan(
107107 kwargs ["text" ] = kwargs .get ("text" , True )
108108 args = [conan_app ] + args
109109 logger .debug (args )
110- res = subprocess .run (
110+ returncode = 0
111+ lines = []
112+ with subprocess .Popen (
111113 args ,
112- shell = False ,
113- check = False ,
114- ** kwargs
115- )
116- if res .returncode :
117- fail ("Error while executing conan:\n %s\n %s" , res .stdout , res .stderr )
118- return res
114+ stdout = subprocess .PIPE ,
115+ stderr = subprocess .STDOUT ,
116+ bufsize = 1 ,
117+ universal_newlines = True ,
118+ env = kwargs ["env" ]
119+ ) as proc :
120+ for line in proc .stdout :
121+ line = line .rstrip ()
122+ logger .info (line )
123+ lines += [line ]
124+
125+ if proc .returncode :
126+ fail ("Error while executing conan..." )
127+
128+ return lines
119129
120130
121131def download (
@@ -208,6 +218,17 @@ def download(
208218 downloaded .extractall (destdir )
209219
210220
221+ def get_existing_config (config_file ):
222+ """Get existing configuration from existing global.conf"""
223+ config_file = Path (config_file )
224+ if not config_file .exists ():
225+ logger .info ("No global.conf found" )
226+ return []
227+ with config_file .open () as f :
228+ # Minimal filtering: remove blank lines and lines starting with '#' (comments...)
229+ return [l .rstrip () for l in f .readlines () if l .rstrip () and not l .startswith ('#' )]
230+
231+
211232def show_build_info (destdir ):
212233 """Show build information that should be bundled with the archive."""
213234 file_path = destdir / "build-info.json"
@@ -255,12 +276,11 @@ def conan_home():
255276 """Get Conan home path."""
256277 res = run_conan (
257278 ["config" , "home" ],
258- capture_output = True ,
259279 text = True ,
260280 )
261- if res . returncode :
262- fail ( "Error while executing conan: \n %s \n %s" , res . stdout , res . stderr )
263- return Path (res . stdout .strip ())
281+ if not res :
282+ raise RuntimeError ( "Cannot find conan home" )
283+ return Path (res [ 0 ] .strip ())
264284
265285
266286def copy_global_conf (
@@ -280,7 +300,7 @@ def copy_global_conf(
280300 )
281301
282302
283- def set_global_conf (cache_dir ):
303+ def set_global_conf (cache_dir , existing_config ):
284304 """Set global.conf file."""
285305 global_conf = conan_home () / "global.conf"
286306 global_conf .touch ()
@@ -290,12 +310,14 @@ def set_global_conf(cache_dir):
290310
291311 def write (entry ):
292312 logger .info (" - %s" , entry )
293- p .write (entry )
313+ p .write (entry . rstrip () )
294314 p .write ("\n " )
295315
296316 write (f"core.cache:storage_path={ cache_dir } " )
297317 write (f"core.download:download_cache={ cache_dir } " )
298318 write (f"core:non_interactive=True" )
319+ for line in existing_config :
320+ write (line )
299321
300322
301323def main (
@@ -381,7 +403,21 @@ def main(
381403 preset_dir = output_dir .absolute () if os .name == "nt" else None
382404 output_dir .mkdir (parents = True , exist_ok = True )
383405
406+ # We need to get the existing configuration, from the existing
407+ # global.conf.
408+ logger_step ("Getting existing config" )
409+ config_file = conan_home () / "global.conf"
410+ logger .info ("Reading %s" , str (config_file ))
411+ existing_config = get_existing_config (config_file )
412+ if not existing_config :
413+ logger .info ("<empty>" )
414+ else :
415+ for line in existing_config :
416+ logger .info (" - " + line )
417+
384418 # Process
419+ # We download in a separate, temporary environment
420+ # and then we deploy in project output directory
385421 with tempfile .TemporaryDirectory (dir = preset_dir ) as tmpdir :
386422
387423 tmpdir = Path (tmpdir )
@@ -405,7 +441,7 @@ def main(
405441
406442 # Set global.conf
407443 logger_step ("Setting conan configuration" )
408- set_global_conf (tmpdir )
444+ set_global_conf (tmpdir , existing_config )
409445
410446 # Initialize
411447 user = args .user or settings ["Dependencies" ]["user" ]
@@ -440,16 +476,7 @@ def main(
440476
441477 # Clean
442478 logger_step ("Cleaning local cache" )
443- res = run_conan (
444- [
445- "remove" ,
446- "-c" ,
447- "*" ,
448- ],
449- capture_output = True ,
450- )
451- for line in res .stderr .splitlines ():
452- logger .info (line )
479+ res = run_conan (["remove" , "-c" , "*" ])
453480
454481 # Install
455482 logger_step ("Installing" )
@@ -460,60 +487,42 @@ def main(
460487 "restore" ,
461488 archive ,
462489 ],
463- capture_output = True ,
464490 )
465- for line in res .stderr .splitlines ():
466- logger .info (line )
467491
468492 # Check
469493 logger_step ("Checking integrity" )
470- res = run_conan (
471- [
472- "cache" ,
473- "check-integrity" ,
474- "*" ,
475- ],
476- capture_output = True ,
477- )
478- for line in res .stderr .splitlines ():
479- logger .info (line )
494+ res = run_conan (["cache" , "check-integrity" , "*" ])
480495 logger .info ("Integrity check: OK" )
481496
482497 # Install profiles in conan home
483498 logger_step ("Installing profiles" )
484499 run_conan (["cache" , "path" , f"luxcoreconf/{ release } @luxcore/luxcore" ])
485500
486- res = run_conan (
501+ run_conan (
487502 [
488503 "config" ,
489504 "install-pkg" ,
490505 "-vvv" ,
491506 f"luxcoreconf/{ release } @luxcore/luxcore" ,
492- ],
493- capture_output = True ,
507+ ]
494508 )
495- for line in res .stderr .splitlines ():
496- logger .info (line )
497509
498510 # Install profiles into destination ("deploy")
499511 src_profile_dir = conan_home () / "profiles"
500512 profile_dir = output_dir .absolute () / ".conan2" / "profiles"
501513 profile_dir .mkdir (parents = True , exist_ok = True )
502514 logger .info ("" )
503515 logger .info ("Deploying profiles from %s to %s" , src_profile_dir , profile_dir )
504- res = run_conan (
516+ run_conan (
505517 [
506518 "config" ,
507519 "install" ,
508520 "--type=dir" ,
509521 f"--target-folder={ str (profile_dir )} " ,
510522 "-vvv" ,
511523 src_profile_dir ,
512- ],
513- capture_output = True ,
524+ ]
514525 )
515- for line in res .stderr .splitlines ():
516- logger .info (line )
517526
518527 # Generate & deploy
519528 logger_step ("Generating..." )
@@ -562,9 +571,9 @@ def main(
562571 "conanfile.py" ,
563572 ),
564573 ]
565- res = run_conan ( main_block + end_block , capture_output = True )
566- for line in res . stderr . splitlines ():
567- logger . info ( line )
574+
575+ # conan is called here
576+ run_conan ( main_block + end_block )
568577
569578 # Show presets
570579 res = subprocess .run (
0 commit comments