@@ -247,7 +247,6 @@ public class Workspace {
247
247
/// - Parameters:
248
248
/// - fileSystem: The file system to use.
249
249
/// - location: Workspace location configuration.
250
- /// - registries: Configuration for registries
251
250
/// - authorizationProvider: Provider of authentication information for outbound network requests.
252
251
/// - configuration: Configuration to fine tune the dependency resolution behavior.
253
252
/// - customManifestLoader: Custom manifest loader. Used to customize how manifest are loaded.
@@ -288,6 +287,92 @@ public class Workspace {
288
287
)
289
288
}
290
289
290
+ /// A convenience method for creating a workspace for the given root
291
+ /// package path.
292
+ ///
293
+ /// The root package path is used to compute the build directory and other
294
+ /// default paths.
295
+ ///
296
+ /// - Parameters:
297
+ /// - fileSystem: The file system to use, defaults to local file system.
298
+ /// - forRootPackage: The path for the root package.
299
+ /// - authorizationProvider: Provider of authentication information for outbound network requests.
300
+ /// - configuration: Configuration to fine tune the dependency resolution behavior.
301
+ /// - customManifestLoader: Custom manifest loader. Used to customize how manifest are loaded.
302
+ /// - customPackageContainerProvider: Custom package container provider. Used to provide specialized package providers.
303
+ /// - customRepositoryProvider: Custom repository provider. Used to customize source control access.
304
+ /// - delegate: Delegate for workspace events
305
+ public convenience init (
306
+ fileSystem: FileSystem ? = . none,
307
+ forRootPackage packagePath: AbsolutePath ,
308
+ authorizationProvider: AuthorizationProvider ? = . none,
309
+ configuration: WorkspaceConfiguration ? = . none,
310
+ // optional customization used for advanced integration situations
311
+ customManifestLoader: ManifestLoaderProtocol ? = . none,
312
+ customPackageContainerProvider: PackageContainerProvider ? = . none,
313
+ customRepositoryProvider: RepositoryProvider ? = . none,
314
+ // delegate
315
+ delegate: WorkspaceDelegate ? = . none
316
+ ) throws {
317
+ let fileSystem = fileSystem ?? localFileSystem
318
+ let location = Location ( forRootPackage: packagePath, fileSystem: fileSystem)
319
+ try self . init (
320
+ fileSystem: fileSystem,
321
+ location: location,
322
+ customManifestLoader: customManifestLoader,
323
+ customPackageContainerProvider: customPackageContainerProvider,
324
+ customRepositoryProvider: customRepositoryProvider,
325
+ delegate: delegate
326
+ )
327
+ }
328
+
329
+ /// A convenience method for creating a workspace for the given root
330
+ /// package path.
331
+ ///
332
+ /// The root package path is used to compute the build directory and other
333
+ /// default paths.
334
+ ///
335
+ /// - Parameters:
336
+ /// - fileSystem: The file system to use, defaults to local file system.
337
+ /// - forRootPackage: The path for the root package.
338
+ /// - authorizationProvider: Provider of authentication information for outbound network requests.
339
+ /// - configuration: Configuration to fine tune the dependency resolution behavior.
340
+ /// - customToolchain: Custom toolchain. Used to create a customized ManifestLoader, customizing how manifest are loaded.
341
+ /// - customPackageContainerProvider: Custom package container provider. Used to provide specialized package providers.
342
+ /// - customRepositoryProvider: Custom repository provider. Used to customize source control access.
343
+ /// - delegate: Delegate for workspace events
344
+ public convenience init (
345
+ fileSystem: FileSystem ? = . none,
346
+ forRootPackage packagePath: AbsolutePath ,
347
+ authorizationProvider: AuthorizationProvider ? = . none,
348
+ configuration: WorkspaceConfiguration ? = . none,
349
+ // optional customization used for advanced integration situations
350
+ customToolchain: UserToolchain ,
351
+ customPackageContainerProvider: PackageContainerProvider ? = . none,
352
+ customRepositoryProvider: RepositoryProvider ? = . none,
353
+ // delegate
354
+ delegate: WorkspaceDelegate ? = . none
355
+ ) throws {
356
+ let fileSystem = fileSystem ?? localFileSystem
357
+ let location = Location ( forRootPackage: packagePath, fileSystem: fileSystem)
358
+ let manifestLoader = ManifestLoader (
359
+ toolchain: customToolchain. configuration,
360
+ cacheDir: location. sharedManifestsCacheDirectory
361
+ )
362
+ try self . init (
363
+ fileSystem: fileSystem,
364
+ forRootPackage: packagePath,
365
+ authorizationProvider: authorizationProvider,
366
+ configuration: configuration,
367
+ customManifestLoader: manifestLoader,
368
+ customPackageContainerProvider: customPackageContainerProvider,
369
+ customRepositoryProvider: customRepositoryProvider,
370
+ delegate: delegate
371
+ )
372
+ }
373
+
374
+
375
+
291
376
// deprecate 12/21
292
377
@_disfavoredOverload
293
378
@available ( * , deprecated, message: " use alternative initializer " )
@@ -406,64 +491,6 @@ public class Workspace {
406
491
}
407
492
}
408
493
409
- /// A convenience method for creating a workspace for the given root
410
- /// package path.
411
- ///
412
- /// The root package path is used to compute the build directory and other
413
- /// default paths.
414
- ///
415
- /// - Parameters:
416
- /// - fileSystem: The file system to use, defaults to local file system.
417
- /// - forRootPackage: The path for the root package.
418
- /// - customToolchain: A custom toolchain.
419
- /// - delegate: Delegate for workspace events
420
- public convenience init (
421
- fileSystem: FileSystem ? = . none,
422
- forRootPackage packagePath: AbsolutePath ,
423
- customToolchain: UserToolchain ,
424
- delegate: WorkspaceDelegate ? = . none
425
- ) throws {
426
- let fileSystem = fileSystem ?? localFileSystem
427
- let location = Location ( forRootPackage: packagePath, fileSystem: fileSystem)
428
- let manifestLoader = ManifestLoader (
429
- toolchain: customToolchain. configuration,
430
- cacheDir: location. sharedManifestsCacheDirectory
431
- )
432
- try self . init (
433
- fileSystem: fileSystem,
434
- forRootPackage: packagePath,
435
- customManifestLoader: manifestLoader,
436
- delegate: delegate
437
- )
438
- }
439
-
440
- /// A convenience method for creating a workspace for the given root
441
- /// package path.
442
- ///
443
- /// The root package path is used to compute the build directory and other
444
- /// default paths.
445
- ///
446
- /// - Parameters:
447
- /// - fileSystem: The file system to use, defaults to local file system.
448
- /// - forRootPackage: The path for the root package.
449
- /// - customManifestLoader: A custom manifest loader.
450
- /// - delegate: Delegate for workspace events
451
- public convenience init (
452
- fileSystem: FileSystem ? = . none,
453
- forRootPackage packagePath: AbsolutePath ,
454
- customManifestLoader: ManifestLoaderProtocol ? = . none,
455
- delegate: WorkspaceDelegate ? = . none
456
- ) throws {
457
- let fileSystem = fileSystem ?? localFileSystem
458
- let location = Location ( forRootPackage: packagePath, fileSystem: fileSystem)
459
- try self . init (
460
- fileSystem: fileSystem,
461
- location: location,
462
- customManifestLoader: customManifestLoader,
463
- delegate: delegate
464
- )
465
- }
466
-
467
494
/// A convenience method for creating a workspace for the given root
468
495
/// package path.
469
496
///
@@ -478,9 +505,10 @@ public class Workspace {
478
505
delegate: WorkspaceDelegate ? = nil ,
479
506
identityResolver: IdentityResolver ? = nil
480
507
) -> Workspace {
481
- let workspace = try ! Workspace ( forRootPackage: packagePath,
482
- customManifestLoader: manifestLoader,
483
- delegate: delegate
508
+ let workspace = try ! Workspace (
509
+ forRootPackage: packagePath,
510
+ customManifestLoader: manifestLoader,
511
+ delegate: delegate
484
512
)
485
513
if let repositoryManager = repositoryManager {
486
514
workspace. repositoryManager = repositoryManager
@@ -562,12 +590,11 @@ public class Workspace {
562
590
// delegate
563
591
delegate: WorkspaceDelegate ?
564
592
) throws {
565
- // we do not take an observabilityScope in the workspace initializer as the workspace is designed to be long lived.
593
+ // we do not store the observabilityScope in the workspace initializer as the workspace is designed to be long lived.
566
594
// instead, observabilityScope is passed into the individual workspace methods which are short lived.
567
- // however, the workspace initializer may need to emit diagnostics, for which a consumer like the CLI can set as a thread local
568
- let observabilityScope = Thread . current. threadDictionary [ " observabilityScope " ] as? ObservabilityScope
595
+
569
596
// validate locations, returning a potentially modified one to deal with non-accessible or non-writable shared locations
570
- let location = try location. validatingSharedLocations ( fileSystem: fileSystem, observabilityScope : observabilityScope )
597
+ let location = try location. validatingSharedLocations ( fileSystem: fileSystem)
571
598
572
599
let currentToolsVersion = customToolsVersion ?? ToolsVersion . currentToolsVersion
573
600
let toolsVersionLoader = ToolsVersionLoader ( currentToolsVersion: currentToolsVersion)
@@ -590,8 +617,8 @@ public class Workspace {
590
617
fileSystem: fileSystem,
591
618
path: location. repositoriesDirectory,
592
619
provider: repositoryProvider,
593
- delegate : delegate . map ( WorkspaceRepositoryManagerDelegate . init ( workspaceDelegate : ) ) ,
594
- cachePath : configuration . sharedRepositoriesCacheEnabled ? location . sharedRepositoriesCacheDirectory : . none
620
+ cachePath : configuration . sharedRepositoriesCacheEnabled ? location . sharedRepositoriesCacheDirectory : . none ,
621
+ delegate : delegate . map ( WorkspaceRepositoryManagerDelegate . init ( workspaceDelegate : ) )
595
622
)
596
623
597
624
let fingerprints = customFingerprints ?? location. sharedFingerprintsDirectory. map {
@@ -654,7 +681,7 @@ public class Workspace {
654
681
655
682
self . configuration = configuration
656
683
657
- self . state = WorkspaceState ( dataPath : self . location. workingDirectory, fileSystem : fileSystem )
684
+ self . state = WorkspaceState ( fileSystem : fileSystem , storageDirectory : self . location. workingDirectory)
658
685
}
659
686
}
660
687
@@ -3847,7 +3874,7 @@ extension Workspace.Location {
3847
3874
}
3848
3875
3849
3876
extension Workspace . Location {
3850
- func validatingSharedLocations( fileSystem: FileSystem , observabilityScope : ObservabilityScope ? ) throws -> Self {
3877
+ func validatingSharedLocations( fileSystem: FileSystem ) throws -> Self {
3851
3878
var location = self
3852
3879
3853
3880
// local configuration directory must be accessible, throw if we cannot access it
@@ -3856,7 +3883,7 @@ extension Workspace.Location {
3856
3883
// check that shared configuration directory is accessible, or warn + reset if not
3857
3884
if let sharedConfigurationDirectory = self . sharedConfigurationDirectory {
3858
3885
// it may not always be possible to create default location (for example de to restricted sandbox)
3859
- let defaultDirectory = try ? fileSystem. getOrCreateSwiftPMConfigurationDirectory ( observabilityScope : observabilityScope )
3886
+ let defaultDirectory = try ? fileSystem. getOrCreateSwiftPMConfigurationDirectory ( )
3860
3887
if sharedConfigurationDirectory != defaultDirectory {
3861
3888
// custom location must be writable, throw if we cannot access it
3862
3889
try fileSystem. withLock ( on: sharedConfigurationDirectory. appending ( component: " test " ) , type: . exclusive, { } )
@@ -3865,8 +3892,10 @@ extension Workspace.Location {
3865
3892
do {
3866
3893
try fileSystem. withLock ( on: sharedConfigurationDirectory. appending ( component: " test " ) , type: . exclusive, { } )
3867
3894
} catch {
3868
- observabilityScope? . emit ( warning: " \( sharedConfigurationDirectory) is not writable, disabling user-level configuration features. \( error) " )
3869
3895
location. sharedConfigurationDirectory = . none
3896
+ // FIXME: We should emit a warning here using the diagnostic engine.
3897
+ TSCBasic . stderrStream. write ( " warning: \( sharedConfigurationDirectory) is not writable, disabling user-level configuration features. \( error) \n " )
3898
+ TSCBasic . stderrStream. flush ( )
3870
3899
}
3871
3900
}
3872
3901
}
@@ -3883,8 +3912,10 @@ extension Workspace.Location {
3883
3912
do {
3884
3913
try fileSystem. withLock ( on: sharedSecurityDirectory. appending ( component: " test " ) , type: . exclusive, { } )
3885
3914
} catch {
3886
- observabilityScope? . emit ( warning: " \( sharedSecurityDirectory) is not writable, disabling user-level security features. \( error) " )
3887
3915
location. sharedSecurityDirectory = . none
3916
+ // FIXME: We should emit a warning here using the diagnostic engine.
3917
+ TSCBasic . stderrStream. write ( " warning: \( sharedSecurityDirectory) is not writable, disabling user-level security features. \( error) \n " )
3918
+ TSCBasic . stderrStream. flush ( )
3888
3919
}
3889
3920
}
3890
3921
}
@@ -3901,8 +3932,10 @@ extension Workspace.Location {
3901
3932
do {
3902
3933
try fileSystem. withLock ( on: sharedCacheDirectory. appending ( component: " test " ) , type: . exclusive, { } )
3903
3934
} catch {
3904
- observabilityScope? . emit ( warning: " \( sharedCacheDirectory) is not writable, disabling user-level cache features. \( error) " )
3905
3935
location. sharedCacheDirectory = . none
3936
+ // FIXME: We should emit a warning here using the diagnostic engine.
3937
+ TSCBasic . stderrStream. write ( " warning: \( sharedCacheDirectory) is not writable, disabling user-level cache features. \( error) \n " )
3938
+ TSCBasic . stderrStream. flush ( )
3906
3939
}
3907
3940
}
3908
3941
}
0 commit comments