Skip to content

Commit

Permalink
Add support for Class-Path entries in Manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal authored and WojciechMazur committed Jul 10, 2024
1 parent 22d9df0 commit 1910ea9
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
21 changes: 19 additions & 2 deletions compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dotty.tools.io.{AbstractFile, VirtualDirectory}
import FileUtils.*
import dotty.tools.io.ClassPath
import dotty.tools.dotc.core.Contexts.*
import java.nio.file.Files

/**
* Provides factory methods for classpath. When creating classpath instances for a given path,
Expand Down Expand Up @@ -52,14 +53,30 @@ class ClassPathFactory {

// Internal
protected def classesInPathImpl(path: String, expand: Boolean)(using Context): List[ClassPath] =
for {
val files = for {
file <- expandPath(path, expand)
dir <- {
def asImage = if (file.endsWith(".jimage")) Some(AbstractFile.getFile(file)) else None
Option(AbstractFile.getDirectory(file)).orElse(asImage)
}
}
yield newClassPath(dir)
yield dir

val expanded =
if scala.util.Properties.propOrFalse("scala.expandjavacp") then
for
file <- files
a <- ClassPath.expandManifestPath(file.absolutePath)
path = java.nio.file.Paths.get(a.toURI()).nn
if Files.exists(path)
yield
newClassPath(AbstractFile.getFile(path))
else
Seq.empty

files.map(newClassPath) ++ expanded

end classesInPathImpl

private def createSourcePath(file: AbstractFile)(using Context): ClassPath =
if (file.isJarOrZip)
Expand Down
13 changes: 9 additions & 4 deletions compiler/src/dotty/tools/io/ClassPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,18 @@ object ClassPath {

val baseDir = file.parent
new Jar(file).classPathElements map (elem =>
specToURL(elem) getOrElse (baseDir / elem).toURL
specToURL(elem, baseDir) getOrElse (baseDir / elem).toURL
)
}

def specToURL(spec: String): Option[URL] =
try Some(new URI(spec).toURL)
catch case _: MalformedURLException | _: URISyntaxException => None
def specToURL(spec: String, basedir: Directory): Option[URL] =
try
val uri = new URI(spec)
if uri.isAbsolute() then Some(uri.toURL())
else
Some(basedir.resolve(Path(spec)).toURL)
catch
case _: MalformedURLException | _: URISyntaxException => None

def manifests: List[java.net.URL] = {
import scala.jdk.CollectionConverters.EnumerationHasAsScala
Expand Down
1 change: 1 addition & 0 deletions dist/bin/scalac
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ eval "\"$JAVACMD\"" \
${JAVA_OPTS:-$default_java_opts} \
"${java_args[@]}" \
"-classpath \"$jvm_cp_args\"" \
"-Dscala.expandjavacp=true" \
"-Dscala.usejavacp=true" \
"-Dscala.home=\"$PROG_HOME\"" \
"dotty.tools.MainGenericCompiler" \
Expand Down
2 changes: 1 addition & 1 deletion dist/bin/scalac.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ call :compilerJavaClasspathArgs
@rem we need to escape % in the java command path, for some reason this doesnt work in common.bat
set "_JAVACMD=!_JAVACMD:%%=%%%%!"

call "%_JAVACMD%" %_JAVA_ARGS% -classpath "%_JVM_CP_ARGS%" "-Dscala.usejavacp=true" "-Dscala.home=%_PROG_HOME%" dotty.tools.MainGenericCompiler %_SCALA_ARGS%
call "%_JAVACMD%" %_JAVA_ARGS% -classpath "%_JVM_CP_ARGS%" "-Dscala.usejavacp=true" "-Dscala.expandjavacp=true" "-Dscala.home=%_PROG_HOME%" dotty.tools.MainGenericCompiler %_SCALA_ARGS%
if not %ERRORLEVEL%==0 (
set _EXITCODE=1
goto end
Expand Down
1 change: 1 addition & 0 deletions dist/bin/scaladoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ eval "\"$JAVACMD\"" \
${JAVA_OPTS:-$default_java_opts} \
"${java_args[@]}" \
-classpath "${JVM_CP_ARGS}" \
-Dscala.expandjavacp=true \
-Dscala.usejavacp=true \
"dotty.tools.scaladoc.Main" \
"${scala_args[@]}" \
Expand Down
1 change: 1 addition & 0 deletions dist/bin/scaladoc.bat
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ set "_JAVACMD=!_JAVACMD:%%=%%%%!"

call "%_JAVACMD%" %_JAVA_OPTS% %_JAVA_DEBUG% %_JAVA_ARGS% ^
-classpath "%_LIB_DIR%\scaladoc.jar" ^
-Dscala.expandjavacp=true ^
-Dscala.usejavacp=true ^
dotty.tools.scaladoc.Main %_SCALA_ARGS% %_RESIDUAL_ARGS%
if not %ERRORLEVEL%==0 (
Expand Down
2 changes: 1 addition & 1 deletion project/RepublishPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ object RepublishPlugin extends AutoPlugin {

def compose(libs: List[String]): List[String] =
libs.map(fuzzyFind(classpaths, _)).reduceOption(_ ++ _).map(_.distinct).getOrElse(Nil)

// Compute the classpath entries
val entries = compose(actual).diff(compose(subtractions))
// Generate the MANIFEST for the pathing jar
Expand Down

0 comments on commit 1910ea9

Please sign in to comment.