File tree 4 files changed +70
-0
lines changed
4 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -274,6 +274,13 @@ typedef struct {
274
274
275
275
//=== Scanner CAS Operations ----------------------------------------------===//
276
276
swiftscan_cas_options_t (* swiftscan_cas_options_create )(void );
277
+ int64_t (* swiftscan_cas_get_ondisk_size )(swiftscan_cas_t ,
278
+ swiftscan_string_ref_t * error );
279
+ bool (* swiftscan_cas_set_ondisk_size_limit )(swiftscan_cas_t ,
280
+ int64_t size_limit ,
281
+ swiftscan_string_ref_t * error );
282
+ bool (* swiftscan_cas_prune_ondisk_data )(swiftscan_cas_t ,
283
+ swiftscan_string_ref_t * error );
277
284
void (* swiftscan_cas_options_dispose )(swiftscan_cas_options_t options );
278
285
void (* swiftscan_cas_options_set_ondisk_path )(swiftscan_cas_options_t options ,
279
286
const char * path );
Original file line number Diff line number Diff line change @@ -300,6 +300,17 @@ internal extension swiftscan_diagnostic_severity_t {
300
300
#endif
301
301
}
302
302
303
+ @_spi ( Testing) public var supportsCASSizeManagement : Bool {
304
+ #if os(Windows)
305
+ // CAS is currently not supported on Windows hosts.
306
+ return false
307
+ #else
308
+ return api. swiftscan_cas_get_ondisk_size != nil &&
309
+ api. swiftscan_cas_set_ondisk_size_limit != nil &&
310
+ api. swiftscan_cas_prune_ondisk_data != nil
311
+ #endif
312
+ }
313
+
303
314
@_spi ( Testing) public var supportsBridgingHeaderPCHCommand : Bool {
304
315
return api. swiftscan_swift_textual_detail_get_bridging_pch_command_line != nil
305
316
}
@@ -511,6 +522,9 @@ private extension swiftscan_functions_t {
511
522
self . swiftscan_cas_options_set_plugin_option = try loadOptional ( " swiftscan_cas_options_set_plugin_option " )
512
523
self . swiftscan_cas_options_dispose = try loadOptional ( " swiftscan_cas_options_dispose " )
513
524
self . swiftscan_cas_create_from_options = try loadOptional ( " swiftscan_cas_create_from_options " )
525
+ self . swiftscan_cas_get_ondisk_size = try loadOptional ( " swiftscan_cas_get_ondisk_size " )
526
+ self . swiftscan_cas_set_ondisk_size_limit = try loadOptional ( " swiftscan_cas_set_ondisk_size_limit " )
527
+ self . swiftscan_cas_prune_ondisk_data = try loadOptional ( " swiftscan_cas_prune_ondisk_data " )
514
528
self . swiftscan_cas_dispose = try loadOptional ( " swiftscan_cas_dispose " )
515
529
self . swiftscan_cache_compute_key = try loadOptional ( " swiftscan_cache_compute_key " )
516
530
self . swiftscan_cache_compute_key_from_input_index = try loadOptional ( " swiftscan_cache_compute_key_from_input_index " )
Original file line number Diff line number Diff line change @@ -198,6 +198,32 @@ public final class SwiftScanCAS {
198
198
return try scanner. toSwiftString ( casid)
199
199
}
200
200
201
+ public var supportsSizeManagement : Bool {
202
+ scanner. supportsCASSizeManagement
203
+ }
204
+
205
+ public func getStorageSize( ) throws -> Int64 {
206
+ let size = try scanner. handleCASError { err_msg in
207
+ scanner. api. swiftscan_cas_get_ondisk_size ( cas, & err_msg)
208
+ }
209
+ if size == - 1 {
210
+ throw DependencyScanningError . casError ( " CAS storage size query is not supported " )
211
+ }
212
+ return size
213
+ }
214
+
215
+ public func setSizeLimit( _ size: Int64 ) throws {
216
+ _ = try scanner. handleCASError { err_msg in
217
+ scanner. api. swiftscan_cas_set_ondisk_size_limit ( cas, size, & err_msg)
218
+ }
219
+ }
220
+
221
+ public func prune( ) throws {
222
+ _ = try scanner. handleCASError { err_msg in
223
+ scanner. api. swiftscan_cas_prune_ondisk_data ( cas, & err_msg)
224
+ }
225
+ }
226
+
201
227
@available ( * , deprecated)
202
228
public func computeCacheKey( commandLine: [ String ] , input: String ) throws -> String {
203
229
let casid = try scanner. handleCASError { err_msg in
Original file line number Diff line number Diff line change @@ -849,4 +849,27 @@ final class CachingBuildTests: XCTestCase {
849
849
}
850
850
}
851
851
}
852
+
853
+ func testCASManagement( ) throws {
854
+ try withTemporaryDirectory { path in
855
+ let casPath = path. appending ( component: " cas " )
856
+ let driver = try Driver ( args: [ " swiftc " , " -v " ] )
857
+ let scanLibPath = try XCTUnwrap ( driver. getSwiftScanLibPath ( ) )
858
+ try dependencyOracle. verifyOrCreateScannerInstance ( fileSystem: localFileSystem,
859
+ swiftScanLibPath: scanLibPath)
860
+ let cas = try dependencyOracle. getOrCreateCAS ( pluginPath: nil , onDiskPath: casPath, pluginOptions: [ ] )
861
+ guard cas. supportsSizeManagement else {
862
+ throw XCTSkip ( " CAS size management is not supported " )
863
+ }
864
+ let preSize = try cas. getStorageSize ( )
865
+ let dataToStore = Data ( count: 1000 )
866
+ _ = try cas. store ( data: dataToStore)
867
+ let postSize = try cas. getStorageSize ( )
868
+ XCTAssertTrue ( postSize > preSize)
869
+
870
+ // Try prune.
871
+ try cas. setSizeLimit ( 100 )
872
+ try cas. prune ( )
873
+ }
874
+ }
852
875
}
You can’t perform that action at this time.
0 commit comments