Fix import resolution on Windows: normalise path separators#493
Open
sgraphics wants to merge 1 commit into
Open
Fix import resolution on Windows: normalise path separators#493sgraphics wants to merge 1 commit into
sgraphics wants to merge 1 commit into
Conversation
solc's findImports callback always receives '/'-separated import paths, but buildSources keyed the sources map with path.relative()'s output, which uses '\' on Windows. The mismatch made every contract with a relative import fail on Windows with "We couldn't find the import ..." (e.g. CharityPot, Escrow, Swap, Assign-constructor2). Extract the key-building into an injectable toImportKey() helper that normalises separators to '/', and add cross-platform unit tests in test/solc-import-path.test.js covering both path.posix and path.win32. The Windows case is driven with path.win32 explicitly, so it fails without the fix even on a Linux CI runner. No-op on POSIX (path.sep is '/'); takes `npm test` from 0 -> 9 passing on Windows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows, every contract with a relative import fails to compile with
We couldn't find the import ...— for exampleCharityPot,Escrow,Swap, andAssign-constructor2. Import-free contracts are unaffected, which is why CI (Ubuntu) stays green.Cause
buildSourcesinsrc/solc.tskeys the sources map with the output ofpath.relative(). solc'sfindImportscallback always looks those keys up with forward slashes, but on Windowspath.relativereturns the OS-native separator (a backslash), so the lookup never matches and compilation aborts.Fix
Extract the key-building into a small
toImportKey()helper that normalises the separators to forward slashes. This is a no-op on POSIX (path.sepis already/) and only changes behaviour on Windows.Tests
Adds
test/solc-import-path.test.jswith cross-platform cases driven bypath.posixandpath.win32explicitly, so the Windows case fails without the fix even when run on a Linux CI runner. With the fix,npm testgoes from 0 to 9 passing on Windows and is unchanged on Linux/Mac.