Skip to content

Commit 6609bcf

Browse files
committed
Generated native modules.
1 parent 0deb0ec commit 6609bcf

File tree

5 files changed

+573
-24
lines changed

5 files changed

+573
-24
lines changed

build.sbt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,16 @@ lazy val scalatestDiagramsJS = ScalatestBuild.scalatestDiagramsJS
7171
lazy val scalatestMatchersCoreJS = ScalatestBuild.scalatestMatchersCoreJS
7272
lazy val scalatestShouldMatchersJS = ScalatestBuild.scalatestShouldMatchersJS
7373
lazy val scalatestMustMatchersJS = ScalatestBuild.scalatestMustMatchersJS
74-
lazy val scalatestModulesJS = ScalatestBuild.scalatestModulesJS
74+
lazy val scalatestModulesJS = ScalatestBuild.scalatestModulesJS
75+
lazy val scalatestCoreNative = ScalatestBuild.scalatestCoreNative
76+
lazy val scalatestFeatureSpecNative = ScalatestBuild.scalatestFeatureSpecNative
77+
lazy val scalatestFlatSpecNative = ScalatestBuild.scalatestFlatSpecNative
78+
lazy val scalatestFreeSpecNative = ScalatestBuild.scalatestFreeSpecNative
79+
lazy val scalatestFunSuiteNative = ScalatestBuild.scalatestFunSuiteNative
80+
lazy val scalatestPropSpecNative = ScalatestBuild.scalatestPropSpecNative
81+
lazy val scalatestWordSpecNative = ScalatestBuild.scalatestWordSpecNative
82+
lazy val scalatestDiagramsNative = ScalatestBuild.scalatestDiagramsNative
83+
lazy val scalatestMatchersCoreNative = ScalatestBuild.scalatestMatchersCoreNative
84+
lazy val scalatestShouldMatchersNative = ScalatestBuild.scalatestShouldMatchersNative
85+
lazy val scalatestMustMatchersNative = ScalatestBuild.scalatestMustMatchersNative
86+
lazy val scalatestModulesNative = ScalatestBuild.scalatestModulesNative

