Skip to content

Commit 39c332c

Browse files
ml86mpollmeier
andauthored
Enable Scala 3 cross build. (#118)
* Fix indentation induced warnings and errors. * Cross build for scala 3. * Make Main class scala 2 and 3 compatible. * split subproject definitions into separate build.sbt * WIP * wip - works for scala3 * fuzzy scala version detection * final dependencies Co-authored-by: Michael Pollmeier <[email protected]>
1 parent 87f7d84 commit 39c332c

File tree

15 files changed

+243
-173
lines changed

15 files changed

+243
-173
lines changed

build.sbt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ name := "overflowdb-codegen-root"
33
ThisBuild/organization := "io.shiftleft"
44

55
/** scala cross version settings for codegen:
6-
* we need scala 2.12 for the sbt plugin and 2.13 for everything else */
6+
* we need scala 2.12 for the sbt plugin, 2.13 and 3 for everything else */
77
lazy val codegen_2_12 = Projects.codegen_2_12
88
lazy val codegen_2_13 = Projects.codegen_2_13
9+
lazy val codegen_3 = Projects.codegen_3
10+
lazy val integrationTestSchemas_3 = Projects.integrationTestSchemas_3
11+
lazy val integrationTestSchemas_2_13 = Projects.integrationTestSchemas_2_13
12+
lazy val integrationTestDomainClasses_2_13 = Projects.integrationTestDomainClasses_2_13
13+
lazy val integrationTestDomainClasses_3 = Projects.integrationTestDomainClasses_3
14+
lazy val integrationTests_2_13 = Projects.integrationTests_2_13
15+
lazy val integrationTests_3 = Projects.integrationTests_3
916
lazy val sbtPlugin = Projects.sbtPlugin
10-
lazy val integrationTests = Projects.integrationTests
1117

1218
ThisBuild/resolvers += Resolver.mavenLocal
1319

@@ -16,8 +22,6 @@ ThisBuild/Compile/scalacOptions ++= Seq(
1622
"-feature",
1723
"-deprecation",
1824
"-language:implicitConversions",
19-
"-Ywarn-unused",
20-
// "-language:existentials",
2125
)
2226

2327
ThisBuild/licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0"))

codegen/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name := "overflowdb-codegen"
44

55
libraryDependencies ++= Seq(
66
"io.shiftleft" % "overflowdb-core" % Versions.overflowdb,
7-
"com.github.pathikrit" %% "better-files" % "3.8.0",
7+
("com.github.pathikrit" %% "better-files" % "3.8.0").cross(CrossVersion.for3Use2_13),
88
"com.github.scopt" %% "scopt" % "4.0.1",
99
"org.scalatest" %% "scalatest" % "3.2.9" % Test,
1010
)

codegen/src/main/scala/overflowdb/codegen/CodeGen.scala

Lines changed: 84 additions & 84 deletions
Large diffs are not rendered by default.

codegen/src/main/scala/overflowdb/codegen/Helpers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ object Helpers {
181181
| $propertyDefaultValueCases
182182
| case _ => super.propertyDefaultValue(propertyKey)
183183
| }
184-
|""".stripMargin
184+
|""".stripMargin.replaceAll("\n", "\n ")
185185
}
186186

187187
def propertyDefaultCases(properties: Seq[Property[_]]): String =

codegen/src/main/scala/overflowdb/codegen/Main.scala

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,42 @@ import java.io.File
44
import overflowdb.schema.Schema
55
import scopt.OParser
66

