@@ -231,6 +231,28 @@ proc buildFromDir(pkgInfo: PackageInfo, paths: HashSet[string],
231231 cd pkgDir: # Make sure `execHook` executes the correct .nimble file.
232232 discard execHook (options, actionBuild, false )
233233
234+ proc cleanFromDir (pkgInfo: PackageInfo , options: Options ) =
235+ # # Clean up build files.
236+ # Handle pre-`clean` hook.
237+ let pkgDir = pkgInfo.myPath.parentDir ()
238+
239+ cd pkgDir: # Make sure `execHook` executes the correct .nimble file.
240+ if not execHook (options, actionClean, true ):
241+ raise nimbleError (" Pre-hook prevented further execution." )
242+
243+ if pkgInfo.bin.len == 0 :
244+ return
245+
246+ for bin, _ in pkgInfo.bin:
247+ let outputDir = pkgInfo.getOutputDir (" " )
248+ if dirExists (outputDir):
249+ if fileExists (outputDir / bin):
250+ removeFile (outputDir / bin)
251+
252+ # Handle post-`clean` hook.
253+ cd pkgDir: # Make sure `execHook` executes the correct .nimble file.
254+ discard execHook (options, actionClean, false )
255+
234256proc promptRemoveEntirePackageDir (pkgDir: string , options: Options ) =
235257 let exceptionMsg = getCurrentExceptionMsg ()
236258 let warningMsgEnd = if exceptionMsg.len > 0 : & " : { exceptionMsg} " else : " ."
@@ -689,6 +711,12 @@ proc build(options: Options) =
689711 var args = options.getCompilationFlags ()
690712 buildFromDir (pkgInfo, paths, args, options)
691713
714+ proc clean (options: Options ) =
715+ let dir = getCurrentDir ()
716+ let pkgInfo = getPkgInfo (dir, options)
717+ nimScriptHint (pkgInfo)
718+ cleanFromDir (pkgInfo, options)
719+
692720proc execBackend (pkgInfo: PackageInfo , options: Options ) =
693721 let
694722 bin = options.getCompilationBinary (pkgInfo).get (" " )
@@ -1862,6 +1890,8 @@ proc doAction(options: var Options) =
18621890 listPaths (options)
18631891 of actionBuild:
18641892 build (options)
1893+ of actionClean:
1894+ clean (options)
18651895 of actionRun:
18661896 run (options)
18671897 of actionCompile, actionDoc:
0 commit comments