project/GenModulesNative.scala

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import java.io.{File, BufferedWriter, FileWriter}
2+
import scala.io.Source
3+
4+
object GenModulesNative {
5+
6+
private def uncommentJsExport(line: String): String =
7+
if (line.trim.startsWith("//SCALATESTJS,NATIVE-ONLY "))
8+
line.substring(line.indexOf("//SCALATESTJS,NATIVE-ONLY ") + 26)
9+
else if (line.trim.startsWith("//SCALATESTNATIVE-ONLY "))
10+
line.substring(line.indexOf("//SCALATESTNATIVE-ONLY ") + 23)
11+
else
12+
line
13+
14+
private def transformLine(line: String): String =
15+
uncommentJsExport(line)
16+
17+
private def copyFile(sourceFile: File, destFile: File): File = {
18+
val destWriter = new BufferedWriter(new FileWriter(destFile))
19+
try {
20+
val lines = Source.fromFile(sourceFile).getLines.toList
21+
var skipMode = false
22+
for (line <- lines) {
23+
if (line.trim == "// SKIP-SCALATESTJS,NATIVE-START" || line.trim == "// SKIP-SCALATESTNATIVE-START")
24+
skipMode = true
25+
else if (line.trim == "// SKIP-SCALATESTJS,NATIVE-END" || line.trim == "// SKIP-SCALATESTNATIVE-END")
26+
skipMode = false
27+
else if (!skipMode) {
28+
destWriter.write(transformLine(line))
29+
destWriter.newLine()
30+
}
31+
}
32+
destFile
33+
}
34+
finally {
35+
destWriter.flush()
36+
destWriter.close()
37+
println("Copied " + destFile.getAbsolutePath)
38+
}
39+
}
40+
41+
def copyDir(sourceDirName: String, packageDirName: String, targetDir: File, skipList: List[String]): Seq[File] = {
42+
val packageDir = new File(targetDir, packageDirName)
43+
packageDir.mkdirs()
44+
val sourceDir = new File(sourceDirName)
45+
sourceDir.listFiles.toList.filter(f => f.isFile && !skipList.contains(f.getName) && f.getName.endsWith(".scala")).map { sourceFile =>
46+
val destFile = new File(packageDir, sourceFile.getName)
47+
copyFile(sourceFile, destFile)
48+
}
49+
}
50+
51+
def genScalaTestCore(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
52+
GenScalaTestNative.genScalaPackages.filter { case (packagePath, skipList) =>
53+
List(
54+
"org/scalatest",
55+
"org/scalatest/concurrent",
56+
"org/scalatest/enablers",
57+
"org/scalatest/exceptions",
58+
"org/scalatest/events",
59+
"org/scalatest/fixture",
60+
"org/scalatest/prop",
61+
"org/scalatest/tagobjects",
62+
"org/scalatest/time",
63+
"org/scalatest/tools",
64+
"org/scalatest/verbs",
65+
).contains(packagePath)
66+
}.flatMap { case (packagePath, skipList) =>
67+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir,
68+
if (packagePath == "org/scalatest" || packagePath == "org/scalatest/fixture") skipList ++ List("package.scala") else skipList)
69+
}.toList ++
70+
copyDir("scalatest.native/src/main/scala/org/scalatest", "org/scalatest", targetDir, List.empty) ++
71+
copyDir("scalatest.native/src/main/scala/org/scalatest/compatible", "org/scalatest/compatible", targetDir, List.empty) ++
72+
copyDir("scalatest.native/src/main/scala/org/scalatest/concurrent", "org/scalatest/concurrent", targetDir, List.empty) ++
73+
copyDir("scalatest.native/src/main/scala/org/scalatest/exceptions", "org/scalatest/exceptions", targetDir, List.empty) ++
74+
copyDir("scalatest.native/src/main/scala/org/scalatest/tools", "org/scalatest/tools", targetDir, List.empty) ++
75+
copyDir("modules/jvm/scalatest-core/src/main/scala/org/scalatest", "org/scalatest", targetDir, List.empty) ++
76+
copyDir("modules/jvm/scalatest-core/src/main/scala/org/scalatest/fixture", "org/scalatest/fixture", targetDir, List.empty)
77+
}
78+
79+
def genScalaTestFeatureSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
80+
GenScalaTestNative.genScalaPackages.filter { case (packagePath, skipList) =>
81+
List(
82+
"org/scalatest/featurespec"
83+
).contains(packagePath)
84+
}.flatMap { case (packagePath, skipList) =>
85+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
86+
}.toList
87+
88+
def genScalaTestFlatSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
89+
GenScalaTestNative.genScalaPackages.filter { case (packagePath, skipList) =>
90+
List(
91+
"org/scalatest/flatspec"
92+
).contains(packagePath)
93+
}.flatMap { case (packagePath, skipList) =>
94+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
95+
}.toList
96+
97+
def genScalaTestFreeSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
98+
GenScalaTestNative.genScalaPackages.filter { case (packagePath, skipList) =>
99+
List(
100+
"org/scalatest/freespec"
101+
).contains(packagePath)
102+
}.flatMap { case (packagePath, skipList) =>
103+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
104+
}.toList
105+
106+
def genScalaTestFunSuite(targetDir: File, version: String, scalaVersion: String): Seq[File] =
107+
GenScalaTestNative.genScalaPackages.filter { case (packagePath, skipList) =>
108+
List(
109+
"org/scalatest/funsuite"
110+
).contains(packagePath)
111+
}.flatMap { case (packagePath, skipList) =>
112+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
113+
}.toList
114+
115+
def genScalaTestPropSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
116+
GenScalaTestNative.genScalaPackages.filter { case (packagePath, skipList) =>
117+
List(
118+
"org/scalatest/propspec"
119+
).contains(packagePath)
120+
}.flatMap { case (packagePath, skipList) =>
121+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
122+
}.toList
123+
124+
def genScalaTestWordSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
125+
GenScalaTestNative.genScalaPackages.filter { case (packagePath, skipList) =>
126+
List(
127+
"org/scalatest/wordspec"
128+
).contains(packagePath)
129+
}.flatMap { case (packagePath, skipList) =>
130+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
131+
}.toList
132+
133+
def genScalaTestDiagrams(targetDir: File, version: String, scalaVersion: String): Seq[File] =
134+
GenScalaTestNative.genScalaPackages.filter { case (packagePath, skipList) =>
135+
List(
136+
"org/scalatest/diagrams"
137+
).contains(packagePath)
138+
}.flatMap { case (packagePath, skipList) =>
139+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
140+
}.toList
141+
142+
def genScalaTestMatchersCore(targetDir: File, version: String, scalaVersion: String): Seq[File] =
143+
GenScalaTestNative.genScalaPackages.filter { case (packagePath, skipList) =>
144+
List(
145+
"org/scalatest/matchers",
146+
"org/scalatest/matchers/dsl"
147+
).contains(packagePath)
148+
}.flatMap { case (packagePath, skipList) =>
149+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
150+
}.toList
151+
152+
def genScalaTestShouldMatchers(targetDir: File, version: String, scalaVersion: String): Seq[File] =
153+
GenScalaTestNative.genScalaPackages.filter { case (packagePath, skipList) =>
154+
List(
155+
"org/scalatest/matchers/should"
156+
).contains(packagePath)
157+
}.flatMap { case (packagePath, skipList) =>
158+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
159+
}.toList
160+
161+
}

