@@ -1555,6 +1555,7 @@ internal final class OperationSystemAdaptor: SWBLLBuild.BuildSystemDelegate, Act
1555
1555
func waitForCompletion( buildSucceeded: Bool ) async {
1556
1556
let completionToken = await dynamicOperationContext. waitForCompletion ( )
1557
1557
cleanupCompilationCache ( )
1558
+ cleanupGlobalModuleCache ( )
1558
1559
1559
1560
await queue. sync {
1560
1561
self . isCompleted = true
@@ -1601,6 +1602,33 @@ internal final class OperationSystemAdaptor: SWBLLBuild.BuildSystemDelegate, Act
1601
1602
}
1602
1603
}
1603
1604
1605
+ func cleanupGlobalModuleCache( ) {
1606
+ let settings = operation. requestContext. getCachedSettings ( operation. request. parameters)
1607
+ if settings. globalScope. evaluate ( BuiltinMacros . KEEP_GLOBAL_MODULE_CACHE_DIRECTORY) {
1608
+ return // Keep the cache directory.
1609
+ }
1610
+
1611
+ let cachePath = settings. globalScope. evaluate ( BuiltinMacros . MODULE_CACHE_DIR)
1612
+ guard !cachePath. isEmpty, operation. fs. exists ( cachePath) else {
1613
+ return
1614
+ }
1615
+
1616
+ let signatureCtx = InsecureHashContext ( )
1617
+ signatureCtx. add ( string: " CleanupGlobalModuleCache " )
1618
+ signatureCtx. add ( string: cachePath. str)
1619
+ let signature = signatureCtx. signature
1620
+
1621
+ withActivity ( ruleInfo: " CleanupGlobalModuleCache \( cachePath. str) " , executionDescription: " Cleanup global module cache at \( cachePath) " , signature: signature, target: nil , parentActivity: nil ) { activity in
1622
+ do {
1623
+ try operation. fs. removeDirectory ( cachePath)
1624
+ } catch {
1625
+ // Log error but do not fail the build.
1626
+ emit ( diagnostic: Diagnostic . init ( behavior: . warning, location: . unknown, data: DiagnosticData ( " Failed to remove \( cachePath) : \( error. localizedDescription) " ) ) , for: activity, signature: signature)
1627
+ }
1628
+ return . succeeded
1629
+ }
1630
+ }
1631
+
1604
1632
/// Get the active output delegate for an executing command.
1605
1633
///
1606
1634
/// - returns: The active delegate, or nil if not found.
0 commit comments