@@ -39,6 +39,9 @@ import sbtassembly.AssemblyPlugin.autoImport._
39
39
40
40
object Build extends sbt.Build {
41
41
42
+ val isGeneratingEclipse =
43
+ Properties .envOrElse(" GENERATING_ECLIPSE" , " false" ).toBoolean
44
+
42
45
val fetchScalaSource = taskKey[File ](
43
46
" Fetches the scala source for the current scala version" )
44
47
val shouldPartest = settingKey[Boolean ](
@@ -215,6 +218,13 @@ object Build extends sbt.Build {
215
218
}
216
219
) ++ mimaDefaultSettings
217
220
221
+ val noClassFilesSettings : Setting [_] = (
222
+ scalacOptions in (Compile , compile) ++= {
223
+ if (isGeneratingEclipse) Seq ()
224
+ else Seq (" -Yskip:cleanup,icode,jvm" )
225
+ }
226
+ )
227
+
218
228
val publishSettings = Seq (
219
229
publishMavenStyle := true ,
220
230
publishTo := {
@@ -312,7 +322,8 @@ object Build extends sbt.Build {
312
322
313
323
// Link source maps
314
324
scalacOptions ++= {
315
- if (scalaJSIsSnapshotVersion) Seq ()
325
+ if (isGeneratingEclipse) Seq ()
326
+ else if (scalaJSIsSnapshotVersion) Seq ()
316
327
else Seq (
317
328
// Link source maps to github sources
318
329
" -P:scalajs:mapSourceURI:" + root.base.toURI +
@@ -322,13 +333,37 @@ object Build extends sbt.Build {
322
333
}
323
334
)
324
335
325
- /** Depend library as if (exportJars in library) was set to false */
326
- val compileWithLibrarySetting = {
327
- internalDependencyClasspath in Compile ++= {
328
- val prods = (products in (library, Compile )).value
329
- val analysis = (compile in (library, Compile )).value
336
+ implicit class ProjectOps (val project : Project ) extends AnyVal {
337
+ /** Uses the Scala.js compiler plugin. */
338
+ def withScalaJSCompiler : Project =
339
+ if (isGeneratingEclipse) project
340
+ else project.dependsOn(compiler % " plugin" )
341
+
342
+ /** Depends on library as if (exportJars in library) was set to false. */
343
+ def dependsOnLibraryNoJar : Project = {
344
+ if (isGeneratingEclipse) {
345
+ project.dependsOn(library)
346
+ } else {
347
+ project.settings(
348
+ internalDependencyClasspath in Compile ++= {
349
+ val prods = (products in (library, Compile )).value
350
+ val analysis = (compile in (library, Compile )).value
351
+ prods.map(p => Classpaths .analyzed(p, analysis))
352
+ }
353
+ )
354
+ }
355
+ }
330
356
331
- prods.map(p => Classpaths .analyzed(p, analysis))
357
+ /** Depends on the sources of another project. */
358
+ def dependsOnSource (dependency : Project ): Project = {
359
+ if (isGeneratingEclipse) {
360
+ project.dependsOn(dependency)
361
+ } else {
362
+ project.settings(
363
+ unmanagedSourceDirectories in Compile +=
364
+ (scalaSource in (dependency, Compile )).value
365
+ )
366
+ }
332
367
}
333
368
}
334
369
@@ -419,16 +454,14 @@ object Build extends sbt.Build {
419
454
unmanagedSourceDirectories in Compile +=
420
455
(scalaSource in Compile in irProject).value
421
456
)
422
- ).dependsOn(compiler % " plugin " , javalibEx)
457
+ ).withScalaJSCompiler. dependsOn(javalibEx)
423
458
424
459
lazy val compiler : Project = Project (
425
460
id = " compiler" ,
426
461
base = file(" compiler" ),
427
462
settings = commonSettings ++ publishSettings ++ Seq (
428
463
name := " Scala.js compiler" ,
429
464
crossVersion := CrossVersion .full, // because compiler api is not binary compatible
430
- unmanagedSourceDirectories in Compile +=
431
- (scalaSource in (irProject, Compile )).value,
432
465
libraryDependencies ++= Seq (
433
466
" org.scala-lang" % " scala-compiler" % scalaVersion.value,
434
467
" org.scala-lang" % " scala-reflect" % scalaVersion.value,
@@ -459,7 +492,7 @@ object Build extends sbt.Build {
459
492
},
460
493
exportJars := true
461
494
)
462
- )
495
+ ).dependsOnSource(irProject)
463
496
464
497
val commonToolsSettings = (
465
498
commonSettings ++ publishSettings ++ fatalWarningsSettings
@@ -531,7 +564,7 @@ object Build extends sbt.Build {
531
564
runner.run()
532
565
}
533
566
}
534
- ).dependsOn(compiler % " plugin " , javalibEx, testSuite % " test->test" , irProjectJS)
567
+ ).withScalaJSCompiler. dependsOn(javalibEx, testSuite % " test->test" , irProjectJS)
535
568
536
569
lazy val jsEnvs : Project = Project (
537
570
id = " jsEnvs" ,
@@ -573,7 +606,6 @@ object Build extends sbt.Build {
573
606
normalizedName := " sbt-scalajs" ,
574
607
name in bintray := " sbt-scalajs-plugin" , // "sbt-scalajs" was taken
575
608
sbtPlugin := true ,
576
- scalaVersion := " 2.10.6" ,
577
609
scalaBinaryVersion :=
578
610
CrossVersion .binaryScalaVersion(scalaVersion.value),
579
611
previousArtifactSetting,
@@ -598,7 +630,8 @@ object Build extends sbt.Build {
598
630
599
631
lazy val delambdafySetting = {
600
632
scalacOptions ++= (
601
- if (scalaBinaryVersion.value == " 2.10" ) Seq ()
633
+ if (isGeneratingEclipse) Seq ()
634
+ else if (scalaBinaryVersion.value == " 2.10" ) Seq ()
602
635
else Seq (" -Ydelambdafy:method" ))
603
636
}
604
637
@@ -630,8 +663,7 @@ object Build extends sbt.Build {
630
663
name := " java.lang library for Scala.js" ,
631
664
publishArtifact in Compile := false ,
632
665
delambdafySetting,
633
- scalacOptions += " -Yskip:cleanup,icode,jvm" ,
634
- compileWithLibrarySetting,
666
+ noClassFilesSettings,
635
667
636
668
resourceGenerators in Compile <+= Def .task {
637
669
val base = (resourceManaged in Compile ).value
@@ -643,7 +675,7 @@ object Build extends sbt.Build {
643
675
) ++ (
644
676
scalaJSExternalCompileSettings
645
677
)
646
- ).dependsOn(compiler % " plugin " )
678
+ ).withScalaJSCompiler.dependsOnLibraryNoJar
647
679
648
680
lazy val javalib : Project = Project (
649
681
id = " javalib" ,
@@ -654,12 +686,11 @@ object Build extends sbt.Build {
654
686
name := " Java library for Scala.js" ,
655
687
publishArtifact in Compile := false ,
656
688
delambdafySetting,
657
- scalacOptions += " -Yskip:cleanup,icode,jvm" ,
658
- compileWithLibrarySetting
689
+ noClassFilesSettings
659
690
) ++ (
660
691
scalaJSExternalCompileSettings
661
692
)
662
- ).dependsOn(compiler % " plugin " )
693
+ ).withScalaJSCompiler.dependsOnLibraryNoJar
663
694
664
695
lazy val scalalib : Project = Project (
665
696
id = " scalalib" ,
@@ -668,16 +699,13 @@ object Build extends sbt.Build {
668
699
name := " Scala library for Scala.js" ,
669
700
publishArtifact in Compile := false ,
670
701
delambdafySetting,
671
- compileWithLibrarySetting ,
702
+ noClassFilesSettings ,
672
703
673
704
// The Scala lib is full of warnings we don't want to see
674
705
scalacOptions ~= (_.filterNot(
675
706
Set (" -deprecation" , " -unchecked" , " -feature" ) contains _)),
676
707
677
-
678
708
scalacOptions ++= List (
679
- // Do not generate .class files
680
- " -Yskip:cleanup,icode,jvm" ,
681
709
// Tell plugin to hack fix bad classOf trees
682
710
" -P:scalajs:fixClassOf" ,
683
711
// Link source maps to github sources of original Scalalib
@@ -796,7 +824,7 @@ object Build extends sbt.Build {
796
824
) ++ (
797
825
scalaJSExternalCompileSettings
798
826
)
799
- ).dependsOn(compiler % " plugin " )
827
+ ).withScalaJSCompiler.dependsOnLibraryNoJar
800
828
801
829
lazy val libraryAux : Project = Project (
802
830
id = " libraryAux" ,
@@ -807,12 +835,11 @@ object Build extends sbt.Build {
807
835
name := " Scala.js aux library" ,
808
836
publishArtifact in Compile := false ,
809
837
delambdafySetting,
810
- scalacOptions += " -Yskip:cleanup,icode,jvm" ,
811
- compileWithLibrarySetting
838
+ noClassFilesSettings
812
839
) ++ (
813
840
scalaJSExternalCompileSettings
814
841
)
815
- ).dependsOn(compiler % " plugin " )
842
+ ).withScalaJSCompiler.dependsOnLibraryNoJar
816
843
817
844
lazy val library : Project = Project (
818
845
id = " library" ,
@@ -823,7 +850,7 @@ object Build extends sbt.Build {
823
850
name := " Scala.js library" ,
824
851
delambdafySetting,
825
852
scalacOptions in (Compile , doc) ++= Seq (" -implicits" , " -groups" ),
826
- exportJars := true ,
853
+ exportJars := ! isGeneratingEclipse ,
827
854
previousArtifactSetting,
828
855
binaryIssueFilters ++= BinaryIncompatibilities .Library ,
829
856
libraryDependencies +=
@@ -862,7 +889,7 @@ object Build extends sbt.Build {
862
889
libraryMappings ++ otherMappings ++ javalibFilteredMappings
863
890
}
864
891
))
865
- ).dependsOn(compiler % " plugin " )
892
+ ).withScalaJSCompiler
866
893
867
894
lazy val javalibEx : Project = Project (
868
895
id = " javalibEx" ,
@@ -872,14 +899,14 @@ object Build extends sbt.Build {
872
899
) ++ Seq (
873
900
name := " Scala.js JavaLib Ex" ,
874
901
delambdafySetting,
875
- scalacOptions in ( Compile , compile) += " -Yskip:cleanup,icode,jvm " ,
902
+ noClassFilesSettings ,
876
903
exportJars := true ,
877
904
jsDependencies +=
878
905
" org.webjars" % " jszip" % " 2.4.0" / " jszip.min.js" commonJSName " JSZip"
879
906
) ++ (
880
907
scalaJSExternalCompileSettings
881
908
)
882
- ).dependsOn(compiler % " plugin " , library)
909
+ ).withScalaJSCompiler. dependsOn(library)
883
910
884
911
lazy val stubs : Project = Project (
885
912
id = " stubs" ,
@@ -926,7 +953,7 @@ object Build extends sbt.Build {
926
953
previousArtifactSetting,
927
954
binaryIssueFilters ++= BinaryIncompatibilities .TestInterface
928
955
)
929
- ).dependsOn(compiler % " plugin " , library)
956
+ ).withScalaJSCompiler. dependsOn(library)
930
957
931
958
lazy val jasmineTestFramework = Project (
932
959
id = " jasmineTestFramework" ,
@@ -942,14 +969,14 @@ object Build extends sbt.Build {
942
969
" jasmine.js" dependsOn " jasmine-polyfills.js"
943
970
)
944
971
)
945
- ).dependsOn(compiler % " plugin " , library, testInterface)
972
+ ).withScalaJSCompiler. dependsOn(library, testInterface)
946
973
947
974
lazy val jUnitRuntime = Project (
948
975
id = " jUnitRuntime" ,
949
976
base = file(" junit-runtime" ),
950
977
settings = commonSettings ++ publishSettings ++ myScalaJSSettings ++
951
978
fatalWarningsSettings ++ Seq (name := " Scala.js JUnit test runtime" )
952
- ).dependsOn(compiler % " plugin " , testInterface)
979
+ ).withScalaJSCompiler. dependsOn(testInterface)
953
980
954
981
lazy val jUnitPlugin = Project (
955
982
id = " jUnitPlugin" ,
@@ -982,7 +1009,7 @@ object Build extends sbt.Build {
982
1009
moduleName := " helloworld" ,
983
1010
persistLauncher := true
984
1011
)
985
- ).dependsOn(compiler % " plugin " , library)
1012
+ ).withScalaJSCompiler. dependsOn(library)
986
1013
987
1014
lazy val reversi = Project (
988
1015
id = " reversi" ,
@@ -991,7 +1018,7 @@ object Build extends sbt.Build {
991
1018
name := " Reversi - Scala.js example" ,
992
1019
moduleName := " reversi"
993
1020
)
994
- ).dependsOn(compiler % " plugin " , library)
1021
+ ).withScalaJSCompiler. dependsOn(library)
995
1022
996
1023
lazy val testingExample = Project (
997
1024
id = " testingExample" ,
@@ -1005,7 +1032,7 @@ object Build extends sbt.Build {
1005
1032
" org.webjars" % " jquery" % " 1.10.2" / " jquery.js" % " test"
1006
1033
)
1007
1034
)
1008
- ).dependsOn(compiler % " plugin " , library, jasmineTestFramework % " test" )
1035
+ ).withScalaJSCompiler. dependsOn(library, jasmineTestFramework % " test" )
1009
1036
1010
1037
// Testing
1011
1038
@@ -1185,13 +1212,17 @@ object Build extends sbt.Build {
1185
1212
Seq (outFile)
1186
1213
},
1187
1214
1188
- scalacOptions in Test += {
1189
- val jar = (packageBin in (jUnitPlugin, Compile )).value
1190
- s " -Xplugin: $jar"
1215
+ scalacOptions in Test ++= {
1216
+ if (isGeneratingEclipse) {
1217
+ Seq .empty
1218
+ } else {
1219
+ val jar = (packageBin in (jUnitPlugin, Compile )).value
1220
+ Seq (s " -Xplugin: $jar" )
1221
+ }
1191
1222
}
1192
1223
)
1193
- ).dependsOn(
1194
- compiler % " plugin " , library, jUnitRuntime % " test" , jasmineTestFramework % " test"
1224
+ ).withScalaJSCompiler. dependsOn(
1225
+ library, jUnitRuntime % " test" , jasmineTestFramework % " test"
1195
1226
)
1196
1227
1197
1228
lazy val testSuiteJVM : Project = Project (
@@ -1216,7 +1247,7 @@ object Build extends sbt.Build {
1216
1247
),
1217
1248
publishArtifact in Compile := false
1218
1249
)
1219
- ).dependsOn(compiler % " plugin " , library, jasmineTestFramework % " test" )
1250
+ ).withScalaJSCompiler. dependsOn(library, jasmineTestFramework % " test" )
1220
1251
1221
1252
lazy val javalibExTestSuite : Project = Project (
1222
1253
id = " javalibExTestSuite" ,
@@ -1229,7 +1260,7 @@ object Build extends sbt.Build {
1229
1260
1230
1261
scalacOptions in Test ~= (_.filter(_ != " -deprecation" ))
1231
1262
)
1232
- ).dependsOn(compiler % " plugin " , javalibEx, jasmineTestFramework % " test" )
1263
+ ).withScalaJSCompiler. dependsOn(javalibEx, jasmineTestFramework % " test" )
1233
1264
1234
1265
lazy val partest : Project = Project (
1235
1266
id = " partest" ,
0 commit comments