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

GenIdea: more Win-compatible fixes to test suite #1467

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main/core/src/define/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object Module {
outer
.getClass
.getClasses
.filter(implicitly[ClassTag[T]].runtimeClass isAssignableFrom _)
.filter(implicitly[ClassTag[T]].runtimeClass.isAssignableFrom(_))
.flatMap(c =>
c.getFields.find(_.getName == "MODULE$").map(_.get(c).asInstanceOf[T])
)).distinct
Expand Down
14 changes: 9 additions & 5 deletions scalalib/src/GenIdeaImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -691,19 +691,23 @@ case class GenIdeaImpl(
}

/** Try to make the file path a relative JAR URL (to PROJECT_DIR). */
def relativeJarUrl(path: os.Path) = {
def relativeJarUrl(path: os.Path): String = {
// When coursier cache dir is on different logical drive than project dir
// we can not use a relative path. See issue: https://github.com/lihaoyi/mill/issues/905
val relPath =
Try("$PROJECT_DIR$/" + path.relativeTo(workDir)).getOrElse(path)
val relPath = relForwardPath(path, "$PROJECT_DIR$/")
if (path.ext == "jar") "jar://" + relPath + "!/" else "file://" + relPath
}

/** Try to make the file path a relative URL (to PROJECT_DIR). */
def relativeFileUrl(path: Path): String = {
// When coursier cache dir is on different logical drive than project dir
// we can not use a relative path. See issue: https://github.com/lihaoyi/mill/issues/905
"file://" + Try("$PROJECT_DIR$/" + path.relativeTo(workDir)).getOrElse(path)
"file://" + relForwardPath(path, "$PROJECT_DIR$/")
}

private def relForwardPath(path: os.Path, prefix: String): String = {
def forward(p: os.FilePath): String = p.toString().replace("""\""", "/")
Try(prefix + forward(path.relativeTo(workDir))).getOrElse(forward(path))
}

def libraryXmlTemplate(
Expand All @@ -712,7 +716,7 @@ case class GenIdeaImpl(
sources: Option[os.Path],
scalaCompilerClassPath: Loose.Agg[Path]
): Elem = {
val isScalaLibrary = scalaCompilerClassPath.nonEmpty
val isScalaLibrary = scalaCompilerClassPath.iterator.nonEmpty
<component name="libraryTable">
<library name={name} type={if (isScalaLibrary) "Scala" else null}>
{
Expand Down
13 changes: 8 additions & 5 deletions scalalib/test/src/GenIdeaTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ object GenIdeaTests extends ScriptTestSuite(false) {

private def normaliseLibraryPaths(in: String, workspacePath: os.Path): String = {
val coursierPath = os.Path(coursier.paths.CoursierPaths.cacheDirectory())
val path = Try(coursierPath.relativeTo(workspacePath)).getOrElse(coursierPath)
in.replace(
"$PROJECT_DIR$/" + path,
"COURSIER_HOME"
)
val path =
Try("$PROJECT_DIR$/" + coursierPath.relativeTo(workspacePath)).getOrElse(
coursierPath
).toString().replace(
"""\""",
"/"
)
in.replace(path, "COURSIER_HOME")
}

override def workspaceSlug: String = "gen-idea-hello-world"
Expand Down