@@ -28,6 +28,35 @@ import sbtbuildinfo.BuildInfoPlugin.autoImport._
28
28
29
29
import scala .util .Properties .isJavaAtLeast
30
30
31
+ object MyScalaJSPlugin extends AutoPlugin {
32
+ import Build ._
33
+
34
+ override def requires : Plugins = ScalaJSPlugin
35
+
36
+ override def projectSettings : Seq [Setting [_]] = Def .settings(
37
+ commonBootstrappedSettings,
38
+
39
+ /* Remove the Scala.js compiler plugin for scalac, and enable the
40
+ * Scala.js back-end of dotty instead.
41
+ */
42
+ libraryDependencies := {
43
+ val deps = libraryDependencies.value
44
+ deps.filterNot(_.name.startsWith(" scalajs-compiler" )).map(_.withDottyCompat(scalaVersion.value))
45
+ },
46
+ scalacOptions += " -scalajs" ,
47
+
48
+ // Replace the JVM JUnit dependency by the Scala.js one
49
+ libraryDependencies ~= {
50
+ _.filter(! _.name.startsWith(" junit-interface" ))
51
+ },
52
+ libraryDependencies +=
53
+ " org.scala-js" % " scalajs-junit-test-runtime_2.12" % scalaJSVersion % " test" ,
54
+
55
+ // Typecheck the Scala.js IR found on the classpath
56
+ scalaJSLinkerConfig ~= (_.withCheckIR(true )),
57
+ )
58
+ }
59
+
31
60
object Build {
32
61
val scalacVersion = " 2.12.8"
33
62
val referenceVersion = " 0.14.0-RC1"
@@ -101,6 +130,8 @@ object Build {
101
130
val ideTestsCompilerArguments = taskKey[Seq [String ]](" Compiler arguments to use in IDE tests" )
102
131
val ideTestsDependencyClasspath = taskKey[Seq [File ]](" Dependency classpath to use in IDE tests" )
103
132
133
+ val fetchScalaJSSource = taskKey[File ](" Fetch the sources of Scala.js" )
134
+
104
135
lazy val SourceDeps = config(" sourcedeps" )
105
136
106
137
// Settings shared by the build (scoped in ThisBuild). Used in build.sbt
@@ -714,6 +745,22 @@ object Build {
714
745
case Bootstrapped => `dotty-library-bootstrapped`
715
746
}
716
747
748
+ lazy val `dotty-library-bootstrappedJS` : Project = project.in(file(" library-js" )).
749
+ asDottyLibrary(Bootstrapped ).
750
+ enablePlugins(MyScalaJSPlugin ).
751
+ settings(
752
+ // TODO Compile more (enventually all) of the library
753
+ /* unmanagedSourceDirectories in Compile :=
754
+ (unmanagedSourceDirectories in (`dotty-library-bootstrapped`, Compile)).value,*/
755
+ sources in Compile := {
756
+ val baseDir = (baseDirectory in (`dotty-library-bootstrapped`, Compile )).value
757
+ Seq (
758
+ baseDir / " src/scala/forceInline.scala" ,
759
+ baseDir / " src-3.x/dotty/DottyPredef.scala" ,
760
+ )
761
+ },
762
+ )
763
+
717
764
lazy val `dotty-sbt-bridge` = project.in(file(" sbt-bridge/src" )).
718
765
// We cannot depend on any bootstrapped project to compile the bridge, since the
719
766
// bridge is needed to compile these projects.
@@ -819,36 +866,95 @@ object Build {
819
866
* useful, as that would not provide the linker and JS runners.
820
867
*/
821
868
lazy val sjsSandbox = project.in(file(" sandbox/scalajs" )).
822
- enablePlugins(ScalaJSPlugin ).
823
- dependsOn(dottyLibrary(Bootstrapped )).
824
- settings(commonBootstrappedSettings).
869
+ enablePlugins(MyScalaJSPlugin ).
870
+ dependsOn(`dotty-library-bootstrappedJS`).
825
871
settings(
826
- /* Remove the Scala.js compiler plugin for scalac, and enable the
827
- * Scala.js back-end of dotty instead.
828
- */
829
- libraryDependencies := {
830
- val deps = libraryDependencies.value
831
- deps.filterNot(_.name.startsWith(" scalajs-compiler" )).map(_.withDottyCompat(scalaVersion.value))
832
- },
833
- scalacOptions += " -scalajs" ,
872
+ scalaJSUseMainModuleInitializer := true ,
873
+ )
834
874
835
- // Replace the JVM JUnit dependency by the Scala.js one
836
- libraryDependencies ~= {
837
- _.filter(! _.name.startsWith(" junit-interface" ))
875
+ lazy val sjsJUnitTests = project.in(file(" tests/sjs-junit" )).
876
+ enablePlugins(MyScalaJSPlugin ).
877
+ dependsOn(`dotty-library-bootstrappedJS`).
878
+ settings(
879
+ scalacOptions --= Seq (" -Xfatal-warnings" , " -deprecation" ),
880
+
881
+ sourceDirectory in fetchScalaJSSource := target.value / s " scala-js-src- $scalaJSVersion" ,
882
+
883
+ fetchScalaJSSource := {
884
+ import org .eclipse .jgit .api ._
885
+
886
+ val s = streams.value
887
+ val ver = scalaJSVersion
888
+ val trgDir = (sourceDirectory in fetchScalaJSSource).value
889
+
890
+ if (! trgDir.exists) {
891
+ s.log.info(s " Fetching Scala.js source version $ver" )
892
+ IO .createDirectory(trgDir)
893
+ new CloneCommand ()
894
+ .setDirectory(trgDir)
895
+ .setURI(" https://github.com/scala-js/scala-js.git" )
896
+ .call()
897
+ }
898
+
899
+ // Checkout proper ref. We do this anyway so we fail if something is wrong
900
+ val git = Git .open(trgDir)
901
+ s.log.info(s " Checking out Scala.js source version $ver" )
902
+ git.checkout().setName(s " v $ver" ).call()
903
+
904
+ trgDir
838
905
},
906
+
907
+ // We need JUnit in the Compile configuration
839
908
libraryDependencies +=
840
- " org.scala-js" % " scalajs-junit-test-runtime_2.12" % scalaJSVersion % " test" ,
909
+ " org.scala-js" % " scalajs-junit-test-runtime_2.12" % scalaJSVersion,
910
+
911
+ sourceGenerators in Compile += Def .task {
912
+ import org .scalajs .linker .CheckedBehavior
841
913
842
- // The main class cannot be found automatically due to the empty inc.Analysis
843
- mainClass in Compile := Some (" hello.HelloWorld" ),
914
+ val stage = scalaJSStage.value
844
915
845
- scalaJSUseMainModuleInitializer := true ,
916
+ val linkerConfig = stage match {
917
+ case FastOptStage => (scalaJSLinkerConfig in (Compile , fastOptJS)).value
918
+ case FullOptStage => (scalaJSLinkerConfig in (Compile , fullOptJS)).value
919
+ }
846
920
847
- /* Debug-friendly Scala.js optimizer options.
848
- * In particular, typecheck the Scala.js IR found on the classpath.
849
- */
850
- scalaJSLinkerConfig ~= {
851
- _.withCheckIR(true ).withParallel(false )
921
+ val moduleKind = linkerConfig.moduleKind
922
+ val sems = linkerConfig.semantics
923
+
924
+ ConstantHolderGenerator .generate(
925
+ (sourceManaged in Compile ).value,
926
+ " org.scalajs.testsuite.utils.BuildInfo" ,
927
+ " scalaVersion" -> scalaVersion.value,
928
+ " hasSourceMaps" -> false , // MyScalaJSPlugin.wantSourceMaps.value,
929
+ " isNoModule" -> (moduleKind == ModuleKind .NoModule ),
930
+ " isESModule" -> (moduleKind == ModuleKind .ESModule ),
931
+ " isCommonJSModule" -> (moduleKind == ModuleKind .CommonJSModule ),
932
+ " isFullOpt" -> (stage == FullOptStage ),
933
+ " compliantAsInstanceOfs" -> (sems.asInstanceOfs == CheckedBehavior .Compliant ),
934
+ " compliantArrayIndexOutOfBounds" -> (sems.arrayIndexOutOfBounds == CheckedBehavior .Compliant ),
935
+ " compliantModuleInit" -> (sems.moduleInit == CheckedBehavior .Compliant ),
936
+ " strictFloats" -> sems.strictFloats,
937
+ " productionMode" -> sems.productionMode,
938
+ " es2015" -> linkerConfig.esFeatures.useECMAScript2015,
939
+ )
940
+ }.taskValue,
941
+
942
+ managedSources in Compile ++= {
943
+ val dir = fetchScalaJSSource.value / " test-suite/js/src/main/scala"
944
+ val filter = (
945
+ (" *.scala" : FileFilter )
946
+ -- " Typechecking*.scala"
947
+ -- " NonNativeTypeTestSeparateRun.scala"
948
+ )
949
+ (dir ** filter).get
950
+ },
951
+
952
+ managedSources in Test ++= {
953
+ val dir = fetchScalaJSSource.value / " test-suite"
954
+ (
955
+ (dir / " shared/src/test/scala/org/scalajs/testsuite/compiler" ** " IntTest.scala" ).get
956
+ ++ (dir / " shared/src/test/scala/org/scalajs/testsuite/utils" ** " *.scala" ).get
957
+ )
852
958
}
853
959
)
854
960
0 commit comments