Skip to content

Commit e93430f

Browse files
committed
Add support for Class-Path entries in Manifest
1 parent 78b3f4a commit e93430f

File tree

7 files changed

+33
-8
lines changed

7 files changed

+33
-8
lines changed

compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala

+19-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import dotty.tools.io.{AbstractFile, VirtualDirectory}
77
import FileUtils.*
88
import dotty.tools.io.ClassPath
99
import dotty.tools.dotc.core.Contexts.*
10+
import java.nio.file.Files
1011

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

5354
// Internal
5455
protected def classesInPathImpl(path: String, expand: Boolean)(using Context): List[ClassPath] =
55-
for {
56+
val files = for {
5657
file <- expandPath(path, expand)
5758
dir <- {
5859
def asImage = if (file.endsWith(".jimage")) Some(AbstractFile.getFile(file)) else None
5960
Option(AbstractFile.getDirectory(file)).orElse(asImage)
6061
}
6162
}
62-
yield newClassPath(dir)
63+
yield dir
64+
65+
val expanded =
66+
if scala.util.Properties.propOrFalse("scala.expandjavacp") then
67+
for
68+
file <- files
69+
a <- ClassPath.expandManifestPath(file.absolutePath)
70+
path = java.nio.file.Paths.get(a.toURI()).nn
71+
if Files.exists(path)
72+
yield
73+
newClassPath(AbstractFile.getFile(path))
74+
else
75+
Seq.empty
76+
77+
files.map(newClassPath) ++ expanded
78+
79+
end classesInPathImpl
6380

6481
private def createSourcePath(file: AbstractFile)(using Context): ClassPath =
6582
if (file.isJarOrZip)

compiler/src/dotty/tools/io/ClassPath.scala

+9-4
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,18 @@ object ClassPath {
152152

153153
val baseDir = file.parent
154154
new Jar(file).classPathElements map (elem =>
155-
specToURL(elem) getOrElse (baseDir / elem).toURL
155+
specToURL(elem, baseDir) getOrElse (baseDir / elem).toURL
156156
)
157157
}
158158

159-
def specToURL(spec: String): Option[URL] =
160-
try Some(new URI(spec).toURL)
161-
catch case _: MalformedURLException | _: URISyntaxException => None
159+
def specToURL(spec: String, basedir: Directory): Option[URL] =
160+
try
161+
val uri = new URI(spec)
162+
if uri.isAbsolute() then Some(uri.toURL())
163+
else
164+
Some(basedir.resolve(Path(spec)).toURL)
165+
catch
166+
case _: MalformedURLException | _: URISyntaxException => None
162167

163168
def manifests: List[java.net.URL] = {
164169
import scala.jdk.CollectionConverters.EnumerationHasAsScala

dist/bin/scalac

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ eval "\"$JAVACMD\"" \
8686
${JAVA_OPTS:-$default_java_opts} \
8787
"${java_args[@]}" \
8888
"-classpath \"$jvm_cp_args\"" \
89+
"-Dscala.expandjavacp=true" \
8990
"-Dscala.usejavacp=true" \
9091
"-Dscala.home=\"$PROG_HOME\"" \
9192
"dotty.tools.MainGenericCompiler" \

dist/bin/scalac.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ call :compilerJavaClasspathArgs
2424
@rem we need to escape % in the java command path, for some reason this doesnt work in common.bat
2525
set "_JAVACMD=!_JAVACMD:%%=%%%%!"
2626

27-
call "%_JAVACMD%" %_JAVA_ARGS% -classpath "%_JVM_CP_ARGS%" "-Dscala.usejavacp=true" "-Dscala.home=%_PROG_HOME%" dotty.tools.MainGenericCompiler %_SCALA_ARGS%
27+
call "%_JAVACMD%" %_JAVA_ARGS% -classpath "%_JVM_CP_ARGS%" "-Dscala.usejavacp=true" "-Dscala.expandjavacp=true" "-Dscala.home=%_PROG_HOME%" dotty.tools.MainGenericCompiler %_SCALA_ARGS%
2828
if not %ERRORLEVEL%==0 (
2929
set _EXITCODE=1
3030
goto end

dist/bin/scaladoc

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ eval "\"$JAVACMD\"" \
7878
${JAVA_OPTS:-$default_java_opts} \
7979
"${java_args[@]}" \
8080
-classpath "${JVM_CP_ARGS}" \
81+
-Dscala.expandjavacp=true \
8182
-Dscala.usejavacp=true \
8283
"dotty.tools.scaladoc.Main" \
8384
"${scala_args[@]}" \

dist/bin/scaladoc.bat

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ set "_JAVACMD=!_JAVACMD:%%=%%%%!"
3030

3131
call "%_JAVACMD%" %_JAVA_OPTS% %_JAVA_DEBUG% %_JAVA_ARGS% ^
3232
-classpath "%_LIB_DIR%\scaladoc.jar" ^
33+
-Dscala.expandjavacp=true ^
3334
-Dscala.usejavacp=true ^
3435
dotty.tools.scaladoc.Main %_SCALA_ARGS% %_RESIDUAL_ARGS%
3536
if not %ERRORLEVEL%==0 (

project/RepublishPlugin.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ object RepublishPlugin extends AutoPlugin {
220220

221221
def compose(libs: List[String]): List[String] =
222222
libs.map(fuzzyFind(classpaths, _)).reduceOption(_ ++ _).map(_.distinct).getOrElse(Nil)
223-
223+
224224
// Compute the classpath entries
225225
val entries = compose(actual).diff(compose(subtractions))
226226
// Generate the MANIFEST for the pathing jar

0 commit comments

Comments
 (0)