[CLI] --base-path unexpectedly effects both import and source URLs
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
Hello all - Thanks for all the hard work on solc and taking the time to look at this Issue!
## Description
I am trying to utilize `--base-path` to reduce a large number of import remappings in the compiler configuration required in my project. When using `--base-path` I expecteded that only contract imports would be effected but solidity source URLs are *also* prepended with base path (as far as I can tell this behavior is undocumented).
In practice this means that in order to use `--bash-path` - the entire solidity source tree *and* import remapping tree must share the same base path, which is not the case for all projects.
Since my project uses many contracts defined across multiple directories, I'd like to be able to specify solidity source URLs as absolute paths in the typical manner via compiler input configuration *and* use `--base-path` to effect import remapping as *separate* configuration values. If source URLs *must* be remapped with `--base-path` - In my opinion the ideal behavior is to prepend `--base-path` to relative source file URLs and ignore absolute paths.
## Environment
- Compiler version: v0.6.11
- Target EVM version (as per compiler settings): Berlin (although not applicable here)
- Framework/IDE (e.g. Truffle or Remix): None
- EVM execution environment / backend / blockchain client: None
- Operating system: Ubuntu 20.04
## Steps to Reproduce
##### File Hierarchy
```
- main
- contracts
- my_contract.sol
- my_lib.sol
- tests
- contracts
- test_contract.sol
```
##### JSON Compiler Input Configuration
```
{...,
sources: {
'my_contract.sol': {'urls': ['/my/absolute/path/main/contracts/my_contract.sol']},
'my_lib.sol': {'urls': ['/my/absolute/path/main/contracts/my_lib.sol']},
...,
'test_contract.sol': {'urls': ['/my/absolute/path/tests/contracts/test_contract.sol']},
}
...
}
```
##### Solidity Source
```
import "contracts/my_lib.sol";
```
##### Compiler Command
```
solc --base-path /my/absolute/path/main ...
```
#### Symptom
The `--base-path` option appears to prepend a path to the absolute source file URL unexpectedly resulting in `/my/absolute/path/main/my/absolute/path/main/contracts/my_contract.sol` leading to a file not found exception raised:
```
{"component":"general","formattedMessage":"Cannot import url(\"/my/absolute/path/main/contracts/my_contract.sol"): File not found..."
```
Contributor guide
Research direction
Start by reproducing the reported compiler-input case with solc --base-path, using the absolute source URLs and relative Solidity import shown in the issue. Trace the CLI path-resolution behavior for source URLs and imports; done means absolute source URLs are not incorrectly prefixed while the requested import resolution still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- cli, compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100