From 18abf62b0172bf06809760fb91d13ddf1997b068 Mon Sep 17 00:00:00 2001 From: Ed Burke Date: Thu, 7 Mar 2024 11:52:46 -0500 Subject: [PATCH] add skipCompile option for nasher.cfg --- README.md | 25 ++++++++++++++----------- src/nasher/compile.nim | 16 +++++++++------- src/nasher/utils/target.nim | 4 +++- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 16ae6ed..bf92c53 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -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. @@ -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 diff --git a/src/nasher/compile.nim b/src/nasher/compile.nim index 859f05d..ac46a9b 100644 --- a/src/nasher/compile.nim +++ b/src/nasher/compile.nim @@ -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 @@ -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: @@ -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) @@ -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: diff --git a/src/nasher/utils/target.nim b/src/nasher/utils/target.nim index 0e93944..ddc7cf7 100644 --- a/src/nasher/utils/target.nim +++ b/src/nasher/utils/target.nim @@ -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] @@ -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: @@ -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])