-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.sbt
447 lines (428 loc) · 16.3 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
Global / onChangedBuildSource := ReloadOnSourceChanges
Global / excludeLintKeys += nativeImageVersion
Global / excludeLintKeys += nativeImageJvm
ThisBuild / organization := "codes.quine.labs"
ThisBuild / homepage := Some(url("https://github.com/makenowjust-labs/recheck"))
ThisBuild / licenses := Seq("MIT" -> url("http://opensource.org/licenses/MIT"))
ThisBuild / developers := List(
Developer(
"makenowjust",
"TSUYUSATO Kitsune",
"make.just.on@gmail.com",
url("https://quine.codes/")
)
)
ThisBuild / versionScheme := Some("early-semver")
ThisBuild / scalaVersion := "2.13.13"
ThisBuild / scalacOptions ++= Seq(
"-encoding",
"UTF-8",
"-feature",
"-deprecation",
"-Wunused",
"-P:bm4:implicit-patterns:n"
)
// Scalafix config:
ThisBuild / scalafixScalaBinaryVersion := "2.13"
ThisBuild / semanticdbEnabled := true
ThisBuild / semanticdbVersion := scalafixSemanticdb.revision
val releaseVersion = taskKey[String]("A release version")
ThisBuild / releaseVersion := {
if (version.value.endsWith("-SNAPSHOT")) previousStableVersion.value.getOrElse("0.0.0")
else version.value
}
lazy val root = project
.in(file("."))
.settings(
sonatypeProfileName := "codes.quine",
publish / skip := true,
coverageEnabled := false
)
.aggregate(
coreJVM,
coreJS,
commonJVM,
commonJS,
execJVM,
execJS,
unicodeJVM,
unicodeJS,
parseJVM,
parseJS,
codecJVM,
codecJS,
js,
cli
)
lazy val core = crossProject(JVMPlatform, JSPlatform)
.in(file("modules/recheck-core"))
.settings(
name := "recheck-core",
console / initialCommands := """
|import scala.concurrent.duration._
|import scala.util.{Failure, Random, Success, Try}
|
|import codes.quine.labs.recheck._
|import codes.quine.labs.recheck.automaton._
|import codes.quine.labs.recheck.common._
|import codes.quine.labs.recheck.exec._
|import codes.quine.labs.recheck.data._
|import codes.quine.labs.recheck.diagnostics._
|import codes.quine.labs.recheck.fuzz._
|import codes.quine.labs.recheck.recall._
|import codes.quine.labs.recheck.regexp._
|import codes.quine.labs.recheck.unicode._
|import codes.quine.labs.recheck.util._
|import codes.quine.labs.recheck.vm._
|
|def logger: Context.Logger = (message: String) => {
| val date = java.time.LocalDateTime.now()
| Console.out.println(s"[$date] $message")
|}
|
|implicit def ctx: Context = Context(timeout = 10.seconds, logger = Some(logger))
|
|def time[A](name: String)(body: => A): A = {
| val start = System.nanoTime()
| try body
| finally {
| println(s"$name: ${(System.nanoTime() - start) / 1e9} s")
| }
|}
|
|def parse(source: String, flags: String): Pattern =
| time("parse")(Parser.parse(source, flags) match {
| case Right(pattern) => pattern
| case Left(ex) => throw new InvalidRegExpException(ex.getMessage)
| })
|
|def compile(source: String, flags: String): Program = {
| val pattern = parse(source, flags)
| time("compile")(ProgramBuilder.build(pattern).get)
|}
|
|def run(
| source: String,
| flags: String,
| input: String,
| pos: Int = 0,
| limit: Int = Int.MaxValue,
| usesAcceleration: Boolean = true,
| needsLoopAnalysis: Boolean = false,
| needsFailedPoints: Boolean = false,
| needsCoverage: Boolean = false,
| needsHeatmap: Boolean = false
|)(implicit ctx: Context): Interpreter.Result = {
| val pattern = parse(source, flags)
| val flagSet = pattern.flagSet
| val program = time("compile")(ProgramBuilder.build(pattern).get)
| val uinput0 = UString(input)
| val uinput = if (flagSet.ignoreCase) UString.canonicalize(uinput0, flagSet.unicode) else uinput0
| val opts = Interpreter.Options(
| limit = limit,
| usesAcceleration = usesAcceleration,
| needsLoopAnalysis = needsLoopAnalysis,
| needsFailedPoints = needsFailedPoints,
| needsCoverage = needsCoverage,
| needsHeatmap = needsHeatmap
| )
| time("run")(Interpreter.run(program, uinput, 0, opts))
|}
|
|def seed(
| source: String,
| flags: String,
| maxSimpleRepeatSize: Int = Parameters.DefaultMaxSimpleRepeatCount,
| maxInitialGenerationSize: Int = Parameters.DefaultMaxInitialGenerationSize,
| limit: Int = Parameters.DefaultIncubationLimit
|)(implicit ctx: Context): Set[FString] = {
| val pattern = parse(source, flags)
| time("seed")(StaticSeeder.seed(pattern, maxSimpleRepeatSize, maxInitialGenerationSize, limit))
|}
|
|def validate(
| source: String,
| flags: String,
| pattern: AttackPattern,
| timeout: Duration = Duration(1, SECONDS)
|): RecallResult =
| time("validate")(RecallValidator.validate(source, flags, pattern, timeout)(NodeExecutor.exec))
|
|def check(
| source: String,
| flags: String,
| accelerationMode: AccelerationMode = Parameters.DefaultAccelerationMode,
| attackLimit: Int = Parameters.DefaultAttackLimit,
| attackTimeout: Duration = Parameters.DefaultAttackTimeout,
| checker: Checker = Parameters.DefaultChecker,
| crossoverSize: Int = Parameters.DefaultCrossoverSize,
| heatRatio: Double = Parameters.DefaultHeatRatio,
| incubationLimit: Int = Parameters.DefaultIncubationLimit,
| incubationTimeout: Duration = Parameters.DefaultIncubationTimeout,
| logger: Option[Context.Logger] = Parameters.DefaultLogger,
| maxAttackStringSize: Int = Parameters.DefaultMaxAttackStringSize,
| maxDegree: Int = Parameters.DefaultMaxDegree,
| maxGeneStringSize: Int = Parameters.DefaultMaxGeneStringSize,
| maxGenerationSize: Int = Parameters.DefaultMaxGenerationSize,
| maxInitialGenerationSize: Int = Parameters.DefaultMaxInitialGenerationSize,
| maxIteration: Int = Parameters.DefaultMaxIteration,
| maxNFASize: Int = Parameters.DefaultMaxNFASize,
| maxPatternSize: Int = Parameters.DefaultMaxPatternSize,
| maxRecallStringSize: Int = Parameters.DefaultMaxRecallStringSize,
| maxRepeatCount: Int = Parameters.DefaultMaxRepeatCount,
| maxSimpleRepeatCount: Int = Parameters.DefaultMaxSimpleRepeatCount,
| mutationSize: Int = Parameters.DefaultMutationSize,
| randomSeed: Long = Parameters.DefaultRandomSeed,
| recallLimit: Int = Parameters.DefaultRecallLimit,
| recallTimeout: Duration = Parameters.DefaultRecallTimeout,
| seeder: Seeder = Parameters.DefaultSeeder,
| seedingLimit: Int = Parameters.DefaultSeedingLimit,
| seedingTimeout: Duration = Parameters.DefaultSeedingTimeout,
| timeout: Duration = Parameters.DefaultTimeout,
|): Diagnostics = {
| val params = Parameters(
| accelerationMode,
| attackLimit,
| attackTimeout,
| checker,
| crossoverSize,
| heatRatio,
| incubationLimit,
| incubationTimeout,
| logger,
| maxAttackStringSize,
| maxDegree,
| maxGeneStringSize,
| maxGenerationSize,
| maxInitialGenerationSize,
| maxIteration,
| maxNFASize,
| maxPatternSize,
| maxRecallStringSize,
| maxRepeatCount,
| maxSimpleRepeatCount,
| mutationSize,
| randomSeed,
| recallLimit,
| recallTimeout,
| seeder,
| seedingLimit,
| seedingTimeout,
| timeout,
| )
| time("check")(ReDoS.check(source, flags, params))
|}
|""".stripMargin,
Compile / console / scalacOptions -= "-Wunused",
Test / console / scalacOptions -= "-Wunused",
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
// Settings for test:
libraryDependencies += "org.scalameta" %%% "munit" % "1.0.2" % Test,
testFrameworks += new TestFramework("munit.Framework")
)
.jsSettings(
libraryDependencies += ("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0" % Test)
.cross(CrossVersion.for3Use2_13)
)
.dependsOn(common, exec, unicode, parse)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val common = crossProject(JVMPlatform, JSPlatform)
.in(file("modules/recheck-common"))
.settings(
name := "recheck-common",
console / initialCommands := """
|import codes.quine.labs.recheck.common._
|""".stripMargin,
Compile / console / scalacOptions -= "-Wunused",
Test / console / scalacOptions -= "-Wunused",
// Dependencies:
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
// Settings for test:
libraryDependencies += "org.scalameta" %%% "munit" % "1.0.2" % Test,
testFrameworks += new TestFramework("munit.Framework")
)
.jsSettings(
libraryDependencies += ("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0" % Test)
.cross(CrossVersion.for3Use2_13)
)
lazy val commonJVM = common.jvm
lazy val commonJS = common.js
lazy val exec = crossProject(JVMPlatform, JSPlatform)
.in(file("modules/recheck-exec"))
.settings(
name := "recheck-exec",
console / initialCommands := """
|import codes.quine.labs.recheck.exec._
|""".stripMargin,
Compile / console / scalacOptions -= "-Wunused",
Test / console / scalacOptions -= "-Wunused",
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
// Settings for test:
libraryDependencies += "org.scalameta" %%% "munit" % "1.0.2" % Test,
testFrameworks += new TestFramework("munit.Framework")
)
.jsSettings(
libraryDependencies += ("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0" % Test)
.cross(CrossVersion.for3Use2_13)
)
.dependsOn(common)
lazy val execJVM = exec.jvm
lazy val execJS = exec.js
lazy val unicode = crossProject(JVMPlatform, JSPlatform)
.in(file("modules/recheck-unicode"))
.settings(
name := "recheck-unicode",
console / initialCommands := """
|import codes.quine.labs.recheck.unicode._
|""".stripMargin,
Compile / console / scalacOptions -= "-Wunused",
Test / console / scalacOptions -= "-Wunused",
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
// Generators:
{
val generateUnicodeData = taskKey[Seq[File]]("Generate Unicode data")
Seq(
Compile / sourceGenerators += generateUnicodeData.taskValue,
generateUnicodeData / fileInputs += baseDirectory.value.toGlob / ".." / ".." / ".." / "project" / "*DataGen.scala",
generateUnicodeData := {
val gens = Map[String, UnicodeDataGen](
"CaseMapDataGen.scala" -> CaseMapDataGen,
"PropertyDataGen.scala" -> PropertyDataGen
)
val pkg = "codes.quine.labs.recheck.unicode"
val dir = (Compile / sourceManaged).value / "codes" / "quine" / "labs" / "recheck" / "unicode"
val changes = generateUnicodeData.inputFileChanges
val updatedPaths = changes.created ++ changes.modified
for (path <- updatedPaths) {
val fileName = path.getFileName.toString
gens.get(fileName).foreach(_.gen(pkg, dir))
}
gens.map(_._2.file(dir)).toSeq
}
)
},
// Settings for test:
libraryDependencies += "org.scalameta" %%% "munit" % "1.0.2" % Test,
testFrameworks += new TestFramework("munit.Framework")
)
.jsSettings(
libraryDependencies += ("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0" % Test)
.cross(CrossVersion.for3Use2_13)
)
lazy val unicodeJVM = unicode.jvm
lazy val unicodeJS = unicode.js
lazy val parse = crossProject(JVMPlatform, JSPlatform)
.in(file("modules/recheck-parse"))
.settings(
name := "recheck-parse",
console / initialCommands := """
|import codes.quine.labs.recheck.regexp._
|""".stripMargin,
Compile / console / scalacOptions -= "-Wunused",
Test / console / scalacOptions -= "-Wunused",
// Dependencies:
libraryDependencies += "com.lihaoyi" %%% "fastparse" % "3.1.0",
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
// Settings for test:
libraryDependencies += "org.scalameta" %%% "munit" % "1.0.2" % Test,
testFrameworks += new TestFramework("munit.Framework")
)
.jsSettings(
libraryDependencies += ("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0" % Test)
.cross(CrossVersion.for3Use2_13)
)
.dependsOn(unicode)
lazy val parseJVM = parse.jvm
lazy val parseJS = parse.js
lazy val codec = crossProject(JVMPlatform, JSPlatform)
.in(file("modules/recheck-codec"))
.settings(
name := "recheck-codec",
console / initialCommands := """
|import io.circe._
|import io.circe.syntax._
|
|import codes.quine.labs.recheck.codec._
|""".stripMargin,
Compile / console / scalacOptions -= "-Wunused",
Test / console / scalacOptions -= "-Wunused",
// Dependencies:
libraryDependencies += "io.circe" %%% "circe-core" % "0.14.7",
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
// Settings for test:
libraryDependencies += "org.scalameta" %%% "munit" % "1.0.2" % Test,
testFrameworks += new TestFramework("munit.Framework")
)
.jsSettings(
libraryDependencies += ("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0" % Test)
.cross(CrossVersion.for3Use2_13)
)
.dependsOn(core)
lazy val codecJVM = codec.jvm
lazy val codecJS = codec.js
lazy val js = project
.in(file("modules/recheck-js"))
.enablePlugins(ScalaJSPlugin)
.settings(
name := "recheck-js",
publish / skip := true,
console / initialCommands := """
|import codes.quine.labs.recheck._
|""".stripMargin,
Compile / console / scalacOptions -= "-Wunused",
Test / console / scalacOptions -= "-Wunused",
// Dependencies:
libraryDependencies += "io.circe" %%% "circe-scalajs" % "0.14.6",
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
// Settings for test:
libraryDependencies += "org.scalameta" %%% "munit" % "1.0.2" % Test,
libraryDependencies += ("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0" % Test)
.cross(CrossVersion.for3Use2_13),
testFrameworks += new TestFramework("munit.Framework"),
// ScalaJS config:
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) },
Test / scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) }
)
.dependsOn(coreJS, codecJS)
lazy val cli = project
.in(file("modules/recheck-cli"))
.enablePlugins(NativeImagePlugin)
.settings(
name := "recheck-cli",
NativeImage / name := "recheck",
publish / skip := true,
Compile / mainClass := Some("codes.quine.labs.recheck.cli.Main"),
assembly / mainClass := (Compile / mainClass).value,
assembly / assemblyJarName := "recheck.jar",
nativeImageVersion := "22.3.0",
nativeImageJvm := "graalvm-java17",
nativeImageOptions ++= List(
"--no-fallback",
"--initialize-at-build-time=java",
"--initialize-at-build-time=scala",
"--initialize-at-build-time=cats",
"--initialize-at-build-time=io.circe",
"--initialize-at-build-time=codes.quine.labs.recheck"
),
console / initialCommands := """
|import io.circe._
|import io.circe.parser._
|import io.circe.syntax._
|
|import codes.quine.labs.recheck.cli._
|""".stripMargin,
Compile / console / scalacOptions -= "-Wunused",
Test / console / scalacOptions -= "-Wunused",
// Dependencies:
libraryDependencies += "com.monovore" %% "decline" % "2.4.1",
libraryDependencies += "io.circe" %% "circe-core" % "0.14.7",
libraryDependencies += "io.circe" %% "circe-generic" % "0.14.7",
libraryDependencies += "io.circe" %% "circe-parser" % "0.14.7",
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
// Settings for test:
libraryDependencies += "org.scalameta" %% "munit" % "1.0.2" % Test,
testFrameworks += new TestFramework("munit.Framework")
)
.dependsOn(coreJVM, codecJVM)