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

In-source sbt compiler bridge [ci: last-only] #10472

Merged
merged 507 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
507 commits
Select commit Hold shift + click to select a range
83c22a8
Fix computing name hashes for private classes
gkossakowski Mar 4, 2016
b5964be
Remove unnecessary ExtractAPI.forceStructures calls
gkossakowski Feb 29, 2016
9723b0d
Merge branch '1.0' into cd-filter-branch
gkossakowski Mar 16, 2016
4d5b8e2
Fix broken merge in Dependency.scala
gkossakowski Mar 16, 2016
abc30fb
Fix build failure of the Scala 2.10 bridge sources
gkossakowski Mar 16, 2016
f1c9763
Fix Scaladoc failures in Dependency.scala
gkossakowski Mar 16, 2016
e852757
Move Analyze and ClassToAPI specifications
gkossakowski Mar 25, 2016
25d168f
Remove `declaredClasses` relation.
gkossakowski Mar 25, 2016
4ac773b
Reduce dependency on CallbackGlobal.
gkossakowski Mar 29, 2016
4b4c48e
Compiler instances handling in ScalaCompilerForUnitTesting
gkossakowski Mar 8, 2016
6be0bb3
Add a pending test for self variable bug (#2504)
gkossakowski Mar 30, 2016
e61e1a1
Fix instability of self variable API representation
gkossakowski Mar 30, 2016
3b818de
A wording improvement in ExtractAPISpecification
gkossakowski Mar 30, 2016
6966322
Include used types in the set of used names
smarter Mar 20, 2016
f1d3170
Simplify value class API handling and fix sbt/sbt#2497
smarter Apr 9, 2016
50046e6
Remove leftover dead code after #95
smarter Apr 15, 2016
c1a2d62
Refactor ClassLike and add ClassLikeDef
gkossakowski Apr 14, 2016
388c9bc
Ref sbt/sbt#2537. Includes synthetic methods to name hashing
eed3si9n Apr 6, 2016
d2012fd
Fix sbt/sbt#2560
eed3si9n Apr 18, 2016
1f076e2
Avoid CCE when scalac internally uses compileLate. Fixes #2452
retronym Feb 10, 2016
f7b3f82
Merge pull request #111 from eed3si9n/wip/2563
eed3si9n May 2, 2016
11fe9d5
Merge pull request #112 from eed3si9n/wip/2453
eed3si9n May 3, 2016
69baacb
Fix naming of inherited classes in ExtractAPI
gkossakowski Apr 15, 2016
e3a73fe
Use `Global.debuglog` for logging
gkossakowski Apr 26, 2016
442d7d0
Merge pull request #116 from gkossakowski/inherited-classes
eed3si9n May 4, 2016
6c1d7de
Fix format
eed3si9n May 5, 2016
e5f7941
Bump to sbt-datatype 0.2.2
eed3si9n Jul 16, 2016
1ddb0a6
Forward port of sbt/sbt#2767
avdv Oct 25, 2016
9f6126e
Zinc extract used names is very sluggish
wpopielarski Nov 12, 2016
0176108
Cache visited TypeTree
eed3si9n Nov 12, 2016
0e45204
Apply #193 to 2.10 bridge
eed3si9n Nov 23, 2016
0b5c4d0
Bump Scalatest and sjson-new
eed3si9n Dec 23, 2016
5a314c5
Cross build to Scala 2.12
eed3si9n Jan 7, 2017
360c74f
Speed up API phase
romanowski Nov 9, 2016
2f89553
Speedup Dependency phase.
romanowski Nov 9, 2016
d9ef077
Add callbacks at the end of Dependecy and API phases (in AnalysisCall…
romanowski Jan 25, 2017
aa59aa4
Add option to disable incremental compilation
romanowski Oct 21, 2016
013abba
Add checks against NoType
jvican Jan 31, 2017
b718871
Add helpers `ignoredType` and `ignoredSymbol`
jvican Feb 6, 2017
f3094c4
Use `foreachSymbolInType` for performance reasons
jvican Feb 6, 2017
4b3de42
Rename `foreachSymbolInType` to concise name
jvican Feb 6, 2017
5474aa6
Clean up code and comment in `ExtractUsedNames`
jvican Feb 6, 2017
5417cb0
Fix #113: Implement `SafeLazy` in Java
jvican Feb 7, 2017
3b5a240
Add `Feedback` object that holds common error msgs
jvican Feb 7, 2017
51f6df2
Put copyright notice
eed3si9n Feb 7, 2017
f33b0bb
Fixes in exportable cache mappers.
romanowski Dec 14, 2016
48a754f
Add missing headers.
romanowski Feb 8, 2017
dbbbcda
Merge pull request #213 from romanowski/turn-off-incremental-compilation
eed3si9n Feb 8, 2017
53c2a47
Merge pull request #216 from romanowski/cached-compilaiton
eed3si9n Feb 13, 2017
2abceaf
Use `computePhaseDescriptors` directly
jvican Feb 15, 2017
919e729
Add first version of JMH benchmarks
jvican Feb 13, 2017
da9b61f
Use `ignoredSymbol` in API & reorder `isTopLevel`
jvican Feb 8, 2017
ec1cfda
Improve performance of `Dependency`
jvican Feb 8, 2017
cd41c3d
Remove outdated comment
jvican Feb 8, 2017
fe9c688
Compute moduleClass of `responsibleOfImports` once
jvican Feb 10, 2017
04ba920
Reuse name cache and don't add repeated names
jvican Feb 11, 2017
60b09f1
migrate to java.util.Optional based Position
eed3si9n Jan 26, 2017
322516c
Logger reporter uses event logging
eed3si9n Jan 26, 2017
48fbb78
Fix DelegatingReporter
eed3si9n Feb 17, 2017
119e394
Backport changes from several previous PRs
jvican Feb 21, 2017
2e58d6d
Make ExtractAPI#annotations phase travel to entering typer, again
dwijnand Feb 24, 2017
39f41a5
Optimize `DependencySource` and `EnclosingNonLocal`
jvican Feb 19, 2017
57d2439
Improve test for "names in type tree"
jvican Feb 24, 2017
acb8236
Fix #174: Register names for types and symbols
jvican Feb 25, 2017
2015bcd
Cache type dependency tracking aggressively
jvican Feb 25, 2017
c94311a
Remove `nameHashing` and `antStyle` option
jvican Feb 26, 2017
bc86c50
Raise the timer of names performance
jvican Feb 26, 2017
57cd673
Merge branch '1.0' into as-seen-from
jvican Feb 26, 2017
072408e
Dedup src diffs between 2.10 & 2.11+
dwijnand Feb 27, 2017
023c634
Fix issue with 2.10 traversals
jvican Mar 2, 2017
f7c931f
Fixed compiler warnings, mostly removed unused imports and renamed un…
wlk Mar 7, 2017
c0a3557
Fix #245 Replace use of Scala collections by Java's in Dependency.sca…
wlk Mar 7, 2017
4b337ad
Fix #101: Remove SimpleType
ttreyer Mar 8, 2017
8758b55
ConsoleInterface (+java interfaces) port over from sbt-pamflet
eed3si9n Mar 11, 2017
f6213a9
Cleanup and add a test suite
knirski Mar 11, 2017
77c79b7
Zinc can now declare multiple scopes for name usage.
romanowski Jan 31, 2017
821b8f9
Implement PatMat
romanowski Feb 3, 2017
d65b202
Make minor changes to `ExtractUsedNames` et al
jvican Mar 16, 2017
57815da
Add missing headers
romanowski Mar 18, 2017
b241aa9
Fix #269: Traverse original trees in `Dependency`
jvican Mar 19, 2017
f339b45
Merge pull request #267 from romanowski/sealed-impr
dwijnand Mar 28, 2017
4f7c34d
Merge pull request #264 from zehkae/issue101
jvican Apr 4, 2017
371b374
Remove laziness in Structure type
ttreyer Apr 4, 2017
80be2a9
Remove laziness in ClassLike definition
ttreyer Mar 22, 2017
1adc978
Revert "Remove laziness in ClassLike definition"
eed3si9n Apr 15, 2017
b9bd9ec
Revert "Remove laziness in Structure type"
eed3si9n Apr 15, 2017
a9cb182
Reformat zinc with scalafmt
jvican May 3, 2017
929ab7c
Cleanup the ConsoleInterface API & AnalyzingCompiler
dwijnand May 2, 2017
ad713d4
Move the sbt-pamflet ConsoleInterface API to Interactive*
dwijnand May 3, 2017
0c4e040
Recover the pre-pamflet merge ConsoleInterface
dwijnand May 3, 2017
2075526
Format ConsoleInterface
dwijnand May 3, 2017
809e8c5
Cleanup ConsoleInterface
dwijnand May 3, 2017
66a3231
Fix #97: Avoid spurious recompilations when unrelated constructor cha…
smarter Apr 6, 2017
9dbf5f6
Remove deprecated compatibility stubs
jvican May 15, 2017
d60901f
Make Zinc `Global` implementations independent
jvican May 15, 2017
7f543dc
Replace `OutputSetting` by `OutputGroup`
jvican May 17, 2017
3ae7df2
Fix `Output` and `Compilation` API
jvican May 17, 2017
61c7a77
Remove `apiNote` since Javadoc doesn't accept it
jvican May 17, 2017
0dac786
Make the Output API more Java friendly
jvican May 17, 2017
ae1c68a
Add headers to files that don't have them
jvican May 18, 2017
0db40de
Fix #102: Better main class detection
smarter May 26, 2017
5c7bebf
Fix ConsoleInterface binding things properly.
dwijnand Jun 9, 2017
899d5fe
Fix ScalaFmt wiring
eed3si9n Jul 3, 2017
29ba356
Make caches in 'ExtractAPI' use 'perRunCaches' #324
Jul 7, 2017
ae05eb4
Remove unused 'resident' occurrence
lukeindykiewicz Jul 7, 2017
368046f
Merge branch '1.0' into 1.0
Duhemm Jul 10, 2017
01294ce
Commit auto-formatting code
dwijnand Jul 13, 2017
d490e2a
Clean up DelegatingReporter
jvican Jun 21, 2017
e0311e9
Address Martin's feedback
jvican Jul 13, 2017
e4c873e
Remove any reference to `F0` and `F1`
jvican Jul 14, 2017
bd81342
Bump to the latest Contraband
eed3si9n Jul 14, 2017
40a03fe
Merge branch 'pr/359' into wip/integration
eed3si9n Jul 15, 2017
f1d1af9
Drop util-testing in favour of existing UnitSpec
dwijnand Jun 23, 2017
5bab98c
Add back, re-configure & re-enable Scalafmt
dwijnand Aug 22, 2017
ef72da3
Fix ConsoleInterface binding things properly^2
dwijnand Jul 31, 2017
f57fa2f
Fix depending on non-existing objects from imports.
romanowski Oct 5, 2017
1049cfd
Move REPL related xsbti Java to correct module
eed3si9n Oct 9, 2017
ffbbf85
Move mima exclusions to its own file
eed3si9n Oct 9, 2017
0fb6769
Fixes undercompilation on inheritance on same source
eed3si9n Oct 12, 2017
4db9cbf
Fix #127: Use `unexpanded` name instead of `name`
jvican Oct 13, 2017
6167205
Merge branch '1.0.x' into issue-127
jvican Oct 16, 2017
4529040
Remove unused imports + variables
allantl Oct 22, 2017
ccb8e34
Forward port sbt/sbt#3701, JDK9/Scala 2.{10,11} overcompilation
retronym Nov 1, 2017
2a00087
Fix #442: Name hash of value class should include underlying type
smarter Oct 24, 2017
e8a1045
"sbt '++ 2.13.0-M2!' compile" does not work with sbt 1.0.0
jan0sch Oct 26, 2017
b29e3e1
Implement compiler bridge for 2.13.0-M2
eed3si9n Nov 16, 2017
b359908
Split compiler bridge tests to another subproject
eed3si9n Nov 16, 2017
4ff3d7b
Merge branch '1.0.x' into merge-1.0.x-into-1.x
dwijnand Nov 23, 2017
d334cc7
Add 1.0.5 to mimaPreviousArtifacts, & backfill
dwijnand Dec 18, 2017
7ec16de
Remove unused imports except ZincBenchmark.TryEnrich that is for < Sc…
Feb 11, 2018
6050184
Revert changes that may break tests.
Feb 11, 2018
d5c1c8f
Switch to new type
Feb 20, 2018
1b0cde0
Remove setContextClassLoader which is no-op since scala 2.12.0
Feb 20, 2018
2e6816f
Avoid use of WrappedArray in favour of direct Array usage
retronym Feb 17, 2018
236ee1b
Optimize annotation extraction
retronym Feb 20, 2018
8fccaf5
Use iterators rather than foreach
retronym Feb 20, 2018
876b364
Use AnyRefMap
retronym Feb 19, 2018
f4a9f82
Use Java collections
retronym Feb 22, 2018
7da3245
Suppress "discarded non-Unit" warnings.
Feb 22, 2018
831aaab
extract class dependency from 'classOf' Literal
natansil Mar 8, 2018
5bc7cd8
Revert "Use Java collections"
eed3si9n May 6, 2018
ab4d5c4
Revert "Use AnyRefMap"
eed3si9n May 6, 2018
ad48e02
Merge branch '1.1.x' into 1.x+1.1.x
jvican May 8, 2018
885cc39
Merge branch '1.x' into names-from-nonexisiting-objects
jvican Jun 5, 2018
3998b13
Got rid of multiple warnigns
lukaszwawrzyk Jun 4, 2018
5094876
Fix discarded non-Unit value warnings
lukaszwawrzyk Jun 4, 2018
9fb989e
Use reporter instead of forwarder in global
som-snytt Jul 25, 2018
bfb58a1
Extraneous semis
som-snytt Jul 25, 2018
64c88a6
Fix mismatch between apply methods and initializers
jvican Aug 13, 2018
8fcc9d3
Traverse synthetic top-level members
jvican Aug 14, 2018
92e1df3
sbt.internal.inc.Position: record range information
smarter Aug 12, 2018
44256ee
Move notification of non-local classes to `API`
jvican Aug 16, 2018
45ec259
Update API.scala
jvican Aug 29, 2018
bc12362
Merge pull request #582 from scalacenter/topic/merge-analyzer-and-api
jvican Aug 29, 2018
90614f5
Do best effort to detect `associatedFile` if empty
jvican Aug 31, 2018
cb3748d
Cache results of `findAssociatedFile` for performance
jvican Aug 31, 2018
be67a06
Straight to jar compilation
lukaszwawrzyk Sep 12, 2018
19000a9
Initial reworks
lukaszwawrzyk Sep 18, 2018
9a42971
Change the way of injecting javac temp dir to keep binary compatibility
lukaszwawrzyk Sep 18, 2018
55e1d73
Refactor JaredClass
lukaszwawrzyk Sep 18, 2018
f98b6ec
Added more comments
lukaszwawrzyk Sep 20, 2018
92f5e51
Rename STJ to JarUtils
lukaszwawrzyk Sep 27, 2018
7e7e610
Renamed JaredClass to ClassInJar
lukaszwawrzyk Sep 27, 2018
25006e8
Create JarUtils only once in CallbackGlobal
lukaszwawrzyk Sep 27, 2018
3554692
Moved prev jar path generation and resolving to AnalysisCallback
lukaszwawrzyk Sep 28, 2018
56e87fd
map + getOrElse => match for readability
lukaszwawrzyk Oct 1, 2018
3290f29
Move jar content logic out of bridge
lukaszwawrzyk Oct 2, 2018
62a1edc
Add final modifications to straight-to-jar changes
jvican Oct 4, 2018
ddcf5c1
Refactor compiler bridge unit test
eed3si9n Oct 12, 2018
7cb066f
Optimize finding output dir for source
lukaszwawrzyk Nov 29, 2018
a932014
Sources formatting
dotta Dec 15, 2018
dd65ec4
Bump houserules and Contraband
eed3si9n Sep 27, 2018
7235952
Call Global.close when finished compiling
retronym Feb 26, 2019
1d93a16
Apply header
eed3si9n May 6, 2019
f916e7f
apply formatting
eed3si9n May 13, 2019
b318675
Ignore stub symbols when API hashing annotations
retronym Oct 11, 2019
8d44dbd
workaround Scaladoc range position bug
eed3si9n Feb 3, 2020
caf9fed
Add VirtualFile / VirtualFileRef / FileConverter
eed3si9n Oct 25, 2019
7ba0c66
Fix the Windows regression around <
eed3si9n Apr 22, 2020
27d3517
Avoid slow path for associated file more often
retronym Apr 21, 2020
997bfcd
Merge pull request #758 from retronym/topic/assoc-file
dwijnand Apr 23, 2020
34e6d56
Reduce overhead of workarkaround for Scala 2.11 on JDK9+
retronym Apr 24, 2020
f74c716
Convert VirtualFile to PlainFile in the compiler bridge
adpi2 Jun 2, 2020
148b36c
Ignore annotations are inadvertently added to NoSymbol
retronym Jun 18, 2020
c98773c
Avoid distinct call, the LinkedHashSet serves the same purpose
retronym Jun 18, 2020
7b88ad4
Implement early output and early analysis
eed3si9n May 2, 2020
fe73c69
Expand CompileProgress and Setup
eed3si9n Mar 7, 2020
123233a
Implement pipelining using custom pickle jar
eed3si9n May 1, 2020
3199bec
Use -Ypickle-java to generate pickles from Java
eed3si9n Apr 1, 2020
bc92294
Replace PickleData with -Ypickle-write
dwijnand Jun 17, 2020
d0e5abf
Cleanup parts of the VirtualFile-related code
dwijnand Jun 13, 2020
3679e72
Merge pull request #820 from dwijnand/cleanup-VirtualFile-related-cod…
dwijnand Jul 10, 2020
b5a99f5
Handle a dependency on JRT as a dummy rt.jar
dwijnand Jul 10, 2020
e7f3542
Reluctantly restore compatibility of xsbti.*
eed3si9n Jul 8, 2020
b663132
Address review
eed3si9n Jul 13, 2020
d447ffd
Avoid unsafe code around CachedCompiler2
dwijnand Jul 14, 2020
551a462
Use the real 2.12 scala.reflect.io.PlainNioFile
dwijnand Jul 10, 2020
81b256d
Merge pull request #829 from eed3si9n/wip/dotty
eed3si9n Jul 14, 2020
eab767b
Remove CompilerCache implementation
eed3si9n Jul 15, 2020
b84786c
Undouble CachedCompiler0#run
dwijnand Jul 15, 2020
cc2cb02
Merge pull request #828 from dwijnand/use-the-real-2.12-PlainNioFile
eed3si9n Jul 16, 2020
a6eaf44
Merge pull request #840 from dwijnand/drop-CompilerCache
eed3si9n Jul 17, 2020
619c647
Ignore scala.reflect.io.FileZipArchive$LeakyEntry
eed3si9n Jul 26, 2020
5c1f1b7
Use toIterator instead of toStream
eatkins Jul 28, 2020
8742abc
Make xsbt.CompilerInterface class name configurable
eed3si9n Aug 10, 2020
b35d58e
Add close method to interactive console
eed3si9n Aug 11, 2020
925a6f8
Fix extraction of source <-> class mappings for Java
dwijnand Aug 10, 2020
eaec4dd
Demote some warnings to echos to avoid failing with -Xfatal-warnings
dwijnand Aug 10, 2020
9386d78
Merge pull request #872 from eed3si9n/wip/service
eed3si9n Aug 13, 2020
3ed243e
Merge pull request #875 from eed3si9n/wip/close
eed3si9n Aug 13, 2020
78f693e
Add classpath parameter to compile
eed3si9n Aug 10, 2020
e0b1a43
Reduce footprint by interning stringified Names in Analysis
retronym Apr 19, 2020
8959642
fix warning "return statement uses an exception to pass control to th…
jtjeferreira Aug 19, 2020
07fdb81
Fix some compiler warnings
eatkins Aug 26, 2020
c94cccf
Make doc work with sbt 1.4.x
eatkins Aug 25, 2020
d51f84c
Fix match error in DelegatingReporter.scala
eatkins Sep 3, 2020
84fad04
Don't initialize symbols before finding classfile
Duhemm Nov 27, 2020
c89a16e
Don't initialize symbols before finding classfile
Duhemm Nov 27, 2020
b72b2f6
Merge pull request #953 from eed3si9n/bport/950
eed3si9n Nov 30, 2020
f3f7522
Reuse a TreePrinter for less allocation and lock contention
retronym Mar 23, 2021
1373279
Merge branch 'develop' into topic/used-names-memory
eed3si9n Mar 28, 2021
e502a8e
Fix undercompilation matching a parent sealed
dwijnand May 25, 2021
f80c3c1
Track dependencies using OriginalTreeAttachments
ephemerist Apr 6, 2021
5541afd
Suppress an exhaustivity warning
dwijnand Jul 23, 2021
8980591
Force the type of an annotation's typeSymbol beofre checking isStatic
lrytz Aug 10, 2021
4fe49b2
Make accessing OriginalTree noop on Scala 2.12.0-2
dwijnand Jul 27, 2021
a8b1ddf
Fix ClassCastException in reflective original tree lookup
retronym Jul 28, 2021
cab623d
fix warnings
xuwei-k Nov 14, 2021
d94b719
run headerCreateAll
SethTisue Feb 13, 2022
7d1c8fe
reformat sources using new scalafmt version and config
SethTisue Feb 14, 2022
8379954
remove some old Scala 2.8/9 support code
SethTisue Mar 15, 2022
8277202
silence deprecation warnings, fix typos
SethTisue Mar 16, 2022
51c59d7
Avoid null delegate reporter
som-snytt Jan 19, 2022
fd233e7
Upgrade to util 1.9.0-RC2-2
eed3si9n May 15, 2023
571ae74
Add test for actions
eed3si9n May 15, 2023
08e5f69
add tailrec annotation
xuwei-k Jun 25, 2023
3da709c
Transfer copyright to the Scala Center
eed3si9n Jun 25, 2023
366ba2f
Merge pull request #1209 from xuwei-k/tailrec
eed3si9n Jun 25, 2023
80e8df9
Prepare zinc repo for moving bridge to scala/scala
lrytz Jul 12, 2023
b8cebcc
Integrate compiler bridge sources with git history from zinc
lrytz Jul 12, 2023
5910f0e
sbt project for sbt-bridge
lrytz Jul 13, 2023
9cd09ac
sbtBridge/headerCreate
lrytz Jul 13, 2023
3f4493c
fix package declarations
lrytz Jul 13, 2023
cfebacb
basic test for sbt bridge
lrytz Jul 13, 2023
584f8d1
use code actions from compiler
lrytz Jul 13, 2023
81f0666
more tests
lrytz Jul 13, 2023
9e58f22
fix pomDependencyExclusions for ivy
lrytz Jul 17, 2023
039f658
add remaining tests
lrytz Jul 18, 2023
35a23d6
Use AnalysisCallback2 to avoid dropping CodeActions
lrytz Aug 2, 2023
33c45fc
Make scala2-sbt-bridge's dependencies "provided" (align with Scala 3)
lrytz Aug 3, 2023
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
111 changes: 93 additions & 18 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ val jnaDep = "net.java.dev.jna" % "jna"
val jlineDeps = Seq(jlineDep, jnaDep)
val testInterfaceDep = "org.scala-sbt" % "test-interface" % "1.0"
val diffUtilsDep = "io.github.java-diff-utils" % "java-diff-utils" % "4.12"
val compilerInterfaceDep = "org.scala-sbt" % "compiler-interface" % "1.9.3"

val projectFolder = settingKey[String]("subfolder in src when using configureAsSubproject, else the project name")

Expand Down Expand Up @@ -275,8 +276,26 @@ def fixPom(extra: (String, scala.xml.Node)*): Setting[_] = {
) ++ extra) }
}

