Skip to content

Commit 1531a86

Browse files
authored
Merge pull request scala-js#3790 from gzm0/linker-interface
Split linker interface into separate artifact
2 parents 5506926 + 92b9610 commit 1531a86

File tree

75 files changed

+809
-625
lines changed

Some content is hidden

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

75 files changed

+809
-625
lines changed

Jenkinsfile

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -308,20 +308,22 @@ def Tasks = [
308308
'set scalaJSStage in testSuite := FastOptStage' \
309309
++$scala testSuite/bootstrap:test &&
310310
sbt ++$scala irJS/mimaReportBinaryIssues \
311-
loggingJS/mimaReportBinaryIssues linkerJS/mimaReportBinaryIssues
311+
loggingJS/mimaReportBinaryIssues \
312+
linkerInterfaceJS/mimaReportBinaryIssues linkerJS/mimaReportBinaryIssues
312313
''',
313314

314315
"tools": '''
315316
setJavaVersion $java
316317
npm install &&
317-
sbt ++$scala ir/test logging/compile linker/compile \
318-
jsEnvs/test nodeJSEnv/test testAdapter/test \
319-
ir/mimaReportBinaryIssues \
320-
logging/mimaReportBinaryIssues linker/mimaReportBinaryIssues \
318+
sbt ++$scala ir/test logging/compile linkerInterface/compile \
319+
linker/compile jsEnvs/test nodeJSEnv/test testAdapter/test \
320+
ir/mimaReportBinaryIssues logging/mimaReportBinaryIssues \
321+
linkerInterface/mimaReportBinaryIssues linker/mimaReportBinaryIssues \
321322
jsEnvs/mimaReportBinaryIssues jsEnvsTestKit/mimaReportBinaryIssues \
322323
nodeJSEnv/mimaReportBinaryIssues \
323324
testAdapter/mimaReportBinaryIssues &&
324325
sbt ++$scala ir/compile:doc logging/compile:doc \
326+
linkerInterface/compile:doc \
325327
linker/compile:doc jsEnvs/compile:doc \
326328
jsEnvsTestKit/compile:doc nodeJSEnv/compile:doc \
327329
testAdapter/compile:doc
@@ -330,11 +332,11 @@ def Tasks = [
330332
"tools-sbtplugin": '''
331333
setJavaVersion $java
332334
npm install &&
333-
sbt ++$scala ir/test logging/compile linker/compile \
334-
jsEnvs/test nodeJSEnv/test testAdapter/test \
335+
sbt ++$scala ir/test logging/compile linkerInterface/compile \
336+
linker/compile jsEnvs/test nodeJSEnv/test testAdapter/test \
335337
sbtPlugin/package \
336-
ir/mimaReportBinaryIssues \
337-
logging/mimaReportBinaryIssues linker/mimaReportBinaryIssues \
338+
ir/mimaReportBinaryIssues logging/mimaReportBinaryIssues \
339+
linkerInterface/mimaReportBinaryIssues linker/mimaReportBinaryIssues \
338340
jsEnvs/mimaReportBinaryIssues jsEnvsTestKit/mimaReportBinaryIssues \
339341
nodeJSEnv/mimaReportBinaryIssues \
340342
testAdapter/mimaReportBinaryIssues \
@@ -343,6 +345,8 @@ def Tasks = [
343345
ir/scalastyle compiler/scalastyle \
344346
compiler/test:scalastyle \
345347
logging/scalastyle logging/test:scalastyle \
348+
linkerInterface/scalastyle \
349+
linkerInterface/scalastyle \
346350
linker/scalastyle linker/test:scalastyle \
347351
jsEnvs/scalastyle jsEnvsTestKit/scalastyle nodeJSEnv/scalastyle \
348352
jsEnvs/test:scalastyle nodeJSEnv/test:scalastyle testAdapter/scalastyle \
@@ -356,6 +360,7 @@ def Tasks = [
356360
jUnitTestOutputsJVM/scalastyle jUnitTestOutputsJVM/test:scalastyle \
357361
jUnitTestOutputsJS/scalastyle jUnitTestOutputsJS/test:scalastyle &&
358362
sbt ++$scala ir/compile:doc logging/compile:doc \
363+
linkerInterface/compile:doc \
359364
linker/compile:doc jsEnvs/compile:doc \
360365
jsEnvsTestKit/compile:doc nodeJSEnv/compile:doc \
361366
testAdapter/compile:doc \
@@ -378,6 +383,7 @@ def Tasks = [
378383
jUnitPlugin/publishLocal jUnitRuntime/publishLocal &&
379384
sbt ++$toolsscala \
380385
ir/publishLocal logging/publishLocal \
386+
linkerInterface/publishLocal \
381387
linker/publishLocal jsEnvs/publishLocal \
382388
nodeJSEnv/publishLocal testAdapter/publishLocal \
383389
sbtPlugin/publishLocal &&

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ val irJS = Build.irProjectJS
66
val compiler = Build.compiler
77
val logging = Build.logging
88
val loggingJS = Build.loggingJS
9+
val linkerInterface = Build.linkerInterface
10+
val linkerInterfaceJS = Build.linkerInterfaceJS
911
val linker = Build.linker
1012
val linkerJS = Build.linkerJS
1113
val jsEnvs = Build.jsEnvs

linker/js/src/main/scala/org/scalajs/linker/StandardLinkerPlatformExtensions.scala renamed to linker-interface/js/src/main/scala/org/scalajs/linker/interface/StandardConfigPlatformExtensions.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
* additional information regarding copyright ownership.
1111
*/
1212

13-
package org.scalajs.linker
13+
package org.scalajs.linker.interface
1414

15-
object StandardLinkerPlatformExtensions {
16-
import StandardLinker.Config
15+
object StandardConfigPlatformExtensions {
1716

18-
final class ConfigExt private[linker] (private val self: Config)
17+
final class ConfigExt private[linker] (private val self: StandardConfig)
1918
extends AnyVal {
2019

2120
/** Whether to actually use the Google Closure Compiler pass.

linker/jvm/src/main/scala/org/scalajs/linker/StandardLinkerPlatformExtensions.scala renamed to linker-interface/jvm/src/main/scala/org/scalajs/linker/interface/StandardConfigPlatformExtensions.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@
1010
* additional information regarding copyright ownership.
1111
*/
1212

13-
package org.scalajs.linker
13+
package org.scalajs.linker.interface
1414

15-
object StandardLinkerPlatformExtensions {
16-
import StandardLinker.Config
15+
object StandardConfigPlatformExtensions {
1716

18-
final class ConfigExt private[linker] (val __private_self: Config)
17+
final class ConfigExt private[linker] (private val self: StandardConfig)
1918
extends AnyVal {
2019

21-
@inline private def self: Config = __private_self
22-
2320
/** Whether to actually use the Google Closure Compiler pass. */
2421
def closureCompiler: Boolean = self.closureCompilerIfAvailable
2522

26-
def withClosureCompiler(closureCompiler: Boolean): Config =
23+
def withClosureCompiler(closureCompiler: Boolean): StandardConfig =
2724
self.withClosureCompilerIfAvailable(closureCompiler)
2825
}
2926
}

linker/shared/src/main/scala/org/scalajs/linker/CheckedBehavior.scala renamed to linker-interface/shared/src/main/scala/org/scalajs/linker/interface/CheckedBehavior.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* additional information regarding copyright ownership.
1111
*/
1212

13-
package org.scalajs.linker
13+
package org.scalajs.linker.interface
1414

1515
sealed abstract class CheckedBehavior {
1616
import CheckedBehavior._
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Scala.js (https://www.scala-js.org/)
3+
*
4+
* Copyright EPFL.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (https://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package org.scalajs.linker.interface
14+
15+
/** A box around a [[Linker]] to support clearing.
16+
*
17+
* Calling `clear()` completely resets the state of this `ClearableLinker`, so
18+
* that it can be used again without being affected by previous calls to
19+
* `link`, even of those would have corrupted the internal state.
20+
*
21+
* In addition to the contract of [[Linker]], if [[Linker.link]] throws an
22+
* exception, the `ClearableLinker` is automatically `clear()`'ed.
23+
*
24+
* Implementations are allowed to automatically `clear()` in other cases, but
25+
* never while a linking is in progress.
26+
*
27+
* Unless otherwise specified, instances of this trait are not thread-safe.
28+
*/
29+
trait ClearableLinker extends Linker {
30+
/** Completely resets the state of this `ClearableLinker`.
31+
*
32+
* After calling this method, this `ClearableLinker`, it can be used again
33+
* without being affected by previous calls to `link`, even of those would
34+
* have corrupted the internal state.
35+
*/
36+
def clear(): Unit
37+
}

linker/shared/src/main/scala/org/scalajs/linker/ESFeatures.scala renamed to linker-interface/shared/src/main/scala/org/scalajs/linker/interface/ESFeatures.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* additional information regarding copyright ownership.
1111
*/
1212

13-
package org.scalajs.linker
13+
package org.scalajs.linker.interface
1414

1515
/** ECMAScript features to use when linking to JavaScript.
1616
*

linker/shared/src/main/scala/org/scalajs/linker/IRContainer.scala renamed to linker-interface/shared/src/main/scala/org/scalajs/linker/interface/IRContainer.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
* additional information regarding copyright ownership.
1111
*/
1212

13-
package org.scalajs.linker
13+
package org.scalajs.linker.interface
1414

1515
import scala.concurrent._
1616

17-
import org.scalajs.linker.standard._
17+
import org.scalajs.linker.interface.unstable.{IRContainerImpl, IRFileImpl}
1818

19-
abstract class IRContainer private[linker] () {
20-
private[linker] def impl: IRContainerImpl
19+
abstract class IRContainer private[interface] () {
20+
private[interface] def impl: IRContainerImpl
2121
}
2222

23-
object IRContainer extends IRContainerPlatformExtensions {
23+
object IRContainer {
2424
def fromIRFile(irFile: IRFile): IRContainer = {
2525
val f = IRFileImpl.fromIRFile(irFile)
2626
new IRContainerImpl(f.path, f.version) {

linker/shared/src/main/scala/org/scalajs/linker/IRFile.scala renamed to linker-interface/shared/src/main/scala/org/scalajs/linker/interface/IRFile.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
* additional information regarding copyright ownership.
1111
*/
1212

13-
package org.scalajs.linker
13+
package org.scalajs.linker.interface
1414

15-
import org.scalajs.linker.standard.IRFileImpl
15+
import org.scalajs.linker.interface.unstable.IRFileImpl
1616

17-
abstract class IRFile private[linker] () {
18-
private[linker] def impl: IRFileImpl
17+
abstract class IRFile private[interface] () {
18+
private[interface] def impl: IRFileImpl
1919
}
20-
21-
object IRFile extends IRFilePlatformExtensions

linker/shared/src/main/scala/org/scalajs/linker/IRFileCache.scala renamed to linker-interface/shared/src/main/scala/org/scalajs/linker/interface/IRFileCache.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@
1010
* additional information regarding copyright ownership.
1111
*/
1212

13-
package org.scalajs.linker
13+
package org.scalajs.linker.interface
1414

1515
import scala.concurrent._
1616

17-
import org.scalajs.linker.standard.StandardIRFileCache
18-
1917
/** Centralized Scala.js IR cache.
2018
*
2119
* Caches all Scala.js IR used in a given JVM. It supports creating of multiple
2220
* sub-caches ([[IRFileCache.Cache]]) that track individual file sets.
2321
* The global cache is fully thread-safe. However, the sub-caches are not.
2422
*/
25-
abstract class IRFileCache private[linker] () {
23+
abstract class IRFileCache private[interface] () {
2624
/** Create a new sub-cache.
2725
*
2826
* Users should call [[IRFileCache.Cache.free]] once they are done to allow
@@ -38,10 +36,8 @@ abstract class IRFileCache private[linker] () {
3836
}
3937

4038
object IRFileCache {
41-
def apply(): IRFileCache = new StandardIRFileCache()
42-
4339
/** A cache to use for individual runs. Not threadsafe */
44-
abstract class Cache private[linker] () {
40+
abstract class Cache private[interface] () {
4541
/** Extract and cache IR.
4642
*
4743
* The returned value is valid until the next invocation of [[cached]] or
@@ -64,7 +60,7 @@ object IRFileCache {
6460
}
6561

6662
/** Statistics about an individual run. */
67-
abstract class Stats private[linker] {
63+
abstract class Stats private[interface] {
6864
/** Descriptive line to display in logs */
6965
def logLine: String
7066
}

linker/shared/src/main/scala/org/scalajs/linker/Linker.scala renamed to linker-interface/shared/src/main/scala/org/scalajs/linker/interface/Linker.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* additional information regarding copyright ownership.
1111
*/
1212

13-
package org.scalajs.linker
13+
package org.scalajs.linker.interface
1414

1515
import scala.concurrent._
1616

@@ -22,7 +22,7 @@ import org.scalajs.logging.Logger
2222
* module initializers, link them together, and write the output to a writable
2323
* .js file.
2424
*/
25-
abstract class Linker private[linker] () {
25+
abstract class Linker private[interface] () {
2626
def link(irFiles: Seq[IRFile],
2727
moduleInitializers: Seq[ModuleInitializer],
2828
output: LinkerOutput, logger: Logger)(
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Scala.js (https://www.scala-js.org/)
3+
*
4+
* Copyright EPFL.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (https://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package org.scalajs.linker.interface
14+
15+
import scala.concurrent._
16+
17+
import java.io.ByteArrayOutputStream
18+
import java.nio.ByteBuffer
19+
20+
import java.net.URI
21+
22+
import org.scalajs.linker.interface.unstable.OutputFileImpl
23+
24+
/** Output specification for a linker run.
25+
*
26+
* @param jsFile The JavaScript file a [[Linker]] writes to.
27+
*
28+
* @param sourceMap The sourceMap file the linker writes to. A [[Linker]] may
29+
* ignore this file. N.b. the standard linker will ignore it if
30+
* [[StandardConfig.sourceMap]] is false. Further, a [[Linker]] must not
31+
* fail if this is not set, but rather not write a source map (even if it
32+
* is configured to write a source map).
33+
*
34+
* @param sourceMapURI URI to reach the source map from the JavaScript file.
35+
* This is typically a relative URI but is not required. A [[Linker]]
36+
* should ignore this, if [[sourceMap]] is not set or source map production
37+
* is disabled.
38+
*
39+
* @param jsFileURI URI to reach the JavaScript file from the source map. This
40+
* is typically a relative URI but is not required. A [[Linker]] may use
41+
* this even if [[sourceMap]] is not set, but it is typically meaningless.
42+
*/
43+
final class LinkerOutput private (
44+
val jsFile: LinkerOutput.File,
45+
val sourceMap: Option[LinkerOutput.File],
46+
val sourceMapURI: Option[URI],
47+
val jsFileURI: Option[URI]
48+
) {
49+
private def this(jsFile: LinkerOutput.File) =
50+
this(jsFile, None, None, None)
51+
52+
def withSourceMap(sourceMap: LinkerOutput.File): LinkerOutput =
53+
copy(sourceMap = Some(sourceMap))
54+
55+
def withSourceMapURI(sourceMapURI: URI): LinkerOutput =
56+
copy(sourceMapURI = Some(sourceMapURI))
57+
58+
def withJSFileURI(jsFileURI: URI): LinkerOutput =
59+
copy(jsFileURI = Some(jsFileURI))
60+
61+
private def copy(
62+
jsFile: LinkerOutput.File = jsFile,
63+
sourceMap: Option[LinkerOutput.File] = sourceMap,
64+
sourceMapURI: Option[URI] = sourceMapURI,
65+
jsFileURI: Option[URI] = jsFileURI): LinkerOutput = {
66+
new LinkerOutput(jsFile, sourceMap, sourceMapURI, jsFileURI)
67+
}
68+
}
69+
70+
object LinkerOutput {
71+
def apply(jsFile: LinkerOutput.File): LinkerOutput = new LinkerOutput(jsFile)
72+
73+
abstract class File private[interface] () {
74+
private[interface] def impl: OutputFileImpl
75+
}
76+
}

linker/shared/src/main/scala/org/scalajs/linker/LinkingException.scala renamed to linker-interface/shared/src/main/scala/org/scalajs/linker/interface/LinkingException.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* additional information regarding copyright ownership.
1111
*/
1212

13-
package org.scalajs.linker
13+
package org.scalajs.linker.interface
1414

1515
/** Thrown by the linker when linking cannot be performed. */
1616
class LinkingException(message: String, cause: Throwable)

0 commit comments

Comments
 (0)