Skip to content

Commit 2db6dd7

Browse files
Merge pull request #50 from alexarchambault/master
Merge upstream changes
2 parents f4f187c + c125136 commit 2db6dd7

File tree

137 files changed

+1683
-2313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+1683
-2313
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
- v1.*
66
- v2.*
77
branches:
8-
- master
8+
- main
99
pull_request:
1010

1111
jobs:
@@ -96,7 +96,7 @@ jobs:
9696
./bin/sbt-ci.sh bloopgun/graalvm-native-image:packageBin
9797
- name: Run launcher tests
9898
run: |
99-
./bin/sbt-ci.sh "launcher/test"
99+
./bin/sbt-ci.sh "launcherTest/test"
100100
shell: bash
101101

102102
publish-binaries:
@@ -134,9 +134,9 @@ jobs:
134134
gu install native-image
135135
./bin/sbt-ci.sh "bloopgun/graalvm-native-image:packageBin"
136136
mkdir bloop-artifacts
137-
cp bloopgun/target/graalvm-native-image/bloopgun bloop-artifacts/$ARTIFACT_NAME
137+
cp bloopgun/target/bloopgun-2.12/graalvm-native-image/bloopgun bloop-artifacts/$ARTIFACT_NAME
138138
shell: bash
139-
- uses: actions/upload-artifact@master
139+
- uses: actions/upload-artifact@v2
140140
with:
141141
name: bloop-artifacts
142142
path: bloop-artifacts/${{ matrix.artifact }}
@@ -183,21 +183,21 @@ jobs:
183183
# cmd.
184184
# Keep the sbt version in sync with `sbt-ci-release.bat`.
185185
run: |
186-
sbt -sbt-version 1.3.3 version
186+
sbt -sbt-version 1.6.2 version
187187
shell: bash
188188
- name: Publish GraalVM Native artifacts
189189
run: >-
190-
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" &&
190+
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" &&
191191
"%CD%"\bin\sbt-ci-release.bat
192192
shell: cmd
193193
- name: Prepare generated Windows GraalVM binary
194194
run: |
195195
echo $ARTIFACT_NAME
196-
ls bloopgun/target/graalvm-native-image/bloopgun.exe
196+
ls bloopgun/target/bloopgun-2.12/graalvm-native-image/bloopgun.exe
197197
mkdir bloop-artifacts
198-
cp bloopgun/target/graalvm-native-image/bloopgun.exe bloop-artifacts/$ARTIFACT_NAME
198+
cp bloopgun/target/bloopgun-2.12/graalvm-native-image/bloopgun.exe bloop-artifacts/$ARTIFACT_NAME
199199
shell: bash
200-
- uses: actions/upload-artifact@master
200+
- uses: actions/upload-artifact@v2
201201
with:
202202
name: bloop-artifacts
203203
path: bloop-artifacts/${{ matrix.artifact }}

.gitmodules

Lines changed: 0 additions & 4 deletions
This file was deleted.

backend/src/main/scala/bloop/BloopClassFileManager.scala

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
package bloop
22

3-
import bloop.io.{Paths => BloopPaths}
43
import bloop.io.AbsolutePath
5-
import bloop.tracing.BraveTracer
64
import bloop.io.ParallelOps
75
import bloop.io.ParallelOps.CopyMode
6+
import bloop.io.{Paths => BloopPaths}
7+
import bloop.reporter.Reporter
8+
import bloop.tracing.BraveTracer
9+
import monix.eval.Task
10+
import xsbti.compile.ClassFileManager
11+
import xsbti.compile.PreviousResult
812

913
import java.io.File
14+
import java.io.IOException
15+
import java.nio.file.CopyOption
16+
import java.nio.file.Files
1017
import java.nio.file.Path
1118
import java.nio.file.Paths
12-
19+
import java.nio.file.StandardCopyOption
1320
import scala.collection.mutable
14-
15-
import xsbti.compile.ClassFileManager
16-
import monix.eval.Task
17-
import bloop.reporter.Reporter
18-
import xsbti.compile.PreviousResult
19-
import java.nio.file.Files
20-
import java.io.IOException
21-
import scala.util.Try
2221
import scala.util.Failure
2322
import scala.util.Success
23+
import scala.util.Try
2424