def ivyDependencyFilter(deps: Seq[(String, String)], scalaBinaryVersion: String) = {
import scala.xml._
import scala.xml.transform._
new RuleTransformer(new RewriteRule {
override def transform(node: Node) = node match {
case e: Elem if e.label == "dependency" && {
val org = e.attribute("org").getOrElse("").toString
val name = e.attribute("name").getOrElse("").toString
deps.exists { case (g, a) =>
org == g && (name == a || name == (a + "_" + scalaBinaryVersion))
}
} => Seq.empty
case n => n
}
})
}

val pomDependencyExclusions =
settingKey[Seq[(String, String)]]("List of (groupId, artifactId) pairs to exclude from the POM and ivy.xml")
lazy val fixCsrIvy = taskKey[Unit]("Apply pomDependencyExclusions to coursier ivy")

Global / pomDependencyExclusions := Nil

Expand All @@ -294,27 +313,47 @@ lazy val removePomDependencies: Seq[Setting[_]] = Seq(
e.child.contains(<groupId>{g}</groupId>) &&
(e.child.contains(<artifactId>{a}</artifactId>) || e.child.contains(<artifactId>{a + "_" + scalaBinaryVersion.value}</artifactId>))
} => Seq.empty
case n => Seq(n)
case n => n
}
}).transform(Seq(n2)).head
},
fixCsrIvy := {
// - coursier makes target/sbt-bridge/resolution-cache/org.scala-lang/scala2-sbt-bridge/2.13.12-bin-SNAPSHOT/resolved.xml.xml
// - copied to target/sbt-bridge//ivy-2.13.12-bin-SNAPSHOT.xml
// - copied to ~/.ivy2/local/org.scala-lang/scala2-sbt-bridge/2.13.12-bin-SNAPSHOT/ivys/ivy.xml
import scala.jdk.CollectionConverters._
import scala.xml._
val currentProject = csrProject.value
val ivyModule = org.apache.ivy.core.module.id.ModuleRevisionId.newInstance(
currentProject.module.organization.value,
currentProject.module.name.value,
currentProject.version,
currentProject.module.attributes.asJava)
val ivyFile = ivySbt.value.withIvy(streams.value.log)(_.getResolutionCacheManager).getResolvedIvyFileInCache(ivyModule)
val e = ivyDependencyFilter(pomDependencyExclusions.value, scalaBinaryVersion.value)
.transform(Seq(XML.loadFile(ivyFile))).head
XML.save(ivyFile.getAbsolutePath, e, xmlDecl = true)
},
publishConfiguration := Def.taskDyn {
val pc = publishConfiguration.value
Def.task {
fixCsrIvy.value
pc
}
}.value,
publishLocalConfiguration := Def.taskDyn {
val pc = publishLocalConfiguration.value
Def.task {
fixCsrIvy.value
pc
}
}.value,
deliverLocal := {
// this doesn't seem to do anything currently, it probably worked before sbt used coursier
import scala.xml._
import scala.xml.transform._
val f = deliverLocal.value
val deps = pomDependencyExclusions.value
val e = new RuleTransformer(new RewriteRule {
override def transform(node: Node) = node match {
case e: Elem if e.label == "dependency" && {
val org = e.attribute("org").getOrElse("").toString
val name = e.attribute("name").getOrElse("").toString
deps.exists { case (g, a) =>
org == g && (name == a || name == (a + "_" + scalaBinaryVersion.value))
}
} => Seq.empty
case n => Seq(n)
}
}).transform(Seq(XML.loadFile(f))).head
val e = ivyDependencyFilter(pomDependencyExclusions.value, scalaBinaryVersion.value)
.transform(Seq(XML.loadFile(f))).head
XML.save(f.getAbsolutePath, e, xmlDecl = true)
f
}
Expand Down Expand Up @@ -579,6 +618,42 @@ lazy val scaladoc = configureAsSubproject(project)
)
.dependsOn(compiler)

