Procs
proc sleep(milsecs: int) {...}{.raises: [], tags: [].}
- Sleep at compile time
proc execAction(cmd: string; retry = 0; die = true; cache = false; cacheKey = ""; onRetry: proc () = nil; onError: proc (output: string; err: int) = nil): tuple[ output: string, ret: int] {...}{.raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
-
Execute an external command - supported at compile time
Checks if command exits successfully before returning. If not, an error is raised. Always caches results to be used in nimsuggest or nimcheck mode.
retry - number of times command should be retried before error die = false - return on errors cache = true - cache results unless cleared with -f cacheKey - key to create unique cache entry onRetry() - proc to call before retrying onError(output, err) - proc to call on error
proc findExe(exe: string): string {...}{.raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
- Find the specified executable using the which/where command - supported at compile time
proc mkDir(dir: string) {...}{.raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ ReadDirEffect, ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect].}
-
Create a directory at compile time
The os module is not available at compile time so a few crucial helper functions are included with nimterop.
proc cpFile(source, dest: string; psymlink = false; move = false) {...}{. raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
-
Copy a file from source to dest at compile time
psymlink = true preserves symlinks instead of dereferencing on posix
proc mvFile(source, dest: string) {...}{.raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
- Move a file from source to dest at compile time
proc rmFile(source: string; dir = false) {...}{.raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ReadDirEffect, ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect].}
- Remove a file or pattern at compile time
proc rmDir(dir: string) {...}{.raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ ReadDirEffect, ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect].}
- Remove a directory or pattern at compile time
proc cleanDir(dir: string) {...}{.raises: [OSError, ValueError, Exception, IOError, KeyError], tags: [ ReadDirEffect, ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect].}
- Remove all contents of a directory at compile time
proc cpTree(source, dest: string; move = false) {...}{. raises: [OSError, ValueError, Exception, IOError, KeyError], tags: [ReadDirEffect, ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect].}
- Copy contents of source dir to the destination, not the directory itself
proc mvTree(source, dest: string) {...}{.raises: [OSError, ValueError, Exception, IOError, KeyError], tags: [ReadDirEffect, ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect].}
- Move contents of source dir to the destination, not the directory itself
proc getFileDate(fullpath: string): string {...}{. raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
- Get file date for fullpath
proc touchFile(fullpath: string) {...}{.raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
- Touch file to update modified date
proc extractZip(zipfile, outdir: string; quiet = false) {...}{. raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
- Extract a zip file using powershell on Windows and unzip on other systems to the specified output directory
proc extractTar(tarfile, outdir: string; quiet = false) {...}{. raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
- Extract a tar file using tar, 7z or 7za to the specified output directory
proc downloadUrl(url, outdir: string; quiet = false; retry = 1) {...}{. raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ReadDirEffect, ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect].}
-
Download a file using curl or wget (or powershell on Windows) to the specified directory
If an archive file, it is automatically extracted after download.
proc gitReset(outdir: string) {...}{.raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
- Hard reset the git repository at the specified directory
proc gitCheckout(file, outdir: string) {...}{.raises: [Exception, ValueError, OSError, IOError, KeyError], tags: [RootEffect, ExecIOEffect, ReadIOEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
-
Checkout the specified file in the git repository at outdir
This effectively resets all changes in the file and can be used to undo any changes that were made to source files to enable successful wrapping with cImport() or c2nImport().
proc gitAtCheckout(outdir, checkout: string): bool {...}{. raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
- Check if specified git repository is checked out to the specified commit hash, tag or branch
proc gitDefaultBranch(outdir: string): string {...}{. raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
- Get the default branch for a git repository before it is pulled
proc gitPull(url: string; outdir = ""; plist = ""; checkout = ""; quiet = false) {...}{. raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ReadDirEffect, ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect].}
-
Pull the specified git repository to the output directory
plist is the list of specific files and directories or wildcards to sparsely checkout. Multiple values can be specified one entry per line. It is optional and if omitted, the entire repository will be checked out.
checkout is the git tag, branch or commit hash to checkout once the repository is downloaded. This allows for pinning to a specific version of the code.
proc gitTags(outdir: string): seq[string] {...}{.raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
- Get all the git tags in the specified directory
proc findFiles(file: string; dir: string; recurse = true; regex = false): seq[string] {...}{. raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
-
Find all matching files in the specified directory
file is a regular expression if regex is true
Turn off recursive search with recurse
proc findFile(file: string; dir: string; recurse = true; first = false; regex = false): string {...}{. raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
-
Find the file in the specified directory
file is a regular expression if regex is true
Turn off recursive search with recurse and stop on first match with first. Without it, the shortest match is returned.
proc linkLibs(names: openArray[string]; staticLink = true): string {...}{. raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
-
Create linker flags for specified libraries using pkg-config
Prepends lib to the name so you only need ssl for libssl.
proc getNumProcs(): string {...}{.raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
- Get number of processors
proc getProjectCacheDir(name: string; forceClean = true): string {...}{. raises: [ValueError, OSError, Exception, IOError, KeyError], tags: [ExecIOEffect, ReadIOEffect, RootEffect, WriteIOEffect, ReadEnvEffect, ReadDirEffect].}
-
Get a cache directory where all nimterop artifacts can be stored
Projects can use this location to download source code and build binaries that can be then accessed by multiple apps. This is created under the per-user Nim cache directory.
Use name to specify the subdirectory name for a project.
forceClean is enabled by default and effectively deletes the folder if Nim is compiled with the -f or --forceBuild flag. This allows any project to start out with a clean cache dir on a forced build.
NOTE: avoid calling getProjectCacheDir() multiple times on the same name when forceClean = true else checked out source might get deleted at the wrong time during build.
- E.g.
nimgit2 downloads libgit2 source so name = "libgit2"
nimarchive downloads libarchive, bzlib, liblzma and zlib so name = "nimarchive" / "libarchive" for libarchive, etc.