2525
final class BloopClassFileManager(
26+
backupDir0: Path,
2627
inputs: CompileInputs,
2728
outPaths: CompileOutPaths,
2829
allGeneratedRelativeClassFilePaths: mutable.HashMap[String, File],
29-
readOnlyCopyBlacklist: mutable.HashSet[Path],
30+
readOnlyCopyDenylist: mutable.HashSet[Path],
3031
allInvalidatedClassFilesForProject: mutable.HashSet[File],
3132
allInvalidatedExtraCompileProducts: mutable.HashSet[File],
3233
backgroundTasksWhenNewSuccessfulAnalysis: mutable.ListBuffer[CompileBackgroundTasks.Sig],
@@ -38,9 +39,16 @@ final class BloopClassFileManager(
3839
private[this] val newClassesDirPath = newClassesDir.toString
3940
private[this] val dependentClassFilesLinks = new mutable.HashSet[Path]()
4041
private[this] val weakClassFileInvalidations = new mutable.HashSet[Path]()
42+
private[this] val generatedFiles = new mutable.HashSet[File]
4143

4244
// Supported compile products by the class file manager
4345
private[this] val supportedCompileProducts = List(".sjsir", ".nir", ".tasty")
46+
// Files backed up during compilation
47+
private[this] val movedFiles = new mutable.HashMap[File, File]
48+
49+
private val backupDir = backupDir0.normalize
50+
backupDir.toFile.delete()
51+
Files.createDirectories(backupDir)
4452

4553
/**
4654
* Returns the set of all invalidated class files.
@@ -114,22 +122,21 @@ final class BloopClassFileManager(
114122
inputs.dependentResults
115123
) match {
116124
case None => ()
117-
case Some(foundClassFile) =>
125+
case Some(foundClassFilePath) =>
118126
weakClassFileInvalidations.+=(classFilePath)
119127
val newLink = newClassesDir.resolve(relativeFilePath)
120-
BloopClassFileManager.link(newLink, foundClassFile.toPath) match {
128+
BloopClassFileManager.link(newLink, foundClassFilePath) match {
121129
case Success(_) => dependentClassFilesLinks.+=(newLink)
122130
case Failure(exception) =>
123131
inputs.logger.error(
124-
s"Failed to create link for invalidated file $foundClassFile: ${exception.getMessage()}"
132+
s"Failed to create link for invalidated file $foundClassFilePath: ${exception.getMessage()}"
125133
)
126134
inputs.logger.trace(exception)
127135
}
128136
()
129137
}
130138
}
131139
}
132-
133140
allInvalidatedClassFilesForProject.++=(classes)
134141

135142
val invalidatedExtraCompileProducts = classes.flatMap { classFile =>
@@ -142,12 +149,28 @@ final class BloopClassFileManager(
142149
}
143150
}
144151

152+
// Idea taken from the default TransactionalClassFileManager in zinc
153+
// https://github.com/sbt/zinc/blob/c18637c1b30f8ab7d1f702bb98301689ec75854b/internal/zinc-core/src/main/scala/sbt/internal/inc/ClassFileManager.scala#L183
154+
val toBeBackedUp = (classes ++ invalidatedExtraCompileProducts).filter(c =>
155+
!movedFiles.contains(c) && !generatedFiles(c)
156+
)
157+
for {
158+
c <- toBeBackedUp
159+
if c.exists()
160+
} movedFiles.put(c, move(c)).foreach(move)
161+
162+
for {
163+
f <- classes
164+
if f.exists()
165+
} f.delete()
166+
145167
allInvalidatedExtraCompileProducts.++=(invalidatedExtraCompileProducts)
146168
}
147169

148170
def generated(generatedClassFiles: Array[File]): Unit = {
149171
memoizedInvalidatedClassFiles = null
150172
generatedClassFiles.foreach { generatedClassFile =>
173+
generatedFiles += generatedClassFile
151174
val newClassFile = generatedClassFile.getAbsolutePath
152175
val relativeClassFilePath = newClassFile.replace(newClassesDirPath, "")
153176
allGeneratedRelativeClassFilePaths.put(relativeClassFilePath, generatedClassFile)
@@ -157,16 +180,24 @@ final class BloopClassFileManager(
157180
// invalidations can happen in both paths, no-op if missing
158181
allInvalidatedClassFilesForProject.-=(generatedClassFile)
159182
allInvalidatedClassFilesForProject.-=(rebasedClassFile)
160-
supportedCompileProducts.foreach { supportedProductSuffix =>
161-
val productName = rebasedClassFile
183+
184+
def productFile(classFile: File, supportedProductSuffix: String) = {
185+
val productName = classFile
162186
.getName()
163187
.stripSuffix(".class") + supportedProductSuffix
164-
val productAssociatedToClassFile =
165-
new File(rebasedClassFile.getParentFile, productName)
166-
if (productAssociatedToClassFile.exists())
167-
allInvalidatedExtraCompileProducts.-=(productAssociatedToClassFile)
188+
new File(classFile.getParentFile, productName)
189+
}
190+
supportedCompileProducts.foreach { supportedProductSuffix =>
191+
val generatedProductName = productFile(generatedClassFile, supportedProductSuffix)
192+
val rebasedProductName = productFile(rebasedClassFile, supportedProductSuffix)
193+
194+
if (generatedProductName.exists() || rebasedProductName.exists()) {
195+
allInvalidatedExtraCompileProducts.-=(generatedProductName)
196+
allInvalidatedExtraCompileProducts.-=(rebasedProductName)
197+
}
168198
}
169199
}
200+
170201
}
171202

172203
def complete(success: Boolean): Unit = {
@@ -193,13 +224,28 @@ final class BloopClassFileManager(
193224
enableCancellation = false
194225
)
195226
.map { walked =>
196-
readOnlyCopyBlacklist.++=(walked.target)
227+
readOnlyCopyDenylist.++=(walked.target)
197228
()
198229
}
199230
}
200231
}
201232
)
202233
} else {
234+
/* Restore all files from backuped last successful compilation to make sure
235+
* that they are still available.
236+
*/
237+
for {
238+
(orig, tmp) <- movedFiles
239+
if tmp.exists
240+
} {
241+
if (!orig.getParentFile.exists) {
242+
Files.createDirectory(orig.getParentFile.toPath())
243+
}
244+
Files.move(tmp.toPath(), orig.toPath())
245+
}
246+
backupDir.toFile().delete()
247+
()
248+
203249
// Delete all compilation products generated in the new classes directory
204250
val deleteNewDir = Task { BloopPaths.delete(AbsolutePath(newClassesDir)); () }.memoize
205251
backgroundTasksForFailedCompilation.+=(
@@ -245,6 +291,12 @@ final class BloopClassFileManager(
245291
)
246292
}
247293
}
294+
295+
private def move(c: File): File = {
296+
val target = Files.createTempFile(backupDir, "bloop", ".class").toFile
297+
Files.move(c.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING)
298+
target
299+
}
248300
}
249301

250302
object BloopClassFileManager {

backend/src/main/scala/bloop/BloopClasspathEntryLookup.scala

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,54 @@
11
package bloop
22

3-
import java.io.File
4-
import java.{util => ju}
5-
6-
import sbt.util.InterfaceUtil
3+
import bloop.util.AnalysisUtils
4+
import sbt.internal.inc.PlainVirtualFileConverter
5+
import sbt.internal.inc.bloop.internal.BloopNameHashing
6+
import sbt.internal.inc.bloop.internal.BloopStamps
7+
import sbt.internal.inc.classpath.ClasspathUtil
78
import sbt.internal.inc.classpath.ClasspathUtilities
8-
9-
import xsbti.compile.PreviousResult
10-
import xsbti.compile.PerClasspathEntryLookup
9+
import sbt.util.InterfaceUtil
10+
import xsbti.FileConverter
11+
import xsbti.VirtualFile
1112
import xsbti.compile.CompileAnalysis
1213
import xsbti.compile.DefinesClass
13-
import java.util.zip.ZipFile
14-
import java.util.zip.ZipException
15-
import java.util.concurrent.ConcurrentHashMap
1614
import xsbti.compile.FileHash
17-
import sbt.internal.inc.bloop.internal.BloopNameHashing
18-
import sbt.internal.inc.bloop.internal.BloopStamps
15+
import xsbti.compile.PerClasspathEntryLookup
16+
import xsbti.compile.PreviousResult
17+
18+
import java.io.File
19+
import java.nio.file.Path
20+
import java.util.concurrent.ConcurrentHashMap
21+
import java.util.zip.ZipException
22+
import java.util.zip.ZipFile
23+
import java.{util => ju}
1924

2025
final class BloopClasspathEntryLookup(
2126
results: Map[File, PreviousResult],
22-
classpathHashes: Vector[FileHash]
27+
classpathHashes: Vector[FileHash],
28+
converter: FileConverter
2329
) extends PerClasspathEntryLookup {
24-
override def analysis(classpathEntry: File): ju.Optional[CompileAnalysis] = {
25-
InterfaceUtil.toOptional(results.get(classpathEntry)).flatMap(_.analysis())
30+
override def analysis(classpathEntry: VirtualFile): ju.Optional[CompileAnalysis] = {
31+
val file = converter.toPath(classpathEntry).toFile()
32+
InterfaceUtil.toOptional(results.get(file)).flatMap(_.analysis())
2633
}
2734

28-
override def definesClass(entry: File): DefinesClass = {
29-
if (!entry.exists) FalseDefinesClass
35+
override def definesClass(entry: VirtualFile): DefinesClass = {
36+
val path = converter.toPath(entry)
37+
val file = path.toFile()
38+
if (!file.exists) FalseDefinesClass
3039
else {
31-
classpathHashes.find(fh => fh.file() == entry) match {
40+
classpathHashes.find(fh => fh.file() == file) match {
3241
case None => FalseDefinesClass
3342
case Some(entryHash) =>
3443
def computeDefinesClassForJar = {
35-
if (!ClasspathUtilities.isArchive(entry, contentFallback = true)) FalseDefinesClass
36-
else new JarDefinesClass(entry)
44+
if (!ClasspathUtil.isArchive(path, contentFallback = true)) FalseDefinesClass
45+
else new JarDefinesClass(file)
3746
}
3847

39-
if (BloopStamps.isDirectoryHash(entryHash)) new DirectoryDefinesClass(entry)
48+
if (BloopStamps.isDirectoryHash(entryHash)) new DirectoryDefinesClass(file)
4049
else {
4150
val (_, cachedDefinesClass) = BloopClasspathEntryLookup.definedClasses.compute(
42-
entry,
51+
file,
4352
(entry, definesClass) => {
4453
definesClass match {
4554
case null =>
@@ -116,14 +125,15 @@ object BloopClasspathEntryLookup {
116125
def definedClassFileInDependencies(
117126
relativeClassFile: String,
118127
results: Map[File, PreviousResult]
119-
): Option[File] = {
120-
def findClassFile(t: (File, PreviousResult)): Option[File] = {
128+
): Option[Path] = {
129+
def findClassFile(t: (File, PreviousResult)): Option[Path] = {
121130
val (classesDir, result) = t
122-
val targetClassFile = new File(classesDir, relativeClassFile)
131+
val targetFile = classesDir.toPath().resolve(relativeClassFile)
132+
val targetClassFile = PlainVirtualFileConverter.converter.toVirtualFile(targetFile)
123133
InterfaceUtil.toOption(result.analysis()).flatMap { analysis0 =>
124134
val analysis = analysis0.asInstanceOf[sbt.internal.inc.Analysis]
125135
val definedClass = analysis.relations.allProducts.contains(targetClassFile)
126-
if (definedClass) Some(targetClassFile) else None
136+
if (definedClass) Some(targetFile) else None
127137
}
128138
}
129139

backend/src/main/scala/bloop/CompileMode.scala

Lines changed: 0 additions & 27 deletions
This file was deleted.

backend/src/main/scala/bloop/CompileProducts.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@ case class CompileProducts(
3535
resultForDependentCompilationsInSameRun: PreviousResult,
3636
resultForFutureCompilationRuns: PreviousResult,
3737
invalidatedCompileProducts: Set[File],
38-
generatedRelativeClassFilePaths: Map[String, File],
39-
definedMacroSymbols: Array[String]
38+
generatedRelativeClassFilePaths: Map[String, File]
4039
)

0 commit comments

Comments
 (0)