// dependencies on compiler and compiler-interface are "provided" to align with scala3-sbt-bridge
lazy val sbtBridge = configureAsSubproject(project, srcdir = Some("sbt-bridge"))
.settings(Osgi.settings)
.settings(AutomaticModuleName.settings("scala.sbtbridge"))
//.settings(fatalWarningsSettings)
.settings(
name := "scala2-sbt-bridge",
description := "sbt compiler bridge for Scala 2",
libraryDependencies += compilerInterfaceDep % Provided,
generateServiceProviderResources("xsbti.compile.CompilerInterface2" -> "scala.tools.xsbt.CompilerBridge"),
generateServiceProviderResources("xsbti.compile.ConsoleInterface1" -> "scala.tools.xsbt.ConsoleBridge"),
generateServiceProviderResources("xsbti.compile.ScaladocInterface2" -> "scala.tools.xsbt.ScaladocBridge"),
generateServiceProviderResources("xsbti.InteractiveConsoleFactory" -> "scala.tools.xsbt.InteractiveConsoleBridgeFactory"),
Compile / managedResourceDirectories := Seq((Compile / resourceManaged).value),
pomDependencyExclusions ++= List((organization.value, "scala-repl-frontend"), (organization.value, "scala-compiler-doc")),
fixPom(
"/project/name" -> <name>Scala 2 sbt Bridge</name>,
"/project/description" -> <description>sbt compiler bridge for Scala 2</description>,
"/project/packaging" -> <packaging>jar</packaging>
),
headerLicense := Some(HeaderLicense.Custom(
s"""Zinc - The incremental compiler for Scala.
|Copyright Scala Center, Lightbend, and Mark Harrah
|
|Scala (${(ThisBuild/homepage).value.get})
|Copyright EPFL and Lightbend, Inc.
|
|Licensed under Apache License 2.0
|(http://www.apache.org/licenses/LICENSE-2.0).
|
|See the NOTICE file distributed with this work for
|additional information regarding copyright ownership.
|""".stripMargin)),
)
.dependsOn(compiler % Provided, replFrontend, scaladoc)

