Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dapp: Ignore non-directories in dapp-remappings #778

Merged
merged 9 commits into from
Sep 12, 2021
3 changes: 2 additions & 1 deletion src/dapp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Dapp debug respects DAPP_LINK_TEST_LIBRARIES
- Dapp debug respects `DAPP_LINK_TEST_LIBRARIES`
- Dapp remappings ignores non-directories in `DAPP_LIB`
transmissions11 marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

Expand Down
24 changes: 19 additions & 5 deletions src/dapp/libexec/dapp/dapp-remappings
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ Object.keys(pkg_src).sort((a, b) => a.length - b.length).sort(
function findRemappings(prefix) {
ls(`${prefix}/${process.env.DAPP_LIB}`).forEach(name => {
var lib = `${prefix}/${process.env.DAPP_LIB}`
var src = `${lib}/${name}/${process.env.DAPP_SRC}`.replace(/^.\//, "")
var path = `${lib}/${name}`
var src = `${path}/${process.env.DAPP_SRC}`.replace(/^.\//, "")

// If the path is a not a directory, return early.
if (!isDir(path)) {
return
}

// Shortcut when we're ignoring all the Git hash stuff.
if (process.env.DAPP_IGNORE_HASHES) {
pkg_src[name] = src
findRemappings(`${lib}/${name}`)
findRemappings(path)
return
}

if (ls(`${lib}/${name}`).includes(".git") != true) {
console.error(`${PROGRAM_NAME}: error: ${lib}/${name} is not a Git repository`)
if (ls(path).includes(".git") != true) {
console.error(`${PROGRAM_NAME}: error: ${path} is not a Git repository`)
console.error(`${PROGRAM_NAME}: error: try "dapp update" to initialize submodules`)
process.exit(1)
}
Expand All @@ -47,7 +53,7 @@ function findRemappings(prefix) {
pkg_hash[name] = hash
}

findRemappings(`${lib}/${name}`)
findRemappings(path)
})
}

Expand All @@ -59,6 +65,14 @@ function ls(dir) {
}
}

function isDir(path) {
try {
return require("fs").lstatSync(path).isDirectory()
} catch (error) {
return false;
}
}

function run(cmd, args) {
return require("child_process").execFileSync(cmd, args, {
encoding: "utf-8"
Expand Down