Open eyooooo opened 3 years ago
the issue is in /usr/local/lib/python3.6/dist-packages/brownie/project/compiler/__init__.py
in func _get_solc_remappings
. im seeing if i can patch it.
This is a hacky workaround
def _get_solc_remappings(remappings: Optional[list]) -> list:
if remappings is None:
remap_dict: Dict = {}
elif isinstance(remappings, str):
remap_dict = dict([remappings.split("=")])
else:
remap_dict = dict(i.split("=") for i in remappings)
#hacky crap here
for path in _get_data_folder().joinpath("packages").iterdir():
for k,v in remap_dict.items():
remap_dict[k] = path.parent.joinpath(v).as_posix()
#print([f"{k}={v}" for k, v in remap_dict.items()])
for path in _get_data_folder().joinpath("packages").iterdir():
key = next((k for k, v in remap_dict.items() if v.startswith(path.name)), None)
if key:
remap_dict[key] = path.parent.joinpath(remap_dict[key]).as_posix()
else:
remap_dict[path.name] = path.as_posix()
return [f"{k}={v}" for k, v in remap_dict.items()]
Thanks for the workaround, I'll have a look here shortly.
For reference: https://docs.soliditylang.org/en/latest/using-the-compiler.html#path-remapping
I have reproduced the same bug. I think can formalize it in the next way:
dependecies
and/or remappings
. Also at least one contract should use items from the first repository and at least one more contract should use items from the second repository. After the compilation, items from all repositories except the first will not be found and will fail the compilation.For example I have:
remappings:
- "@openzeppelinV3=OpenZeppelin/openzeppelin-contracts@3.1.0"
- "@ozUpgradesV3=OpenZeppelin/openzeppelin-contracts-upgradeable@3.3.0"
So both packages has the same OpenZeppelin/
root.
One contract of mine imports Ownable
from the regular package, and another contract imports OwnableUpgradeable
from the upgradable package. After the compilation I get an error:
ParserError: Source "OpenZeppelin/openzeppelin-contracts-upgradeable@3.3.0/contracts/access/OwnableUpgradeable.sol" not found: File not found.
import "@ozUpgradesV3/contracts/access/OwnableUpgradeable.sol";
^-------------------------------------------------------------^
Issue reproduces with different order of packages, different imports, different truffle or solc versions. Brownie version 1.12.2
Though, issue does not reproduce, when I manually clone all the packages except the first (brownie pm clone "OpenZeppelin/openzeppelin-contracts-upgradeable@3.3.0"
).
Totally reproducing:
compiler:
solc:
version: 0.8.3
remappings:
- "@openzeppelin-upgradeable=/home/username/.brownie/packages/OpenZeppelin/openzeppelin-contracts-upgradeable@4.1.0"
- "@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.1.0"
the above works, but if you remap as just
compiler:
solc:
version: 0.8.3
remappings:
- "@openzeppelin-upgradeable=OpenZeppelin/openzeppelin-contracts-upgradeable@4.1.0"
- "@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.1.0"
i.e. if 2 remappings have the same path prefix, it's compiler errors "File not found" all over the place, like
ParserError: Source "OpenZeppelin/openzeppelin-contracts@4.1.0/contracts/access/Ownable.sol" not found: File not found.
This worked for me:
- "@openzeppelin/contracts=OpenZeppelin/openzeppelin-contracts@3.4.2/contracts"
- "@openzeppelin/contracts-upgradeable=OpenZeppelin/openzeppelin-contracts-upgradeable@3.4.2/contracts"
Environment information
brownie
Version: 1.12.1ganache-cli
Version: x.x.xsolc
Version: x.x.xWhat was wrong?
brownie pm install OpenZeppelin/openzeppelin-contracts@2.5.1
brownie pm install uniswap/uniswap-v2-core@1.0.1
brownie pm install uniswap/uniswap-lib@2.1.0
If I flip the two uniswap remappings, the 2nd one always fails. eg)
will produce errors
How can it be fixed?
regex? it appears the remapping ignores the info after the
/
souniswap/lib
anduniswap/v2-core
are just treated identically. the 2nd entry will always fail.