7-
object Main extends App {
7+
object Main {
88
case class Config(classWithSchema: String, fieldName: String, outputDir: File)
9+
def main(args: Array[String]) = {
10+
val builder = OParser.builder[Config]
11+
val parser1 = {
12+
import builder._
13+
OParser.sequence(
14+
programName("codegen"),
15+
opt[String]('c', "classWithSchema")
16+
.required()
17+
.action((x, c) => c.copy(classWithSchema = x))
18+
.text("class with schema field, e.g. `org.example.MyDomain$`"),
19+
opt[String]('f', "field")
20+
.required()
21+
.action((x, c) => c.copy(fieldName = x))
22+
.text("(static) field name for schema within the specified `classWithSchema` with schema field, e.g. `org.example.MyDomain$`"),
23+
opt[File]('o', "out")
24+
.required()
25+
.action((x, c) => c.copy(outputDir = x))
26+
.text("output directory"),
27+
)
28+
}
929

10-
val builder = OParser.builder[Config]
11-
val parser1 = {
12-
import builder._
13-
OParser.sequence(
14-
programName("codegen"),
15-
opt[String]('c', "classWithSchema")
16-
.required()
17-
.action((x, c) => c.copy(classWithSchema = x))
18-
.text("class with schema field, e.g. `org.example.MyDomain$`"),
19-
opt[String]('f', "field")
20-
.required()
21-
.action((x, c) => c.copy(fieldName = x))
22-
.text("(static) field name for schema within the specified `classWithSchema` with schema field, e.g. `org.example.MyDomain$`"),
23-
opt[File]('o', "out")
24-
.required()
25-
.action((x, c) => c.copy(outputDir = x))
26-
.text("output directory"),
27-
)
28-
}
29-
30-
OParser.parse(parser1, args, Config("", "", null)).foreach(execute)
30+
OParser.parse(parser1, args, Config("", "", null)).foreach(execute)
3131

32-
def execute(config: Config): Seq[File] = config match {
33-
case Config(classWithSchema, fieldName, outputDir) =>
34-
val classLoader = getClass.getClassLoader
35-
val clazz = classLoader.loadClass(classWithSchema)
36-
val field = clazz.getDeclaredField(fieldName)
37-
assert(field.getType == classOf[Schema], s"field $fieldName in class `$classWithSchema` must be of type `overflowdb.schema.Schema`, but actually is of type `${field.getType}`")
38-
field.setAccessible(true)
39-
val schema = field.get(clazz).asInstanceOf[Schema]
32+
def execute(config: Config): Seq[File] = config match {
33+
case Config(classWithSchema, fieldName, outputDir) =>
34+
val classLoader = getClass.getClassLoader
35+
val clazz = classLoader.loadClass(classWithSchema)
36+
val field = clazz.getDeclaredField(fieldName)
37+
assert(field.getType == classOf[Schema], s"field $fieldName in class `$classWithSchema` must be of type `overflowdb.schema.Schema`, but actually is of type `${field.getType}`")
38+
field.setAccessible(true)
39+
val schema = field.get(clazz).asInstanceOf[Schema]
4040

41-
new CodeGen(schema).run(outputDir)
41+
new CodeGen(schema).run(outputDir)
42+
}
4243
}
4344
}
4445

codegen/src/main/scala/overflowdb/schema/testschema1/TestSchema1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import overflowdb.storage.ValueTypes
1010
object TestSchema1 extends App {
1111
val builder = new SchemaBuilder("Cpg", "io.shiftleft.codepropertygraph.generated")
1212

13-
implicit val schemaInfo = SchemaInfo.forClass(getClass)
13+
implicit val schemaInfo: SchemaInfo = SchemaInfo.forClass(getClass)
1414

1515
// properties
1616
val name = builder

codegen/src/main/scala/overflowdb/schema/testschema4/TestSchema4.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java.io.File
99
object TestSchema4 extends App {
1010
val builder = new SchemaBuilder("Cpg","io.shiftleft.codepropertygraph.generated")
1111

12-
implicit val schemaInfo = SchemaInfo.forClass(getClass)
12+
implicit val schemaInfo: SchemaInfo = SchemaInfo.forClass(getClass)
1313

1414
val edge1 = builder.addEdgeType("EDGE_1")
1515
val rootNode1 = builder.addNodeBaseType("ROOT_NODE_1")

integration-tests/build.sbt

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name := "integration-test-domain-classes-2_13"
2+
3+
scalaVersion := Versions.scala_2_13
4+
5+
val generateDomainClasses = taskKey[Seq[File]]("generate overflowdb domain classes for all test schemas")
6+
7+
libraryDependencies ++= Seq(
8+
"io.shiftleft" %% "overflowdb-traversal" % Versions.overflowdb,
9+
"org.scalatest" %% "scalatest" % "3.2.9" % Test,
10+
"org.slf4j" % "slf4j-simple" % "1.7.28" % Test,
11+
)
12+
13+
Compile/sourceGenerators += Projects.integrationTestSchemas_2_13 / generateDomainClasses
14+
scalacOptions -= "-Xfatal-warnings"
15+
16+
publish/skip := true
17+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name := "integration-test-domain-classes-3"
2+
3+
scalaVersion := Versions.scala_3
4+
5+
val generateDomainClasses = taskKey[Seq[File]]("generate overflowdb domain classes for all test schemas")
6+
7+
libraryDependencies ++= Seq(
8+
"io.shiftleft" %% "overflowdb-traversal" % Versions.overflowdb,
9+
"org.scalatest" %% "scalatest" % "3.2.9" % Test,
10+
"org.slf4j" % "slf4j-simple" % "1.7.28" % Test,
11+
)
12+
13+
Compile/sourceGenerators += Projects.integrationTestSchemas_3 / generateDomainClasses
14+
scalacOptions -= "-Xfatal-warnings"
15+
16+
publish/skip := true
17+

0 commit comments

Comments
 (0)