Skip to content

Commit

Permalink
update 3
Browse files Browse the repository at this point in the history
  • Loading branch information
tinygiant98 committed Mar 30, 2024
1 parent 8a5cd17 commit 6995c1e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,12 @@ fields, it will be inherited from the package or parent.

All of these fields are repeatable.

| Field | Description |
| --- | --- |
| `include` | glob pattern matching files to include |
| `exclude` | glob pattern matching files to exclude |
| `filter` | glob pattern matching cached files to be excluded after compilation |
| Field | Description |
| --- | --- |
| `include` | glob pattern matching files to include |
| `exclude` | glob pattern matching files to exclude |
| `filter` | glob pattern matching cached files to be excluded after compilation |
| `skipCompile` | glob pattern matching files to exclude from compilation |

Refer to the [source trees](#source-trees) section to understand how these
fields are used by targets.
Expand Down Expand Up @@ -543,9 +544,9 @@ choice without changing the `nasher.cfg`.

#### Source Trees

A target's source tree is built from the `include`, `exclude`, and `filter`
fields. Remember, each of these are inherited from the `[package.sources]`
section if not specified in the `[target.sources]` section.
A target's source tree is built from the `include`, `exclude`,`filter` and
`skipCompile` fields. Remember, each of these are inherited from the
`[package.sources]` section if not specified in the `[target.sources]` section.

nasher uses [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming))
matching to identify desired files (e.g., `src/**/*.{nss,json}` matches all
Expand All @@ -556,12 +557,14 @@ matching to identify desired files (e.g., `src/**/*.{nss,json}` matches all
removed from the list.

Pack operations ([`convert`](#convert), [`compile`](#compile), [`pack`](#pack),
[`install`](#install), and [launch](#launch)) commands use the source tree as
[`install`](#install), and [`launch`](#launch)) commands use the source tree as
follows:

1. The `convert` and `compile` commands process the source files and output to a
cache directory.
2. Before the `pack` command is run, each cached file is checked against each
2. The `compile` command will prevent compilation of any files identified by
`skipCompile` in nasher.cfg; skipped files may still be used as includes.
3. Before the `pack` command is run, each cached file is checked against each
`filter` pattern; matches are excluded from the final packaged file. Note
that filters should not have any path information since they are compared to
files in the cache, not the source tree.
Expand Down Expand Up @@ -765,7 +768,7 @@ $ nasher config --list --local # local
#### Tips
* The `--` operator causes all following arguments to be treated as positional
arguments, even if they look like options. This is useful when setting config
keys to values starting with `-`: `nasher config -- nssFlags "-n /opt/nwn"`
keys to values starting with `-`: `nasher config --nssFlags "-n /opt/nwn"`
* Keys like `nssCompiler` and `installDir` work best as global options
* Keys like `modName` or `useModuleFolder` work best as local options
* `user.cfg` files are intentionally ignored by git. Do not include them in
Expand Down
25 changes: 12 additions & 13 deletions src/nasher/compile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ proc getIncludesUpdated(file: string,
updated[file] = true
return true

proc getUpdated(updatedNSS: var seq[string], files, skips: seq[string]): seq[string] =
proc getUpdated(updatedNSS: var seq[string], files: seq[string]): seq[string] =
let included = files.getIncludes
var updated: Table[string, bool]

for file in updatedNss:
updated[file] = true

for file in files:
if file.getIncludesUpdated(included, updated) and file notin skips:
if file.getIncludesUpdated(included, updated):
result.add(file)

updatedNss = result
Expand Down Expand Up @@ -159,6 +159,8 @@ proc compile*(opts: Options, target: Target, updatedNss: var seq[string], exitCo
withDir(cacheDir):
# If we are only compiling one file...
var scripts: seq[string]
let skips = target.skips.mapIt(it.extractFilename)

if cmd == "compile" and opts.hasKey("files"):
for file in opts["files"].split(';'):
let
Expand All @@ -178,7 +180,6 @@ proc compile*(opts: Options, target: Target, updatedNss: var seq[string], exitCo
else:
# Only compile scripts that have not been compiled since update
var files: seq[string]

for file in walkFiles("*.nss"):
files.add(file)
if file.executable:
Expand All @@ -190,16 +191,14 @@ proc compile*(opts: Options, target: Target, updatedNss: var seq[string], exitCo
debug("Recompiling", "executable script " & file)
updatedNss.add(file)

scripts = getUpdated(updatedNss, files, target.skips.mapIt(it.extractFilename))
scripts = getUpdated(updatedNss, files)
for script in scripts:
## Ensure any updated scripts have their compiled version deleted so
## they will be re-compiled if compilation fails for some reason.
removeFile(script.changeFileExt("ncs"))
removeFile(script.changeFileExt("ndb"))

for skip in target.skips.mapIt(it.extractFilename):
debug("skipCompile", skip);


scripts.keepItIf(it notin skips)
if scripts.len > 0:
let
chunkSize = opts.get("nssChunks", 500)
Expand All @@ -224,12 +223,12 @@ proc compile*(opts: Options, target: Target, updatedNss: var seq[string], exitCo
else:
display("Skipping", "compilation: nothing to compile")

let unmatchedNcs = executables.filterIt(not fileExists(it.changeFileExt("ncs")))
if unmatchedNcs.len > 0:
executables.keepItIf(not fileExists(it.changeFileExt("ncs")) and it notin skips)
if executables.len > 0:
warning("""
Compiled $1 of $2 scripts. The following executable scripts do not
have a matching compiled (.ncs) script file: $3""".dedent %
[$(scripts.len - unmatchedNcs.len), $scripts.len, unmatchedNcs.join(", ")])
Compiled only $1 of $2 scripts. The following executable scripts do not
have matching .ncs: $3""".dedent %
[$(scripts.len - executables.len), $scripts.len, executables.join(", ")])
if cmd in ["pack", "install", "serve", "test", "play"]:
let forced = getForceAnswer()
if abortOnCompileError != Answer.None:
Expand Down
9 changes: 0 additions & 9 deletions src/nasher/utils/shared.nim
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,11 @@ iterator walkSourceFiles*(target: Target): string =
if file notin excluded:
yield file

iterator walkSkippedFiles*(target: Target): string =
const globOpts = defaultGlobOptions - {GlobOption.DirLinks} + {GlobOption.Absolute}
for pattern in target.skips:
for file in walkGlob(pattern, options = globOpts):
yield file

proc getSourceFiles*(target: Target): seq[string] =
## Returns all files in the source tree matching include patterns while not
## matching exclude patterns.
toSeq(target.walkSourceFiles).deduplicate

proc getSkippedFiles*(target: Target): seq[string] =
toSeq(target.walkSkippedFiles).deduplicate

proc getTimeDiff*(a, b: Time): int =
## Compares two times and returns the difference in seconds. If 0, the files
## are the same age. If positive, a is newer than b. If negative, b is newer
Expand Down

0 comments on commit 6995c1e

Please sign in to comment.