mirror of
				https://github.com/Swatinem/rust-cache.git
				synced 2025-10-31 23:43:47 +00:00 
			
		
		
		
	feat: allow for configurable target-dir
This commit is contained in:
		
							parent
							
								
									063471b9dd
								
							
						
					
					
						commit
						f82d41bcc2
					
				| @ -12,6 +12,8 @@ process.on("uncaughtException", (e) => { | |||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| const cwd = core.getInput("working-directory"); | const cwd = core.getInput("working-directory"); | ||||||
|  | //todo: this could be read from .cargo config file directly
 | ||||||
|  | const targetDir = core.getInput("target-dir") || "./target"; | ||||||
| if (cwd) { | if (cwd) { | ||||||
|   process.chdir(cwd); |   process.chdir(cwd); | ||||||
| } | } | ||||||
| @ -180,13 +182,13 @@ export async function getPackages(): Promise<Packages> { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function cleanTarget(packages: Packages) { | export async function cleanTarget(packages: Packages) { | ||||||
|   await fs.promises.unlink("./target/.rustc_info.json"); |   await fs.promises.unlink(path.join(targetDir, "./.rustc_info.json")); | ||||||
|   await io.rmRF("./target/debug/examples"); |   await io.rmRF(path.join(targetDir, "./debug/examples")); | ||||||
|   await io.rmRF("./target/debug/incremental"); |   await io.rmRF(path.join(targetDir, "./debug/incremental")); | ||||||
| 
 | 
 | ||||||
|   let dir: fs.Dir; |   let dir: fs.Dir; | ||||||
|   // remove all *files* from debug
 |   // remove all *files* from debug
 | ||||||
|   dir = await fs.promises.opendir("./target/debug"); |   dir = await fs.promises.opendir(path.join(targetDir, "./debug")); | ||||||
|   for await (const dirent of dir) { |   for await (const dirent of dir) { | ||||||
|     if (dirent.isFile()) { |     if (dirent.isFile()) { | ||||||
|       await rm(dir.path, dirent); |       await rm(dir.path, dirent); | ||||||
| @ -194,8 +196,8 @@ export async function cleanTarget(packages: Packages) { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   const keepPkg = new Set(packages.map((p) => p.name)); |   const keepPkg = new Set(packages.map((p) => p.name)); | ||||||
|   await rmExcept("./target/debug/build", keepPkg); |   await rmExcept(path.join(targetDir, "./debug/build"), keepPkg); | ||||||
|   await rmExcept("./target/debug/.fingerprint", keepPkg); |   await rmExcept(path.join(targetDir, "./debug/.fingerprint"), keepPkg); | ||||||
| 
 | 
 | ||||||
|   const keepDeps = new Set( |   const keepDeps = new Set( | ||||||
|     packages.flatMap((p) => { |     packages.flatMap((p) => { | ||||||
| @ -207,7 +209,7 @@ export async function cleanTarget(packages: Packages) { | |||||||
|       return names; |       return names; | ||||||
|     }), |     }), | ||||||
|   ); |   ); | ||||||
|   await rmExcept("./target/debug/deps", keepDeps); |   await rmExcept(path.join(targetDir, "./debug/deps"), keepDeps); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const oneWeek = 7 * 24 * 3600 * 1000; | const oneWeek = 7 * 24 * 3600 * 1000; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user