project/JsBuild.scala

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ trait JsBuild { this: BuildCommons =>
442442
Compile / sourceGenerators += {
443443
Def.task{
444444
GenScalaTestJS.genHtml((resourceManaged in Compile).value, version.value, scalaVersion.value)
445-
Seq.empty[File]
445+
GenTable.genMainForScalaJS((sourceManaged in Compile).value / "scala" / "org" / "scalatest", version.value, scalaVersion.value)
446446
//GenSafeStyles.genMainForScalaJS((sourceManaged in Compile).value / "scala" / "org" / "scalatest", version.value, scalaVersion.value)
447447
}
448448
},
@@ -511,8 +511,7 @@ trait JsBuild { this: BuildCommons =>
511511
"Bundle-Name" -> "ScalaTest FeatureSpec JS",
512512
"Bundle-Description" -> "ScalaTest.js is an open-source test framework for the Javascript Platform designed to increase your productivity by letting you write fewer lines of test code that more clearly reveal your intent.",
513513
"Bundle-DocURL" -> "http://www.scalatest.org/",
514-
"Bundle-Vendor" -> "Artima, Inc.",
515-
"Main-Class" -> "org.scalatest.tools.Runner"
514+
"Bundle-Vendor" -> "Artima, Inc."
516515
)
517516
).dependsOn(scalatestCoreJS).enablePlugins(ScalaJSPlugin)
518517

@@ -544,8 +543,7 @@ trait JsBuild { this: BuildCommons =>
544543
"Bundle-Name" -> "ScalaTest FlatSpec JS",
545544
"Bundle-Description" -> "ScalaTest.js is an open-source test framework for the Javascript Platform designed to increase your productivity by letting you write fewer lines of test code that more clearly reveal your intent.",
546545
"Bundle-DocURL" -> "http://www.scalatest.org/",
547-
"Bundle-Vendor" -> "Artima, Inc.",
548-
"Main-Class" -> "org.scalatest.tools.Runner"
546+
"Bundle-Vendor" -> "Artima, Inc."
549547
)
550548
).dependsOn(scalatestCoreJS).enablePlugins(ScalaJSPlugin)
551549

@@ -577,8 +575,7 @@ trait JsBuild { this: BuildCommons =>
577575
"Bundle-Name" -> "ScalaTest FreeSpec JS",
578576
"Bundle-Description" -> "ScalaTest.js is an open-source test framework for the Javascript Platform designed to increase your productivity by letting you write fewer lines of test code that more clearly reveal your intent.",
579577
"Bundle-DocURL" -> "http://www.scalatest.org/",
580-
"Bundle-Vendor" -> "Artima, Inc.",
581-
"Main-Class" -> "org.scalatest.tools.Runner"
578+
"Bundle-Vendor" -> "Artima, Inc."
582579
)
583580
).dependsOn(scalatestCoreJS).enablePlugins(ScalaJSPlugin)
584581

@@ -610,8 +607,7 @@ trait JsBuild { this: BuildCommons =>
610607
"Bundle-Name" -> "ScalaTest FunSuite JS",
611608
"Bundle-Description" -> "ScalaTest.js is an open-source test framework for the Javascript Platform designed to increase your productivity by letting you write fewer lines of test code that more clearly reveal your intent.",
612609
"Bundle-DocURL" -> "http://www.scalatest.org/",
613-
"Bundle-Vendor" -> "Artima, Inc.",
614-
"Main-Class" -> "org.scalatest.tools.Runner"
610+
"Bundle-Vendor" -> "Artima, Inc."
615611
)
616612
).dependsOn(scalatestCoreJS).enablePlugins(ScalaJSPlugin)
617613

