-
Notifications
You must be signed in to change notification settings - Fork 2.3k
truffle compile
becomes quite unpredictable if you move your artifacts from another location on disk
#2114
Comments
Thanks for reporting this @wbt, we'll check it out. Very strange. |
Huh, I'd noticed this problem as well. I hadn't thought of it as a real problem, but I guess maybe it should be considered one. |
This might be related to #2599 ("Resolver.resolve doesn't make any sense") |
truffle compile
becomes quite unpredictable if you move your artifacts from another location on disk
This will be a challenging one to sort out. We've discussed possibly modifying the Might be worth noting @eggplantzzz raises the point that if you specify @haltman-at confirms that this problem still exists (but with slightly different symptoms today). Unclear how to proceed in short-term vs. long-term. @cds-amal suggests maybe we can start addressing this with an "error better" style fix. |
Why is Truffle using absolute paths at all, and where is it getting those paths from?
Until this post, I did not know the build/contracts directory (artifacts) even had any absolute paths in them. In our workflow, we are regularly moving those files around even between computers with very different file systems (and even different operating systems) for their ABI + deployed address information; some are even publicly served for in-browser use and the folder structure information revealed by absolute file paths unnecessarily reduces security. From a user perspective, there's no communication or understanding of the reason for including that, and its inclusion is quite unexpected behavior in itself (plus it leads to even stranger behavior like what's documented at the start of this thread above). Perhaps using an IPFS CID (even if the file is not stored in IPFS) or other content-based file identification system would be better? |
Currently Truffle uses that path to optimize compilation. It checks when the artifacts' were last updated and compares that to when the source files were updated to see which files require compilation and which ones don't. So it uses it to find source material for a given compiled artifact. Maybe there is a different way to do this without requiring the use of absolute paths? |
A couple strategies come to mind:
In our workflow, smart contracts are actually written by scripts as part of the build process, so their last modified dates will always be extremely recent and the |
@gnidan thoughts? |
I concur that we should get rid of absolute paths inside the artifacts. Now that we use that Note that this would require @truffle/resolver to be updated so that |
Summary
Truffle is compiling contracts from a directory way outside the project where the command is entered, to include the
\contracts\
directory of a different copy of the project elsewhere on the computer.Issue
I have a Truffle project on a Windows 10 machine, stored in a path like
Documents/repositories/myprojectname
. In an update some months back, OneDrive decided to move the Documents folder and all subfolders under OneDrive, for automatic backup of files even when not committed to a version control system.When having some difficulties with OneDrive, I unlinked the computer and made a complete copy of the directory to a location outside of OneDrive syncing, prior to a re-initialization. On the command line, I navigated to that copy and ran
truffle migrate --reset
which first runstruffle compile
. This output a list of files it was compiling, which included all the .sol files in the.\contracts\
directory (as I expected), as well as all the files in the OneDrive folder's\contracts\
directory, showing a file path going a few levels up.\..\..\
... and back down into that folder.This was highly unexpected. Why is that?
My Truffle config file only specifies a compiler version and a couple networks, with no directories mentioned.
Steps to Reproduce
Unfortunately, I don't have a set of steps to reliably reproduce this issue handy at the moment. The migration failed, on the grounds that a called function had the wrong number of parameters ("Got 1 expected 2!") which appears to be a separate issue I observe on occasion, that also appears to be a serious but intermittent compiler bug.
Usually the fix is to just run
truffle compile
again (sometimes first deleting the\build\
directory manually), so I tried that. This time, it reported compiling only the contract files I expected. In both cases, the "Artifacts written to" directory was the\build\contracts
directory of the project I was currently in, as expected.However, the first run remains concerning, because Truffle should not be compiling files outside the current project.
Expected Behavior
Only the contracts under the current folder/project's
.\contracts\
directory get compiled.Actual Results
The contracts in the current folder/project were compiled, as well as contents of the
\contracts\
directory of another (much older) copy of the project elsewhere on the same hard drive. Other solidity files within the project (either version) but not in itsprojectName\contracts\
directory were not compiled, nor were contracts from other projects under\repositories\
or anywhere else on the machine. Per expectation, copies of contracts in an unusually named directory's\contracts\
subfolder (within the same project) were also not compiled.Environment
truffle version
): v5.0.14node --version
): v9.3.0npm --version
): 6.9.0I am not aware of any shortcuts, junctions, hard links, mappings, etc. between the directory structure where I was editing and the other one where things were compiled from.
The text was updated successfully, but these errors were encountered: