Skip to content

Let the environment say where the library lives - #36

Merged
gitosaurus merged 1 commit into
mainfrom
feat/include-env-var
Aug 6, 2026
Merged

Let the environment say where the library lives#36
gitosaurus merged 1 commit into
mainfrom
feat/include-env-var

Conversation

@gitosaurus

Copy link
Copy Markdown
Owner

ARCHETYPE_INCLUDE is a colon-separated search path, in the shape PATH taught
everyone to expect. It is consulted after --include, so an explicit flag
still wins, and after the source file's own directory, which primarySource has
always pushed to the front — so nothing changes for a game sitting beside the
library it includes.

The motivating case is a packaged interpreter. The snap in #35 knows perfectly
well where standard.arch ended up inside its own squashfs; without this the
player has to know too, and type
--include=/snap/archetype/current/usr/share/archetype/games. A package can set
the variable once and let archetype --source=mygame.arch simply work.

Two edge cases, both deliberate:

  • Set but empty counts as unset, the way an empty environment variable
    usually does.
  • An empty entry within a list still means the current directory, the way it
    does in PATH. So --include=a: is unchanged.

The split is done on the string_view in place rather than through an
istringstream, so the only strings allocated are the ones actually kept — which
addSearchPath takes by value and moves.

The debug trace

SHOW(path) is gone, and the answer to "wasn't that debug-only?" is yes, and
that was not enough
. It was guarded by #if NDEBUG, but cmake -S src -B build
— the build this project documents — sets no CMAKE_BUILD_TYPE, so CMake passes
no -DNDEBUG and the guard never fired. It has printed path == games on every
compile anyone has run. With that call removed the macro had no users left in
main.cc, so it went too. (TestExpression.cc defines its own, untouched.)

Test plan

  • ./build/archetype --test — 17 suites, 0 failures.
  • Out-of-tree source (mygame.arch in a temp dir, library in games/), which is
    the case the snap cares about:
    • no include at all → fails, Cannot open source file "standard"
    • ARCHETYPE_INCLUDE only → compiles
    • ARCHETYPE_INCLUDE="" → fails, i.e. treated as unset
    • ARCHETYPE_INCLUDE=/nonexistent:games → compiles, second entry found
    • --include present with a bogus env value → compiles, flag wins
  • The .acx produced via the variable is byte-identical to the one produced
    via the flag, and to the in-tree compile: 69,784 bytes.

Once this lands, #35 should gain an environment: stanza setting the variable,
and lose the long path from its description.

🤖 Generated with Claude Code

https://claude.ai/code/session_019g4fqvhoV5MtLJJXM7uFLZ

ARCHETYPE_INCLUDE is a colon-separated search path in the shape PATH taught
everyone to expect.  It is consulted after --include, so an explicit flag
still wins, and after the source file's own directory, which primarySource
has always pushed to the front -- so nothing changes for a game sitting
beside the library it includes.

The motivating case is a packaged interpreter.  The snap knows perfectly well
where standard.arch ended up inside its own squashfs; without this the player
has to know too, and type it.  A package can now set the variable once and
have `archetype --source=mygame.arch` simply work.

Set but empty counts as unset, the way it usually does.  An empty entry
*within* a list still means the current directory, the way it does in PATH,
so --include=a: is unchanged.

Splitting the view in place rather than through an istringstream means the
only strings allocated are the ones actually kept, which addSearchPath takes
by value and moves.

The SHOW(path) trace went with the block it lived in.  It was guarded by
`#if NDEBUG` and so was only ever meant for a debug build, but the build this
project documents sets no CMAKE_BUILD_TYPE, CMake therefore passes no
-DNDEBUG, and the trace printed on every compile anyone has ever run.  With
that call gone the macro had no users left, so it is gone as well.

Verified that a game compiled by way of the variable is byte-for-byte the
game compiled by way of the flag.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019g4fqvhoV5MtLJJXM7uFLZ
@gitosaurus
gitosaurus merged commit 109d5c3 into main Aug 6, 2026
3 of 4 checks passed
@gitosaurus
gitosaurus deleted the feat/include-env-var branch August 6, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant