Skip to content

Commit dc92c39

Browse files
committed
package local remappings
This modifies dapp remappings so that it now generates a unique set of remappings for each `src` folder in the dependency tree that points into the adjacent `lib` folder. This allows for multiple versions of a given package in the dependency tree, and means `ds-pain` is happily obsolete.
1 parent 579a4d4 commit dc92c39

File tree

3 files changed

+25
-52
lines changed

3 files changed

+25
-52
lines changed

src/dapp-tests/integration/tests.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ dapp_testnet() {
5050

5151
dapp_testnet
5252

53+
# tests the behaviour of the package local dapp remappings
54+
dapp_remappings() {
55+
TMPDIR=$(mktemp -d)
56+
git clone https://github.com/dapphub/remappings-test "$TMPDIR"
57+
(cd "$TMPDIR" && dapp update && dapp test)
58+
}
59+
60+
dapp_remappings
61+
5362
test_hevm_symbolic() {
5463
solc --bin-runtime -o . --overwrite factor.sol
5564
# should find counterexample

src/dapp-tests/shell.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ let
88
hypothesis
99
pytest
1010
# other python packages you want
11-
];
11+
];
1212
python-with-pkgs = python3.withPackages my-python-packages;
1313
in
1414

1515
mkShell {
1616
name = "dapp-tests";
17-
buildInputs = [ killall cacert bashInteractive curl dapp gnumake hevm procps seth solc go-ethereum python-with-pkgs ];
17+
buildInputs = [ killall cacert bashInteractive curl dapp git gnumake hevm procps seth solc go-ethereum python-with-pkgs ];
1818
}
Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,23 @@
11
#!/usr/bin/env node
2-
var PROGRAM_NAME = process.argv[1].replace(/.*\//, "")
3-
var pkg_src = {}, pkg_hash = {}
42

5-
findRemappings(".")
3+
console.log(buildRemappings(".").join("\n"))
64

7-
Object.keys(pkg_src).sort((a, b) => a.length - b.length).sort(
8-
(a, b) => {
9-
var depth = name => pkg_src[name].split("/").length
10-
return depth(a) - depth(b)
11-
}
12-
).forEach(name => {
13-
console.log(`${name}/=${pkg_src[name]}/`)
14-
})
15-
16-
function findRemappings(prefix) {
17-
ls(`${prefix}/${process.env.DAPP_LIB}`).forEach(name => {
18-
var lib = `${prefix}/${process.env.DAPP_LIB}`
19-
var src = `${lib}/${name}/${process.env.DAPP_SRC}`.replace(/^.\//, "")
20-
21-
// Shortcut when we're ignoring all the Git hash stuff.
22-
if (process.env.DAPP_IGNORE_HASHES) {
23-
pkg_src[name] = src
24-
findRemappings(`${lib}/${name}`)
25-
return
26-
}
5+
function buildRemappings(prefix) {
6+
const lib = `${prefix}/${process.env.DAPP_LIB}`
7+
const ctx = `${prefix}/${process.env.DAPP_SRC}`
278

28-
if (ls(`${lib}/${name}`).includes(".git") != true) {
29-
console.error(`${PROGRAM_NAME}: error: ${lib}/${name} is not a Git repository`)
30-
console.error(`${PROGRAM_NAME}: error: try "dapp update" to initialize submodules`)
31-
process.exit(1)
32-
}
33-
34-
var hash = run("git", ["-C", src, "rev-parse", "HEAD"])
9+
const remappings = ls(lib).map(name => {
10+
return `${normalize(ctx)}:${name}/=${normalize(lib)}/${name}/${process.env.DAPP_SRC}/`
11+
})
3512

36-
if (pkg_src[name]) {
37-
if (hash != pkg_hash[name]) {
38-
console.error(`${PROGRAM_NAME}: warning: mismatching packages:`)
39-
console.error(`${PROGRAM_NAME}: warning: (1) ${pkg_src[name]}`)
40-
console.error(`${PROGRAM_NAME}: warning: (2) ${src}`)
41-
console.error(`${PROGRAM_NAME}: warning: using ${pkg_src[name]}. You can override this using \`DAPP_REMAPPINGS\``)
42-
} else if (src.length < pkg_src[name].length) {
43-
pkg_src[name] = src
44-
}
45-
} else {
46-
pkg_src[name] = src
47-
pkg_hash[name] = hash
48-
}
13+
return ls(lib).map(name => {
14+
return buildRemappings(`${lib}/${name}`)
15+
}).concat(remappings).flat()
16+
}
4917

50-
findRemappings(`${lib}/${name}`)
51-
})
18+
// strip the leading `.` or `./` from a path
19+
function normalize(path) {
20+
return path.replace(/^\.\//, "").replace(/^\//, "")
5221
}
5322

5423
function ls(dir) {
@@ -59,8 +28,3 @@ function ls(dir) {
5928
}
6029
}
6130

62-
function run(cmd, args) {
63-
return require("child_process").execFileSync(cmd, args, {
64-
encoding: "utf-8"
65-
})
66-
}

0 commit comments

Comments
 (0)