@@ -254,6 +254,7 @@ public class Workspace {
254
254
/// - location: Workspace location configuration.
255
255
/// - authorizationProvider: Provider of authentication information for outbound network requests.
256
256
/// - configuration: Configuration to fine tune the dependency resolution behavior.
257
+ /// - initializationWarningHandler: Initialization warnings handler
257
258
/// - customManifestLoader: Custom manifest loader. Used to customize how manifest are loaded.
258
259
/// - customPackageContainerProvider: Custom package container provider. Used to provide specialized package providers.
259
260
/// - customRepositoryProvider: Custom repository provider. Used to customize source control access.
@@ -263,6 +264,7 @@ public class Workspace {
263
264
location: Location ,
264
265
authorizationProvider: AuthorizationProvider ? = . none,
265
266
configuration: WorkspaceConfiguration ? = . none,
267
+ initializationWarningHandler: ( ( String ) -> Void ) ? = . none,
266
268
// optional customization used for advanced integration situations
267
269
customManifestLoader: ManifestLoaderProtocol ? = . none,
268
270
customPackageContainerProvider: PackageContainerProvider ? = . none,
@@ -275,6 +277,7 @@ public class Workspace {
275
277
location: location,
276
278
authorizationProvider: authorizationProvider,
277
279
configuration: configuration,
280
+ initializationWarningHandler: initializationWarningHandler,
278
281
customRegistriesConfiguration: . none,
279
282
customFingerprints: . none,
280
283
customMirrors: . none,
@@ -303,6 +306,7 @@ public class Workspace {
303
306
/// - forRootPackage: The path for the root package.
304
307
/// - authorizationProvider: Provider of authentication information for outbound network requests.
305
308
/// - configuration: Configuration to fine tune the dependency resolution behavior.
309
+ /// - initializationWarningHandler: Initialization warnings handler
306
310
/// - customManifestLoader: Custom manifest loader. Used to customize how manifest are loaded.
307
311
/// - customPackageContainerProvider: Custom package container provider. Used to provide specialized package providers.
308
312
/// - customRepositoryProvider: Custom repository provider. Used to customize source control access.
@@ -312,6 +316,7 @@ public class Workspace {
312
316
forRootPackage packagePath: AbsolutePath ,
313
317
authorizationProvider: AuthorizationProvider ? = . none,
314
318
configuration: WorkspaceConfiguration ? = . none,
319
+ initializationWarningHandler: ( ( String ) -> Void ) ? = . none,
315
320
// optional customization used for advanced integration situations
316
321
customManifestLoader: ManifestLoaderProtocol ? = . none,
317
322
customPackageContainerProvider: PackageContainerProvider ? = . none,
@@ -324,6 +329,7 @@ public class Workspace {
324
329
try self . init (
325
330
fileSystem: fileSystem,
326
331
location: location,
332
+ initializationWarningHandler: initializationWarningHandler,
327
333
customManifestLoader: customManifestLoader,
328
334
customPackageContainerProvider: customPackageContainerProvider,
329
335
customRepositoryProvider: customRepositoryProvider,
@@ -342,6 +348,7 @@ public class Workspace {
342
348
/// - forRootPackage: The path for the root package.
343
349
/// - authorizationProvider: Provider of authentication information for outbound network requests.
344
350
/// - configuration: Configuration to fine tune the dependency resolution behavior.
351
+ /// - initializationWarningHandler: Initialization warnings handler
345
352
/// - customToolchain: Custom toolchain. Used to create a customized ManifestLoader, customizing how manifest are loaded.
346
353
/// - customPackageContainerProvider: Custom package container provider. Used to provide specialized package providers.
347
354
/// - customRepositoryProvider: Custom repository provider. Used to customize source control access.
@@ -351,6 +358,7 @@ public class Workspace {
351
358
forRootPackage packagePath: AbsolutePath ,
352
359
authorizationProvider: AuthorizationProvider ? = . none,
353
360
configuration: WorkspaceConfiguration ? = . none,
361
+ initializationWarningHandler: ( ( String ) -> Void ) ? = . none,
354
362
// optional customization used for advanced integration situations
355
363
customToolchain: UserToolchain ,
356
364
customPackageContainerProvider: PackageContainerProvider ? = . none,
@@ -369,15 +377,14 @@ public class Workspace {
369
377
forRootPackage: packagePath,
370
378
authorizationProvider: authorizationProvider,
371
379
configuration: configuration,
380
+ initializationWarningHandler: initializationWarningHandler,
372
381
customManifestLoader: manifestLoader,
373
382
customPackageContainerProvider: customPackageContainerProvider,
374
383
customRepositoryProvider: customRepositoryProvider,
375
384
delegate: delegate
376
385
)
377
386
}
378
387
379
-
380
-
381
388
// deprecate 12/21
382
389
@_disfavoredOverload
383
390
@available ( * , deprecated, message: " use alternative initializer " )
@@ -418,6 +425,7 @@ public class Workspace {
418
425
location: location,
419
426
authorizationProvider: authorizationProvider,
420
427
configuration: configuration,
428
+ initializationWarningHandler: . none,
421
429
customRegistriesConfiguration: registries,
422
430
customFingerprints: customFingerprintStorage,
423
431
customMirrors: mirrors,
@@ -533,6 +541,7 @@ public class Workspace {
533
541
location: Location ,
534
542
authorizationProvider: AuthorizationProvider ? = . none,
535
543
configuration: WorkspaceConfiguration ? = . none,
544
+ initializationWarningHandler: ( ( String ) -> Void ) ? = . none,
536
545
// optional customization, primarily designed for testing but also used in some cases by libSwiftPM consumers
537
546
customRegistriesConfiguration: RegistryConfiguration ? = . none,
538
547
customFingerprints: PackageFingerprintStorage ? = . none,
@@ -555,6 +564,7 @@ public class Workspace {
555
564
location: location,
556
565
authorizationProvider: authorizationProvider,
557
566
configuration: configuration,
567
+ initializationWarningHandler: initializationWarningHandler,
558
568
customRegistriesConfiguration: customRegistriesConfiguration,
559
569
customFingerprints: customFingerprints,
560
570
customMirrors: customMirrors,
@@ -578,6 +588,7 @@ public class Workspace {
578
588
location: Location ,
579
589
authorizationProvider: AuthorizationProvider ? ,
580
590
configuration: WorkspaceConfiguration ? ,
591
+ initializationWarningHandler: ( ( String ) -> Void ) ? ,
581
592
// optional customization, primarily designed for testing but also used in some cases by libSwiftPM consumers
582
593
customRegistriesConfiguration: RegistryConfiguration ? ,
583
594
customFingerprints: PackageFingerprintStorage ? ,
@@ -595,11 +606,11 @@ public class Workspace {
595
606
// delegate
596
607
delegate: WorkspaceDelegate ?
597
608
) throws {
598
- // we do not store the observabilityScope in the workspace initializer as the workspace is designed to be long lived.
609
+ // we do not store an observabilityScope in the workspace initializer as the workspace is designed to be long lived.
599
610
// instead, observabilityScope is passed into the individual workspace methods which are short lived.
600
-
611
+ let initializationWarningHandler = initializationWarningHandler ?? warnToStderr
601
612
// validate locations, returning a potentially modified one to deal with non-accessible or non-writable shared locations
602
- let location = try location. validatingSharedLocations ( fileSystem: fileSystem)
613
+ let location = try location. validatingSharedLocations ( fileSystem: fileSystem, warningHandler : initializationWarningHandler )
603
614
604
615
let currentToolsVersion = customToolsVersion ?? ToolsVersion . currentToolsVersion
605
616
let toolsVersionLoader = ToolsVersionLoader ( currentToolsVersion: currentToolsVersion)
@@ -623,6 +634,7 @@ public class Workspace {
623
634
path: location. repositoriesDirectory,
624
635
provider: repositoryProvider,
625
636
cachePath: configuration. sharedRepositoriesCacheEnabled ? location. sharedRepositoriesCacheDirectory : . none,
637
+ initializationWarningHandler: initializationWarningHandler,
626
638
delegate: delegate. map ( WorkspaceRepositoryManagerDelegate . init ( workspaceDelegate: ) )
627
639
)
628
640
@@ -680,7 +692,11 @@ public class Workspace {
680
692
681
693
self . configuration = configuration
682
694
683
- self . state = WorkspaceState ( fileSystem: fileSystem, storageDirectory: self . location. workingDirectory)
695
+ self . state = WorkspaceState (
696
+ fileSystem: fileSystem,
697
+ storageDirectory: self . location. workingDirectory,
698
+ initializationWarningHandler: initializationWarningHandler
699
+ )
684
700
}
685
701
}
686
702
@@ -4014,16 +4030,16 @@ extension FileSystem {
4014
4030
}
4015
4031
4016
4032
extension Workspace . Location {
4017
- func validatingSharedLocations( fileSystem: FileSystem ) throws -> Self {
4033
+ func validatingSharedLocations(
4034
+ fileSystem: FileSystem ,
4035
+ warningHandler: ( String ) -> Void
4036
+ ) throws -> Self {
4018
4037
var location = self
4019
4038
4020
- // local configuration directory must be accessible, throw if we cannot access it
4021
- //try fileSystem.withLock(on: location.localConfigurationDirectory, type: .exclusive, {})
4022
-
4023
4039
// check that shared configuration directory is accessible, or warn + reset if not
4024
4040
if let sharedConfigurationDirectory = self . sharedConfigurationDirectory {
4025
4041
// it may not always be possible to create default location (for example de to restricted sandbox)
4026
- let defaultDirectory = try ? fileSystem. getOrCreateSwiftPMConfigurationDirectory ( )
4042
+ let defaultDirectory = try ? fileSystem. getOrCreateSwiftPMConfigurationDirectory ( warningHandler : warningHandler )
4027
4043
if sharedConfigurationDirectory != defaultDirectory {
4028
4044
// custom location must be writable, throw if we cannot access it
4029
4045
try withTemporaryFile ( dir: sharedConfigurationDirectory) { _ in }
@@ -4033,9 +4049,7 @@ extension Workspace.Location {
4033
4049
try withTemporaryFile ( dir: sharedConfigurationDirectory) { _ in }
4034
4050
} catch {
4035
4051
location. sharedConfigurationDirectory = . none
4036
- // FIXME: We should emit a warning here using the diagnostic engine.
4037
- TSCBasic . stderrStream. write ( " warning: \( sharedConfigurationDirectory) is not accessible or not writable, disabling user-level configuration features. \( error) \n " )
4038
- TSCBasic . stderrStream. flush ( )
4052
+ warningHandler ( " \( sharedConfigurationDirectory) is not accessible or not writable, disabling user-level configuration features. \( error) " )
4039
4053
}
4040
4054
}
4041
4055
}
@@ -4053,9 +4067,7 @@ extension Workspace.Location {
4053
4067
try withTemporaryFile ( dir: sharedSecurityDirectory) { _ in }
4054
4068
} catch {
4055
4069
location. sharedSecurityDirectory = . none
4056
- // FIXME: We should emit a warning here using the diagnostic engine.
4057
- TSCBasic . stderrStream. write ( " warning: \( sharedSecurityDirectory) is not accessible or not writable, disabling user-level security features. \( error) \n " )
4058
- TSCBasic . stderrStream. flush ( )
4070
+ warningHandler ( " \( sharedSecurityDirectory) is not accessible or not writable, disabling user-level security features. \( error) " )
4059
4071
}
4060
4072
}
4061
4073
}
@@ -4073,12 +4085,15 @@ extension Workspace.Location {
4073
4085
try withTemporaryFile ( dir: sharedCacheDirectory) { _ in }
4074
4086
} catch {
4075
4087
location. sharedCacheDirectory = . none
4076
- // FIXME: We should emit a warning here using the diagnostic engine.
4077
- TSCBasic . stderrStream. write ( " warning: \( sharedCacheDirectory) is not accessible or not writable, disabling user-level cache features. \( error) \n " )
4078
- TSCBasic . stderrStream. flush ( )
4088
+ warningHandler ( " \( sharedCacheDirectory) is not accessible or not writable, disabling user-level cache features. \( error) " )
4079
4089
}
4080
4090
}
4081
4091
}
4082
4092
return location
4083
4093
}
4084
4094
}
4095
+
4096
+ fileprivate func warnToStderr( _ message: String ) {
4097
+ TSCBasic . stderrStream. write ( " warning: \( message) \n " )
4098
+ TSCBasic . stderrStream. flush ( )
4099
+ }
0 commit comments