Skip to content

Commit 85dbdbd

Browse files
committed
add some more comments and clean up a bit of code
1 parent dfa4ebb commit 85dbdbd

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/main/scala/io/viash/config/dependencies/Dependency.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,24 +162,28 @@ object Dependency extends Logging {
162162
// If the dependencyPath is a valid path, use it as source
163163
defaultSourcePath
164164
} else if (remoteLocalDependencyResolver.isDefined) {
165+
// This is empty if we're resolving the first level of dependencies.
166+
// For the most part we should not end up here, but there is an edge case where we have to resolve a local dependency for a dependency of a dependency.
167+
// In this case, we don't have the context of the location where the dependency is stored under the dependency folder, however we know where the dependant is stored,
168+
// so we can use the remote local dependency resolver to find the source path.
165169
logger.debug(s"Couldn't find sourcePath, using remote local dependency resolver for $dependencyPath")
166170
logger.debug(s"Remote local dependency resolver: $remoteLocalDependencyResolver")
167-
val alternativeSourcePath = remoteLocalDependencyResolver.get._1
168-
val alternativeTargetPath = remoteLocalDependencyResolver.get._2
171+
val alternativeSourcePath = remoteLocalDependencyResolver.get._1 // This is the path where the dependant is located
172+
val alternativeTargetPath = remoteLocalDependencyResolver.get._2 // This is the relative path of the dependant in the target folder
169173

170174
// strips alternativeTargetPath from dependencyPath
171175
val targetIter = alternativeTargetPath.iterator().asScala.toList.map(p => Some(p))
172176
val depIter = Paths.get(dependencyPath).iterator().asScala.toList.map(p => Some(p))
173177
val zipped = depIter.zipAll(targetIter, None, None).dropWhile {
174178
case (depPart, targetPart) => depPart == targetPart
175179
}
176-
val relativePath = Paths.get(zipped.flatMap(_._1).mkString("/"))
180+
val relativePath = zipped.flatMap(_._1).reduce((p1, p2) => p1.resolve(p2))
177181
logger.debug(s"relativePath: $relativePath")
178182
val res = alternativeSourcePath.resolve(relativePath)
179183
logger.debug(s"Using alternative source path: $res")
180184
res
181185
} else {
182-
// Otherwise, throw an error
186+
// Otherwise, throw an error. We shouldn't end up here.
183187
throw new MissingBuildYamlException(defaultSourcePath, mainDependency)
184188
}
185189
// Split the path into chunks so we can manipulate them more easily

src/main/scala/io/viash/helpers/DependencyResolver.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,13 @@ object DependencyResolver extends Logging {
311311
logger.debug(s"Paths to relativize: dependencySourcePath: $dependencySourcePath, relativeOutput: $relativeOutput")
312312

313313
// remove the trailing path parts as far as relativeOutputPath matches the dependencySourcePath
314-
// baseDependencySourcePath: a/b/c/d/e
314+
// dependencySourcePath: a/b/c/d/e
315315
// relativeOutputPath: c'/d/e
316316
// output: a/b/c & c'
317+
// dependencySourcePath contains a tuple of:
318+
// - left: the the path where the dependency is stored down to common root, matching to 'target'
319+
// - right: the original 'target' folder name
320+
// this is needed to relativize paths correctly when resolving a local dependency of this dependency
317321
val dependencySourceParts = dependencySourcePath.map { dsp =>
318322
val dspParts = dsp.iterator().asScala.toList.map(p => Some(p)).reverse
319323
val relativeOutputPath = Paths.get(relativeOutput).iterator().asScala.toList.map(p => Some(p)).reverse

0 commit comments

Comments
 (0)