Skip to content

Commit

Permalink
add skipCompile option for nasher.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
tinygiant98 committed Mar 30, 2024
1 parent cefdb23 commit 18abf62
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 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
16 changes: 9 additions & 7 deletions src/nasher/compile.nim
Original file line number Diff line number Diff line change
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 @@ -196,7 +197,8 @@ proc compile*(opts: Options, target: Target, updatedNss: var seq[string], exitCo
## they will be re-compiled if compilation fails for some reason.
removeFile(script.changeFileExt("ncs"))
removeFile(script.changeFileExt("ndb"))


scripts.keepItIf(it notin skips)
if scripts.len > 0:
let
chunkSize = opts.get("nssChunks", 500)
Expand All @@ -221,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
4 changes: 3 additions & 1 deletion src/nasher/utils/target.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type
Target* = ref object
name*, description*, file*, branch*, parent*: string
modName*, modMinGameVersion*, modDescription*: string
includes*, excludes*, filters*, flags*, groups*: seq[string]
includes*, excludes*, filters*, flags*, groups*, skips*: seq[string]
variables*: seq[KeyValuePair]
rules*: seq[Rule]

Expand Down Expand Up @@ -212,6 +212,7 @@ proc parseCfgPackage(s: Stream, filename = "nasher.cfg"): seq[Target] =
of "source", "include": target.includes.add(e.value)
of "exclude": target.excludes.add(e.value)
of "filter": target.filters.add(e.value)
of "skipCompile": target.skips.add(e.value)
# Unused, but kept for backwards compatibility
of "version", "url", "author": discard
else:
Expand All @@ -225,6 +226,7 @@ proc parseCfgPackage(s: Stream, filename = "nasher.cfg"): seq[Target] =
of "include": target.includes.add(e.value)
of "exclude": target.excludes.add(e.value)
of "filter": target.filters.add(e.value)
of "skipCompile": target.skips.add(e.value)
else:
p.raisePackageError("invalid key $1 for section [$2$3]" %
[e.key.escape, if context.len > 0: context & "." else: "", section])
Expand Down

0 comments on commit 18abf62

Please sign in to comment.