-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support -d with .jar paths #3382
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
Conversation
res | ||
} else { | ||
assert(output.hasExtension("jar")) | ||
classOutput = new PlainDirectory(Path(Path(output.file).parent + "/tmp-jar-" + System.currentTimeMillis().toHexString).createDirectory()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scalac has code to write directly to a JAR instead of using a temporary directory which should be faster, maybe we can reuse that: https://github.com/scala/scala/blob/d41c97f13ea2348ec6f59c24ae098d83a96f30dc/src/compiler/scala/tools/nsc/backend/jvm/ClassfileWriter.scala#L23 Although apparently in Java >= 7 there's already an API dedicated to this: sbt/zinc#305 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ClassfileWriter
came in the large refactoring made in scala/scala#6012. You said previously in #3113 that you would rather not port this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Java 7 API does not allow direct access to the files in the jar.
Once you have an instance of a zip file system, you can invoke the methods of the java.nio.file.FileSystem and java.nio.file.Path classes to perform operations such as copying, moving, and renaming files, as well as modifying file attributes.
quote link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you do something like:
def outputDir(implicit ctx: Context): AbstractFile = {
if (isJar) {
val jar = Paths.get(pathTojar)
val fs = FileSystems.newFileSystem(jar)
new PlainNioFile(fs.getPath("/"))
}
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It worked with the java.nio.file. FileSystem
jar.
a59020a
to
7ca29b5
Compare
Needs rebase on #3395 one merged |
dfb822a
to
9018fb5
Compare
Rebased |
9018fb5
to
7f00b9c
Compare
// changes the existing extension out for a new one, or adds it | ||
// if the current path has none. | ||
def changeExtension(ext: String): Path = | ||
if (extension == "") addExtension(ext) | ||
else Path(path.stripSuffix(extension) + ext) | ||
else new Path(jpath.resolveSibling(stripExtension + "." + extension)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new Path(jpath.resolveSibling(stripExtension + "." + ext))
Files.createDirectories(path.getParent) | ||
Files.newOutputStream(path) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
path.delete() | ||
val path = Directory(ctx.settings.outputDir.value) | ||
if (path.extension == "jar") { | ||
if (jarFS == null) | ||
jarFS = JarFS.create(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make sure that the jar is empty or all files are rewritten.
object JarFS { | ||
def create(path: Path): JarFS = { | ||
assert(path.extension == "jar") | ||
val env = Map("create" -> "true").asJava |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add these links in comments if they're useful to understand the code
7f00b9c
to
4e39251
Compare
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
|
||
import scala.collection.JavaConverters._ | ||
|
||
class JarFS private (private[this] var jarFS: FileSystem) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some documentation :).
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/3382/ to see the changes. Benchmarks is based on merging with master (7759e00) |
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
a06b041
to
35d29a1
Compare
35d29a1
to
2e79154
Compare
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/3382/ to see the changes. Benchmarks is based on merging with master (7759e00) |
We definitely got a speed up with this PR. It was not intentional though 😂 |
Where does the speed-up comes from? |
We removed implicit conversion. |
@allanrenucci parts LGTM |
No description provided.