question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why paths specified on the CLI are not relative to `--base-path`?

See original GitHub issue

i am unclear on what ‘root of source tree’ means when using the base-path flag

$(npm bin)/solcjs --bin --output-dir build --base-path ./contracts Test.sol returns : Error reading Test.sol: Error: ENOENT: no such file or directory, open 'Test.sol'

$(npm bin)/solcjs --bin --output-dir build --base-path . contracts/Test.sol works and compiles contract

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cameelcommented, Sep 9, 2022

You can find detailed docs about how path resolution works in Import Path Resolution.

In short, the main purpose of base path is to be the location that direct imports are resolved against. I.e. if the base path is /some/path/, and you have import "a/b/c.sol" in your contract, the compiler will look for the file in /some/path/a/b/c.sol on disk.

Base path is not the same thing as your working directory even though by default they have the same value. When they’re different, on the command-line it’s the working directory that counts:

cd /some/other/path
solc --base-path /some/path/ a/b/c.sol

In the above a/b/c.sol refers to /some/other/path/a/b/c.sol because that’s how everyone expects relative paths to work on the CLI. It does not magically become /some/path/a/b/c.sol

0reactions
cameelcommented, Sep 10, 2022

Why not. Feel free to submit a PR to adjust that. We could add a sentence or two on that and maybe link to specific bits in the import path resolution docs. Like, the --base-path option could be a link to the section on base path and we could also link to https://docs.soliditylang.org/en/latest/path-resolution.html#cli-path-normalization-and-stripping.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoiding relative paths in Angular CLI - Stack Overflow
paths tsconfig option is relative to baseUrl option (so keep in mind and use relative paths for the paths keys). * - the...
Read more >
Import Path Resolution — Solidity 0.8.16 documentation
The working directory of the compiler is one of the paths allowed by default only if it happens to be the base path...
Read more >
Search path for libraries (path spec v3) · Issue #11409 - GitHub
By default base path is empty, which means that relative paths are relative to the current working directory while absolute paths remain ...
Read more >
File path formats on Windows systems | Microsoft Learn
These "drive relative" paths are a common source of program and script logic errors.
Read more >
Relative and absolute paths, in the file system and on the web ...
So it goes for the paths in the computer world: given the absolute address, you can always get to the place, no matter...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found