@@ -643,8 +639,7 @@ trait JsBuild { this: BuildCommons =>
643639
"Bundle-Name" -> "ScalaTest PropSpec JS",
644640
"Bundle-Description" -> "ScalaTest.js is an open-source test framework for the Javascript Platform designed to increase your productivity by letting you write fewer lines of test code that more clearly reveal your intent.",
645641
"Bundle-DocURL" -> "http://www.scalatest.org/",
646-
"Bundle-Vendor" -> "Artima, Inc.",
647-
"Main-Class" -> "org.scalatest.tools.Runner"
642+
"Bundle-Vendor" -> "Artima, Inc."
648643
)
649644
).dependsOn(scalatestCoreJS).enablePlugins(ScalaJSPlugin)
650645

@@ -676,8 +671,7 @@ trait JsBuild { this: BuildCommons =>
676671
"Bundle-Name" -> "ScalaTest WordSpec JS",
677672
"Bundle-Description" -> "ScalaTest.js is an open-source test framework for the Javascript Platform designed to increase your productivity by letting you write fewer lines of test code that more clearly reveal your intent.",
678673
"Bundle-DocURL" -> "http://www.scalatest.org/",
679-
"Bundle-Vendor" -> "Artima, Inc.",
680-
"Main-Class" -> "org.scalatest.tools.Runner"
674+
"Bundle-Vendor" -> "Artima, Inc."
681675
)
682676
).dependsOn(scalatestCoreJS).enablePlugins(ScalaJSPlugin)
683677

@@ -709,8 +703,7 @@ trait JsBuild { this: BuildCommons =>
709703
"Bundle-Name" -> "ScalaTest Diagrams JS",
710704
"Bundle-Description" -> "ScalaTest.js is an open-source test framework for the Javascript Platform designed to increase your productivity by letting you write fewer lines of test code that more clearly reveal your intent.",
711705
"Bundle-DocURL" -> "http://www.scalatest.org/",
712-
"Bundle-Vendor" -> "Artima, Inc.",
713-
"Main-Class" -> "org.scalatest.tools.Runner"
706+
"Bundle-Vendor" -> "Artima, Inc."
714707
)
715708
).dependsOn(scalacticMacroJS % "compile-internal, test-internal", scalatestCoreJS).enablePlugins(ScalaJSPlugin)
716709

@@ -744,8 +737,7 @@ trait JsBuild { this: BuildCommons =>
744737
"Bundle-Name" -> "ScalaTest Matchers Core JS",
745738
"Bundle-Description" -> "ScalaTest.js is an open-source test framework for the Javascript Platform designed to increase your productivity by letting you write fewer lines of test code that more clearly reveal your intent.",
746739
"Bundle-DocURL" -> "http://www.scalatest.org/",
747-
"Bundle-Vendor" -> "Artima, Inc.",
748-
"Main-Class" -> "org.scalatest.tools.Runner"
740+
"Bundle-Vendor" -> "Artima, Inc."
749741
)
750742
).dependsOn(scalacticMacroJS % "compile-internal, test-internal", scalatestCoreJS).enablePlugins(ScalaJSPlugin)
751743

@@ -777,8 +769,7 @@ trait JsBuild { this: BuildCommons =>
777769
"Bundle-Name" -> "ScalaTest Should Matchers",
778770
"Bundle-Description" -> "ScalaTest.js is an open-source test framework for the Javascript Platform designed to increase your productivity by letting you write fewer lines of test code that more clearly reveal your intent.",
779771
"Bundle-DocURL" -> "http://www.scalatest.org/",
780-
"Bundle-Vendor" -> "Artima, Inc.",
781-
"Main-Class" -> "org.scalatest.tools.Runner"
772+
"Bundle-Vendor" -> "Artima, Inc."
782773
)
783774
).dependsOn(scalacticMacroJS % "compile-internal, test-internal", scalatestMatchersCoreJS).enablePlugins(ScalaJSPlugin)
784775

@@ -810,8 +801,7 @@ trait JsBuild { this: BuildCommons =>
810801
"Bundle-Name" -> "ScalaTest Must Matchers",
811802
"Bundle-Description" -> "ScalaTest.js is an open-source test framework for the Javascript Platform designed to increase your productivity by letting you write fewer lines of test code that more clearly reveal your intent.",
812803
"Bundle-DocURL" -> "http://www.scalatest.org/",
813-
"Bundle-Vendor" -> "Artima, Inc.",
814-
"Main-Class" -> "org.scalatest.tools.Runner"
804+
"Bundle-Vendor" -> "Artima, Inc."
815805
)
816806
).dependsOn(scalacticMacroJS % "compile-internal, test-internal", scalatestMatchersCoreJS).enablePlugins(ScalaJSPlugin)
817807

0 commit comments

Comments
 (0)