Skip to content

scriptelement.py, buildelement.py: Report relative directories as errors - #2212

Merged
juergbi merged 2 commits into
apache:masterfrom
Thanatos9404:thanatos/relative-work-directory
Nov 6, 2026
Merged

juergbi merged 2 commits into
apache:masterfrom
Thanatos9404:thanatos/relative-work-directory

Conversation

@Thanatos9404

@Thanatos9404 Thanatos9404 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

A script element with a relative cwd, like the cwd: elements in the issue, loads fine and then trips the assertion in Sandbox.set_work_directory() during the build, which shows up as a BUG with a traceback. A relative build-root or install-root on a build element, or a relative install root on a script element, fails the same way in mark_directory().

These directories are now checked when the element is configured: BuildElement in configure(), and ScriptElement in set_work_dir() and set_install_root(), which element plugins call from their configure(). A relative path raises an ElementError, so bst show and bst build report the element and the path before any job starts. The sandbox assertions stay as they are.

I added tests in tests/format/variables.py and ran the test suite, plus black, pylint and mypy, locally.

Fixes #2077

@abderrahim

Copy link
Copy Markdown
Contributor

I feel that conceptually, preflight() isn't the right place for this. I feel this would be better in configure().

Otherwise LGTM.

The sandbox only accepts absolute paths for the working directory and
for the directories it marks, and checks this with an assertion. So an
element with a relative directory, for example a script element with
`cwd: elements`, loads fine and then fails in the build job with a BUG
message and a traceback.

Check these directories when the element is configured and raise an
ElementError, so that the element is reported with a normal error
message when it is loaded, before any job starts.

  o scriptelement.py: Check the working directory in set_work_dir() and
    the install root in set_install_root(), which element plugins call
    from their configure() implementation.

  o buildelement.py: Check the build-root and install-root variables in
    configure(). The working directory is the build root, which
    command-subdir is joined onto when it is set.

Fixes apache#2077
Check that `bst show` reports a relative working directory or install
root on a script element, and a relative build-root or install-root on
a manual element, as an element error, and that a working directory
given by a variable which resolves to an absolute path is accepted.

This is a part of apache#2077
@Thanatos9404
Thanatos9404 force-pushed the thanatos/relative-work-directory branch from 37e74f3 to 9e44bb1 Compare November 3, 2026 14:35
@Thanatos9404

Copy link
Copy Markdown
Contributor Author

Makes sense, moved it. BuildElement now checks in configure(), and ScriptElement in set_work_dir() and set_install_root(), which plugins call from their configure(). The error message and reason are the same.

@juergbi
juergbi merged commit a68cc6e into apache:master Nov 6, 2026
17 checks passed
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.

An unhandled exception occured, when passing bogus input to bst

3 participants