@@ -521,6 +521,8 @@ bool runcpp2::CleanupDependencies( const runcpp2::Data::Profile& profile,
521521 return true ;
522522}
523523
524+ // #define RUNCPP2_USE_PARALLEL_FOR_DEP 0
525+
524526bool runcpp2::SetupDependenciesIfNeeded (const runcpp2::Data::Profile& profile,
525527 const ghc::filesystem::path& buildDir,
526528 const Data::ScriptInfo& scriptInfo,
@@ -550,11 +552,14 @@ bool runcpp2::SetupDependenciesIfNeeded(const runcpp2::Data::Profile& profile,
550552 if (!PopulateAbsoluteIncludePaths (availableDependencies, dependenciesLocalCopiesPaths))
551553 return false ;
552554
555+ #if RUNCPP2_USE_PARALLEL_FOR_DEP
553556 std::vector<std::future<bool >> actions;
557+ std::vector<bool > finished;
554558
555559 // Cache logs for worker threads
556560 ssLOG_ENABLE_CACHE_OUTPUT_FOR_NEW_THREADS ();
557561 int logLevel = ssLOG_GET_CURRENT_THREAD_TARGET_LEVEL ();
562+ #endif
558563
559564 // Run setup steps
560565 for (int i = 0 ; i < availableDependencies.size (); ++i)
@@ -566,6 +571,7 @@ bool runcpp2::SetupDependenciesIfNeeded(const runcpp2::Data::Profile& profile,
566571 continue ;
567572 }
568573
574+ #if RUNCPP2_USE_PARALLEL_FOR_DEP
569575 actions.emplace_back
570576 (
571577 std::async
@@ -574,7 +580,8 @@ bool runcpp2::SetupDependenciesIfNeeded(const runcpp2::Data::Profile& profile,
574580 [i, &profile, &availableDependencies, &dependenciesLocalCopiesPaths, logLevel]()
575581 {
576582 ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL (logLevel);
577-
583+ #endif
584+
578585 ssLOG_INFO (" Running setup commands for " << availableDependencies.at (i)->Name );
579586 if (!RunDependenciesSteps ( profile,
580587 availableDependencies.at (i)->Setup ,
@@ -585,44 +592,62 @@ bool runcpp2::SetupDependenciesIfNeeded(const runcpp2::Data::Profile& profile,
585592 availableDependencies.at (i)->Name );
586593 return false ;
587594 }
595+
596+ #if RUNCPP2_USE_PARALLEL_FOR_DEP
588597 return true ;
589598 }
590599 )
591600 );
592601
602+ finished.emplace_back (false );
603+
593604 // Evaluate the setup results for each batch
594605 if (actions.size () >= maxThreads || i == availableDependencies.size () - 1 )
595606 {
596- std::chrono::system_clock::time_point deadline =
597- std::chrono::system_clock::now () + std::chrono::seconds (60 );
598- for (int j = 0 ; j < actions.size (); ++j)
607+ bool needsWaiting = false ;
608+ do
599609 {
600- if (!actions.at (j).valid ())
601- {
602- ssLOG_ERROR (" Failed to construct actions for setup" );
603- ssLOG_OUTPUT_ALL_CACHE_GROUPED ();
604- return false ;
605- }
606-
607- std::future_status actionStatus = actions.at (j).wait_until (deadline);
608- if (actionStatus == std::future_status::ready)
610+ std::chrono::system_clock::time_point deadline =
611+ std::chrono::system_clock::now () + std::chrono::seconds (30 );
612+ needsWaiting = false ;
613+ for (int j = 0 ; j < actions.size (); ++j)
609614 {
610- if (!actions.at (j).get ())
615+ if (finished.at (j))
616+ continue ;
617+
618+ if (!actions.at (j).valid ())
611619 {
612- ssLOG_ERROR (" Setup failed for dependencies " );
620+ ssLOG_ERROR (" Failed to construct actions for setup " );
613621 ssLOG_OUTPUT_ALL_CACHE_GROUPED ();
614622 return false ;
615623 }
616- }
617- else
618- {
619- ssLOG_ERROR (" Dependencies setup timeout" );
620- ssLOG_OUTPUT_ALL_CACHE_GROUPED ();
621- return false ;
624+
625+ std::future_status actionStatus = actions.at (j).wait_until (deadline);
626+ if (actionStatus == std::future_status::ready)
627+ {
628+ if (!actions.at (j).get ())
629+ {
630+ ssLOG_ERROR (" Setup failed for dependencies" );
631+ ssLOG_OUTPUT_ALL_CACHE_GROUPED ();
632+ return false ;
633+ }
634+ finished.at (j) = true ;
635+ }
636+ else
637+ {
638+ ssLOG_WARNING (" Manual interrupt might be needed" );
639+ ssLOG_WARNING (" Waited 30 seconds, dependencies setup still going..." );
640+ needsWaiting = true ;
641+ }
622642 }
623643 }
644+ while (needsWaiting);
645+
624646 actions.clear ();
647+ finished.clear ();
625648 }
649+
650+ #endif // #if RUNCPP2_USE_PARALLEL_FOR_DEP
626651 }
627652
628653 ssLOG_OUTPUT_ALL_CACHE_GROUPED ();
@@ -641,17 +666,21 @@ bool runcpp2::BuildDependencies(const runcpp2::Data::Profile& profile,
641666 if (!scriptInfo.Populated )
642667 return true ;
643668
669+ #if RUNCPP2_USE_PARALLEL_FOR_DEP
644670 std::vector<std::future<bool >> actions;
671+ std::vector<bool > finished;
645672
646673 // Cache logs for worker threads
647674 ssLOG_ENABLE_CACHE_OUTPUT_FOR_NEW_THREADS ();
648675 int logLevel = ssLOG_GET_CURRENT_THREAD_TARGET_LEVEL ();
676+ #endif
649677
650678 // Run build steps
651679 for (int i = 0 ; i < availableDependencies.size (); ++i)
652680 {
653681 ssLOG_INFO (" Running build commands for " << availableDependencies.at (i)->Name );
654682
683+ #if RUNCPP2_USE_PARALLEL_FOR_DEP
655684 actions.emplace_back
656685 (
657686 std::async
@@ -660,6 +689,7 @@ bool runcpp2::BuildDependencies(const runcpp2::Data::Profile& profile,
660689 [i, &profile, &availableDependencies, &dependenciesLocalCopiesPaths, logLevel]()
661690 {
662691 ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL (logLevel);
692+ #endif
663693
664694 if (!RunDependenciesSteps ( profile,
665695 availableDependencies.at (i)->Build ,
@@ -669,44 +699,61 @@ bool runcpp2::BuildDependencies(const runcpp2::Data::Profile& profile,
669699 ssLOG_ERROR (" Failed to build dependency " << availableDependencies.at (i)->Name );
670700 return false ;
671701 }
702+
703+ #if RUNCPP2_USE_PARALLEL_FOR_DEP
672704 return true ;
673705 }
674706 )
675707 );
676708
709+ finished.emplace_back (false );
710+
677711 // Evaluate the setup results for each batch
678712 if (actions.size () >= maxThreads || i == availableDependencies.size () - 1 )
679713 {
680- std::chrono::system_clock::time_point deadline =
681- std::chrono::system_clock::now () + std::chrono::seconds (60 );
682- for (int j = 0 ; j < actions.size (); ++j)
714+ bool needsWaiting = false ;
715+ do
683716 {
684- if (!actions.at (j).valid ())
685- {
686- ssLOG_ERROR (" Failed to construct actions for building dependencies" );
687- ssLOG_OUTPUT_ALL_CACHE_GROUPED ();
688- return false ;
689- }
690-
691- std::future_status actionStatus = actions.at (j).wait_until (deadline);
692- if (actionStatus == std::future_status::ready)
717+ std::chrono::system_clock::time_point deadline =
718+ std::chrono::system_clock::now () + std::chrono::seconds (30 );
719+ needsWaiting = false ;
720+ for (int j = 0 ; j < actions.size (); ++j)
693721 {
694- if (!actions.at (j).get ())
722+ if (finished.at (j))
723+ continue ;
724+
725+ if (!actions.at (j).valid ())
695726 {
696- ssLOG_ERROR (" Build failed for dependencies" );
727+ ssLOG_ERROR (" Failed to construct actions for building dependencies" );
697728 ssLOG_OUTPUT_ALL_CACHE_GROUPED ();
698729 return false ;
699730 }
700- }
701- else
702- {
703- ssLOG_ERROR (" Dependencies build timeout" );
704- ssLOG_OUTPUT_ALL_CACHE_GROUPED ();
705- return false ;
731+
732+ std::future_status actionStatus = actions.at (j).wait_until (deadline);
733+ if (actionStatus == std::future_status::ready)
734+ {
735+ if (!actions.at (j).get ())
736+ {
737+ ssLOG_ERROR (" Build failed for dependencies" );
738+ ssLOG_OUTPUT_ALL_CACHE_GROUPED ();
739+ return false ;
740+ }
741+ finished.at (j) = true ;
742+ }
743+ else
744+ {
745+ ssLOG_WARNING (" Manual interrupt might be needed" );
746+ ssLOG_WARNING (" Waited 30 seconds, dependencies build still going..." );
747+ needsWaiting = true ;
748+ }
706749 }
707750 }
751+ while (needsWaiting);
752+
708753 actions.clear ();
754+ finished.clear ();
709755 }
756+ #endif // //#if RUNCPP2_USE_PARALLEL_FOR_DEP
710757 }
711758
712759 ssLOG_OUTPUT_ALL_CACHE_GROUPED ();
0 commit comments