NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.33k stars 1.42k forks source link

Vyper plugin compilation not caching files #1107

Open outdoteth opened 3 years ago

outdoteth commented 3 years ago

https://github.com/nomiclabs/hardhat/blob/master/packages/hardhat-vyper/src/compilation.ts#L104

In fsExtra.pathExists the file lookup is not correct. It searches for <working dir>/artifacts/SomeContract.json.

If SomeContract.vy is in this folder: <working dir>/contracts/SomeFolder/SomeContract.vy

Then fsExtra.pathExists should search for: <working dir>/artifacts/contracts/SomeFolder/SomeContract.vy/SomeContract.json

Because the lookup is incorrect, compilations are not cached.

By changing the path lookup to the below it works:

    const contractName = pathToContractName(sourceFile);
    const contractPath = sourceFile.split("/contracts")[1];
    const artifactPath = path_1.default.join(paths.artifacts, `contracts/${contractPath}/${contractName}.json`);

    if (!(await fs_extra_1.default.pathExists(artifactPath))) {
        return false;
    }

However there seems to be a secondary issue with the cTime comparison. Whenever one file changes, all of the files then seem to acquire a cTime that warrants a recompilation; So each time one file changes, all files are then compiled again.

https://github.com/nomiclabs/hardhat/blob/master/packages/hardhat-vyper/src/compilation.ts#L114

alcuadrado commented 3 years ago

Thanks for reporting this @Dylan-Kerler,

Both of the things you mentioned seem correct.

Unfortunately, we don't have much time at the moment, so we can't fix them just yet. Would you consider sending a PR? We can help you thinking through it and reviewing it.

outdoteth commented 3 years ago

Ok, I'll open a PR later today.