mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
Essentially this PR removes the `{.error.}` pragmas littered around in
the OS module and submodules which prevents them from being imported if
the target OS is not supported. This made it impossible to use certain
supported features of the OS module in macros from a supported host OS.
Instead of the `{.error.}` pragmas the `oscommon` module now has a
constant `supportedSystem` which is false in the cases where the
`{.error.}` pragmas where generated. All procedures which can't be run
by macros is also not declared when `supportedSystem` is false.
It would be possible to create dummy versions of the omitted functions
with an `{.error.}` pragma that would trigger upon their use, but this
is currently not done.
This properly fixes #19414
39 lines
1.6 KiB
Nim
39 lines
1.6 KiB
Nim
## This module implements path handling like os module but works at only compile-time.
|
|
## This module works even when cross compiling to OS that is not supported by os module.
|
|
|
|
when defined(nimPreviewSlimSystem):
|
|
import std/assertions
|
|
|
|
proc staticFileExists*(filename: string): bool {.compileTime.} =
|
|
## Returns true if `filename` exists and is a regular file or symlink.
|
|
##
|
|
## Directories, device files, named pipes and sockets return false.
|
|
raiseAssert "implemented in the vmops"
|
|
|
|
proc staticDirExists*(dir: string): bool {.compileTime.} =
|
|
## Returns true if the directory `dir` exists. If `dir` is a file, false
|
|
## is returned. Follows symlinks.
|
|
raiseAssert "implemented in the vmops"
|
|
|
|
type
|
|
PathComponent* = enum ## Enumeration specifying a path component.
|
|
##
|
|
## See also:
|
|
## * `walkDirRec iterator`_
|
|
## * `FileInfo object`_
|
|
pcFile, ## path refers to a file
|
|
pcLinkToFile, ## path refers to a symbolic link to a file
|
|
pcDir, ## path refers to a directory
|
|
pcLinkToDir ## path refers to a symbolic link to a directory
|
|
|
|
proc staticWalkDir*(dir: string; relative = false): seq[
|
|
tuple[kind: PathComponent, path: string]] {.compileTime.} =
|
|
## Walks over the directory `dir` and returns a seq with each directory or
|
|
## file in `dir`. The component type and full path for each item are returned.
|
|
##
|
|
## Walking is not recursive.
|
|
## * If `relative` is true (default: false)
|
|
## the resulting path is shortened to be relative to ``dir``,
|
|
## otherwise the full path is returned.
|
|
raiseAssert "implemented in the vmops"
|