lazy val scalap = configureAsSubproject(project)
.settings(fatalWarningsSettings)
.settings(
Expand Down Expand Up @@ -727,7 +802,7 @@ val addOpensForTesting = "-XX:+IgnoreUnrecognizedVMOptions" +: "--add-exports=jd
Seq("java.util.concurrent.atomic", "java.lang", "java.lang.reflect", "java.net").map(p => s"--add-opens=java.base/$p=ALL-UNNAMED")

lazy val junit = project.in(file("test") / "junit")
.dependsOn(testkit, compiler, replFrontend, scaladoc)
.dependsOn(testkit, compiler, replFrontend, scaladoc, sbtBridge)
.settings(commonSettings)
.settings(disableDocs)
.settings(fatalWarningsSettings)
Expand All @@ -745,7 +820,7 @@ lazy val junit = project.in(file("test") / "junit")
"-Ypatmat-exhaust-depth", "40", // despite not caring about patmat exhaustiveness, we still get warnings for this
),
Compile / javacOptions ++= Seq("-Xlint"),
libraryDependencies ++= Seq(junitInterfaceDep, jolDep, diffUtilsDep),
libraryDependencies ++= Seq(junitInterfaceDep, jolDep, diffUtilsDep, compilerInterfaceDep),
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "-s"),
Compile / unmanagedSourceDirectories := Nil,
Test / unmanagedSourceDirectories := List(baseDirectory.value),
Expand Down Expand Up @@ -1048,7 +1123,7 @@ lazy val root: Project = (project in file("."))

