File tree Expand file tree Collapse file tree 4 files changed +67
-0
lines changed
Expand file tree Collapse file tree 4 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -274,6 +274,13 @@ typedef struct {
274274
275275 //=== Scanner CAS Operations ----------------------------------------------===//
276276 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 );
277284 void (* swiftscan_cas_options_dispose )(swiftscan_cas_options_t options );
278285 void (* swiftscan_cas_options_set_ondisk_path )(swiftscan_cas_options_t options ,
279286 const char * path );
Original file line number Diff line number Diff line change @@ -300,6 +300,17 @@ internal extension swiftscan_diagnostic_severity_t {
300300#endif
301301 }
302302
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+
303314 @_spi ( Testing) public var supportsBridgingHeaderPCHCommand : Bool {
304315 return api. swiftscan_swift_textual_detail_get_bridging_pch_command_line != nil
305316 }
@@ -511,6 +522,9 @@ private extension swiftscan_functions_t {
511522 self . swiftscan_cas_options_set_plugin_option = try loadOptional ( " swiftscan_cas_options_set_plugin_option " )
512523 self . swiftscan_cas_options_dispose = try loadOptional ( " swiftscan_cas_options_dispose " )
513524 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 " )
514528 self . swiftscan_cas_dispose = try loadOptional ( " swiftscan_cas_dispose " )
515529 self . swiftscan_cache_compute_key = try loadOptional ( " swiftscan_cache_compute_key " )
516530 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,29 @@ public final class SwiftScanCAS {
198198 return try scanner. toSwiftString ( casid)
199199 }
200200
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+ return size == - 1 ? nil : size
210+ }
211+
212+ public func setSizeLimit( _ size: Int64 ) throws {
213+ _ = try scanner. handleCASError { err_msg in
214+ scanner. api. swiftscan_cas_set_ondisk_size_limit ( cas, size, & err_msg)
215+ }
216+ }
217+
218+ public func prune( ) throws {
219+ _ = try scanner. handleCASError { err_msg in
220+ scanner. api. swiftscan_cas_prune_ondisk_data ( cas, & err_msg)
221+ }
222+ }
223+
201224 @available ( * , deprecated)
202225 public func computeCacheKey( commandLine: [ String ] , input: String ) throws -> String {
203226 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 {
849849 }
850850 }
851851 }
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 XCTUnwrap ( try cas. getStorageSize ( ) )
865+ let dataToStore = Data ( count: 1000 )
866+ _ = try cas. store ( data: dataToStore)
867+ let postSize = try XCTUnwrap ( try cas. getStorageSize ( ) )
868+ XCTAssertTrue ( postSize > preSize)
869+
870+ // Try prune.
871+ try cas. setSizeLimit ( 100 )
872+ try cas. prune ( )
873+ }
874+ }
852875}
You can’t perform that action at this time.
0 commit comments