-
Notifications
You must be signed in to change notification settings - Fork 888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add opt-in support for resolving relative paths in Yosys scripts based on script location #4571
base: main
Are you sure you want to change the base?
Conversation
I think it would be best to make this opt in, otherwise some tests fail such as Also looking into how to fix the WASI build:
|
I am worried this will break existing users, we could make the lookup relative to the script directory be conditioned on some prefix, e.g. |
I suspect what the prefix should be will be very bikesheddable, but a prefix sounds like a good idea. |
Alternatively, and this is probably also bikesheddable, some sort of command or scratchpad variable or such which asks the Yosys command parser to interpret paths relative to some specified path. That would mean third party scripts could have some equivalent functionality to |
At the time there is no std::filesystem on WASI because of thread related issues and most likely there won't be such support for quite a while. |
What do you think about adding a On the other hand, Thoughts? @povik @Ravenslofty |
Speaking from personal experience, when I want to run a script I use |
An alternative is a command like |
Ah that's what @Ravenslofty suggested. I think we can all agree we want the opt-in controlled from within the script |
df1adf7
to
b7af214
Compare
In Dev JF we came to the conclusion that we want to support scripts calling other scripts. |
What are the reasons/motivation for this change?
This PR addresses the feature described in #4556 by introducing an opt-in mechanism to handle relative file paths in Yosys scripts that are not executed from the current directory.
The opt-in can be controlled from both within and outside the script with a scratchpad variable.
Explain how this is achieved.
When a Yosys script (
.ys
) located outside the current directory is executed, its directory path is stored in the scratchpad under the keyscript.dir
. This is done unconditionally.If the scratchpad variable
script.relative_path_resolution_enabled
is set to true, and the filename to be read/write is relative, the path stored in script.dir is prepended (in a portable manner) to the filename to resolve it correctly.If you want to disable this behavior and revert to the default handling of relative paths, set the scratchpad variable to 0:
scratchpad -set script.relative_path_resolution_enabled 0
This feature is not available in the WASI build since it lacks support for
std::filesystem
.See WASI filesystem status for more details.
If applicable, please suggest to reviewers how they can test the change.
To reproduce the current behaviour, we can run (from yosys root dir)
./yosys tests/opt/opt_expr_cmp.ys
and observe the following error:We can enable the feature via command line:
./yosys -p "scratchpad -set script.relative_path_resolution_enabled 1; script tests/opt/opt_expr_cmp.ys"
Or within the script:
Both ways yosys finds the relevant files correctly.
You can find more .ys scripts to test with the following command (executed from yosys root dir):
find tests -type f -name "*.ys" -exec grep -H "read_" {} + | grep -v -e 'EOT' -e 'EOF' | cut -d':' -f1 | uniq
Note that some of those scripts will fail, for example
tests/blif/bug2729.y
, due to the limitation regarding shell commands documented below.Note 1: While mixing absolute and relative paths works correctly, I haven’t found a straightforward way to automate this test in the test suite.
Known limitations
Script calling another script
In such cases, the script.dir variable is overwritten with the directory of the most recently executed script, which can lead to incorrect path resolution. However, this is not a common use case and is unlikely to affect most users.
Shell commands inside script
The relative path resolution mechanism introduced by this feature does not apply to filenames used in shell commands within Yosys scripts. For example, commands like
! rm filename
or! cp filename
will not have their paths automatically prefixed or resolved using the script.dir variable.@Ravenslofty adding you as a reviewer since you seem to be a proponent of the scratchpad: #3880 (comment)