setIncOptions
)
.aggregate(library, reflect, compiler, interactive, repl, replFrontend,
.aggregate(library, reflect, compiler, interactive, repl, replFrontend, sbtBridge,
scaladoc, scalap, testkit, partest, junit, scalacheck, tasty, tastytest, scalaDist).settings(
Compile / sources := Seq.empty,
onLoadMessage := s"""|*** Welcome to the sbt build definition for Scala! ***
Expand Down
222 changes: 222 additions & 0 deletions src/sbt-bridge/scala/tools/xsbt/API.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright Scala Center, Lightbend, and Mark Harrah
*
* Scala (https://www.scala-lang.org)
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.tools
package xsbt

import scala.tools.nsc.Phase
import scala.tools.nsc.symtab.Flags
import xsbti.api._
import xsbti.VirtualFile

object API {
val name = "xsbt-api"
}

final class API(val global: CallbackGlobal) extends Compat with GlobalHelpers with ClassName {
import global._

import scala.collection.mutable
private val nonLocalClassSymbolsInCurrentUnits = new mutable.HashSet[Symbol]()

def newPhase(prev: Phase) = new ApiPhase(prev)
class ApiPhase(prev: Phase) extends GlobalPhase(prev) {
override def description = "Extracts the public API from source files."
def name = API.name
override def run(): Unit = {
val start = System.currentTimeMillis
super.run()

// After processing all units, register generated classes
registerGeneratedClasses(nonLocalClassSymbolsInCurrentUnits.iterator)
nonLocalClassSymbolsInCurrentUnits.clear()

callback.apiPhaseCompleted()
val stop = System.currentTimeMillis
debuglog("API phase took : " + ((stop - start) / 1000.0) + " s")
}

// TODO In 2.13, shouldSkipThisPhaseForJava should be overridden instead of cancelled
// override def shouldSkipThisPhaseForJava = !global.callback.isPickleJava
override def cancelled(unit: CompilationUnit) = {
if (Thread.interrupted()) reporter.cancelled = true
reporter.cancelled || unit.isJava && !global.callback.isPickleJava
}

def apply(unit: global.CompilationUnit): Unit = processUnit(unit)

private def processUnit(unit: CompilationUnit): Unit = {
if (!unit.isJava || global.callback.isPickleJava) {
processScalaUnit(unit)
}
}

private def processScalaUnit(unit: CompilationUnit): Unit = {
val sourceFile: VirtualFile = unit.source.file match { case AbstractZincFile(vf) => vf }
debuglog("Traversing " + sourceFile)
callback.startSource(sourceFile)
val extractApi = new ExtractAPI[global.type](global, sourceFile)
val traverser = new TopLevelHandler(extractApi)
traverser.apply(unit.body)

val extractUsedNames = new ExtractUsedNames[global.type](global)
extractUsedNames.extractAndReport(unit)

val classApis = traverser.allNonLocalClasses
val mainClasses = traverser.mainClasses

// Use of iterators make this code easier to profile

val classApisIt = classApis.iterator
while (classApisIt.hasNext) {
callback.api(sourceFile, classApisIt.next())
}

val mainClassesIt = mainClasses.iterator
while (mainClassesIt.hasNext) {
callback.mainClass(sourceFile, mainClassesIt.next())
}

extractApi.allExtractedNonLocalSymbols.foreach { cs =>
// Only add the class symbols defined in this compilation unit
if (cs.sourceFile != null) nonLocalClassSymbolsInCurrentUnits.+=(cs)
}
}
}

private case class FlattenedNames(binaryName: String, className: String)

/**
* Registers only non-local generated classes in the callback by extracting
* information about its names and using the names to generate class file paths.
*
* Mimics the previous logic that was present in `Analyzer`, despite the fact
* that now we construct the names that the compiler will give to every non-local
* class independently of genbcode.
*
* Why do we do this? The motivation is that we want to run the incremental algorithm
* independently of the compiler pipeline. This independence enables us to:
*
* 1. Offload the incremental compiler logic out of the primary pipeline and
* run the incremental phases concurrently.
* 2. Know before the compilation is completed whether another compilation will or
* will not be required. This is important to make incremental compilation work
* with pipelining and enables further optimizations; for example, we can start
* subsequent incremental compilations before (!) the initial compilation is done.
* This can buy us ~30-40% faster incremental compiler iterations.
*
* This method only takes care of non-local classes because local classes have no
* relevance in the correctness of the algorithm and can be registered after genbcode.
* Local classes are only used to construct the relations of products and to produce
* the list of generated files + stamps, but names referring to local classes **never**
* show up in the name hashes of classes' APIs, hence never considered for name hashing.
*
* As local class files are owned by other classes that change whenever they change,
* we could most likely live without adding their class files to the products relation
* and registering their stamps. However, to be on the safe side, we will continue to
* register the local products in `Analyzer`.
*
* @param allClassSymbols The class symbols found in all the compilation units.
*/
def registerGeneratedClasses(classSymbols: Iterator[Symbol]): Unit = {
classSymbols.foreach { symbol =>
val sourceFile = symbol.sourceFile
val sourceVF0 =
if (sourceFile == null) symbol.enclosingTopLevelClass.sourceFile
else sourceFile
val sourceVF: Option[VirtualFile] = sourceVF0 match {
case AbstractZincFile(vf) => Some(vf)
// This could be scala.reflect.io.FileZipArchive$LeakyEntry
case _ => None
}

def registerProductNames(names: FlattenedNames): Unit = {
// Guard against a local class in case it surreptitiously leaks here
if (!symbol.isLocalClass) {
val pathToClassFile = s"${names.binaryName}.class"
val classFile = {
JarUtils.outputJar match {
case Some(outputJar) =>
new java.io.File(JarUtils.classNameInJar(outputJar, pathToClassFile))
case None =>
val outputDir = global.settings.outputDirs.outputDirFor(sourceFile).file
new java.io.File(outputDir, pathToClassFile)
}
}
val zincClassName = names.className
val srcClassName = classNameAsString(symbol)
sourceVF foreach { source =>
callback.generatedNonLocalClass(
source,
classFile.toPath,
zincClassName,
srcClassName
)
}
} else ()
}

val names = FlattenedNames(
fullName(symbol, java.io.File.separatorChar, symbol.moduleSuffix, true),
fullName(symbol, '.', symbol.moduleSuffix, false)
)

registerProductNames(names)

// Register the names of top-level module symbols that emit two class files
val isTopLevelUniqueModule =
symbol.owner.isPackageClass && symbol.isModuleClass && symbol.companionClass == NoSymbol
if (isTopLevelUniqueModule || symbol.isPackageObject) {
val names = FlattenedNames(
fullName(symbol, java.io.File.separatorChar, "", true),
fullName(symbol, '.', "", false)
)
registerProductNames(names)
}
}
}

private final class TopLevelHandler(extractApi: ExtractAPI[global.type])
extends TopLevelTraverser {
def allNonLocalClasses: Set[ClassLike] = {
extractApi.allExtractedNonLocalClasses
}

def mainClasses: Set[String] = extractApi.mainClasses

def `class`(c: Symbol): Unit = {
extractApi.extractAllClassesOf(c.owner, c)
}
}

private abstract class TopLevelTraverser extends Traverser {
def `class`(s: Symbol): Unit
override def traverse(tree: Tree): Unit = {
tree match {
case (_: ClassDef | _: ModuleDef) if isTopLevel(tree.symbol) => `class`(tree.symbol)
case _: PackageDef =>
super.traverse(tree)
case _ =>
}
}
def isTopLevel(sym: Symbol): Boolean = {
!ignoredSymbol(sym) &&
sym.isStatic &&
!sym.isImplClass &&
(!sym.hasFlag(Flags.JAVA) || global.callback.isPickleJava) &&
!sym.isNestedClass
}
}

}
Loading