Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance toolchain update 2023 #159

Merged
merged 8 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ project/metals.sbt
# for personal trials / tests that shall be ignored but stay on your disk
ztest/
.bsp/

# OS specific
.DS_Store

7 changes: 7 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules = [
ProcedureSyntax,
ExplicitResultTypes,
NoAutoTupling,
OrganizeImports,
RemoveUnused
]
7 changes: 6 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import sbtassembly.AssemblyPlugin.defaultUniversalScript

ThisBuild / scalaVersion := "2.13.6"
ThisBuild / scalaVersion := "2.12.18"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional, 2.13 brings 100 + deprecations,
so first, get a clean 2.12 state, and then move on

ThisBuild / organization := "com.github.cross-language-cpp"

ThisBuild / semanticdbEnabled := true // enable SemanticDB
ThisBuild / semanticdbVersion := scalafixSemanticdb.revision // use Scalafix compatible version
ThisBuild / scalacOptions += "-Ywarn-unused"

val binExt = if (System.getProperty("os.name").startsWith("Windows")) ".bat" else ""
lazy val djinni = (project in file("."))
.configs(IntegrationTest)
.enablePlugins(ScalafixPlugin) // enable Scalafix for this project
.settings(
name := "djinni",
Defaults.itSettings,
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.5.5
sbt.version=1.9.7
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.4")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1")

10 changes: 5 additions & 5 deletions src/it/scala/djinni/GeneratorIntegrationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -732,23 +732,23 @@ class GeneratorIntegrationTest extends IntegrationTest with GivenWhenThen {
}

it(s"skip-generate should not generate any files") {
var idlFile = "all_datatypes"
var outputPath = "src/it/resources/result/skip_generate"
val idlFile = "all_datatypes"
val outputPath = "src/it/resources/result/skip_generate"
Given(s"`$idlFile.djinni`")
When(s"passing skip-generation true")

djinni(djinniParams(idlFile, outputPath) + " --skip-generation true")

Then(s"`$outputPath` should have been created")
var dir = new java.io.File(outputPath, idlFile)
val dir = new java.io.File(outputPath, idlFile)
dir.exists should be(true)

Then(s"genreated-files.txt should have been generated")
val gen = new java.io.File(dir, "generated-files.txt")
gen.exists should be(true)

Then(s"only the generated-files.txt should be generated")
var files = dir.listFiles()
val files = dir.listFiles()
files should contain only (gen)
}

Expand Down Expand Up @@ -815,7 +815,7 @@ class GeneratorIntegrationTest extends IntegrationTest with GivenWhenThen {
When(
"calling the generator with `--cpp-namespace custom_namespace, --cpp-json-serialization nlohmann_json and --cpp-out`"
)
val output = djinni(
val _ = djinni(
s"--idl src/it/resources/${idlFile}.djinni --cpp-namespace custom_namespace --cpp-json-serialization nlohmann_json --cpp-out $outputPath/cpp --cpp-header-out $outputPath/cpp-headers"
)
Then(
Expand Down
2 changes: 1 addition & 1 deletion src/it/scala/djinni/IntegrationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scala.sys.process._

import scala.reflect.io.Directory
import java.io.File
import java.nio.file.Paths
//import java.nio.file.Paths

// Base class for integration tests, providing a few handy helper functions
class IntegrationTest extends AnyFunSpec {
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/djinni/BaseObjcGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class BaseObjcGenerator(spec: Spec) extends Generator(spec) {
consts: Seq[Const],
selfName: String,
genType: ObjcConstantType.Value
) = {
): Unit = {
def boxedPrimitive(ty: TypeRef): String = {
val (_, needRef) = marshal.toObjcType(ty)
if (needRef) "@" else ""
Expand Down Expand Up @@ -78,16 +78,16 @@ abstract class BaseObjcGenerator(spec: Spec) extends Generator(spec) {
}
}

def writeObjcConstMethImpl(c: Const, w: IndentWriter) {
def writeObjcConstMethImpl(c: Const, w: IndentWriter): Unit = {
val label = "+"
val nullability = marshal.nullability(c.ty.resolved).fold("")(" __" + _)
val ret = marshal.fqFieldType(c.ty) + nullability
val decl = s"$label ($ret)${idObjc.method(c.ident)}"
writeAlignedObjcCall(w, decl, List(), "", p => ("", ""))
writeAlignedObjcCall(w, decl, List(), "", _ => ("", ""))
w.wl

w.braced {
var static_var = s"s_${idObjc.method(c.ident)}"
val static_var = s"s_${idObjc.method(c.ident)}"
w.w(s"static ${marshal.fqFieldType(c.ty)} const ${static_var} = ")
writeObjcConstValue(w, c.ty, c.value)
w.wl(";")
Expand Down
62 changes: 41 additions & 21 deletions src/main/scala/djinni/CWrapperGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import djinni.ast._
import djinni.generatorTools._
import djinni.meta._
import djinni.writer.IndentWriter
import sun.reflect.generics.tree.ReturnType

import scala.collection.mutable

Expand All @@ -30,7 +29,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
val cppMarshal = new CppMarshal(spec)
val dw = "djinni_this"

def getCppDefArgs(m: Interface.Method, self: String) = {
def getCppDefArgs(m: Interface.Method, self: String): String = {
if (m.static || self == "") {
marshal.cArgDecl(
m.params.map(p =>
Expand All @@ -47,7 +46,11 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
}
}

def getDefArgs(m: Interface.Method, self: String, forHeader: Boolean) = {
def getDefArgs(
m: Interface.Method,
self: String,
forHeader: Boolean
): String = {
if (m.static || self == "") {
marshal.cArgDecl(
m.params.map(p =>
Expand All @@ -66,13 +69,17 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
}
}

def getCArgTypes(m: Interface.Method, self: String, forHeader: Boolean) = {
def getCArgTypes(
m: Interface.Method,
self: String,
forHeader: Boolean
): String = {
marshal.cArgDecl(
Seq(self) ++ m.params.map(p => marshal.cParamType(p.ty, forHeader))
)
}

def getRecordTypes(r: Record, forHeader: Boolean) = {
def getRecordTypes(r: Record, forHeader: Boolean): Seq[String] = {
r.fields.map(f => marshal.cParamType(f.ty, forHeader))
}

Expand Down Expand Up @@ -240,6 +247,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
classAsMethodName: String,
w: IndentWriter
): Unit = {
val _ = retType // unused, TODO, check remove
val elTyRef = getContainerElTypeRef(tm, 0, ident)
val addToList = marshal.callback(idCpp.method(classAsMethodName + "__add"))
declareObjectUniquePointerHandle(tm, classAsMethodName, w)
Expand Down Expand Up @@ -326,6 +334,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
classAsMethodName: String,
w: IndentWriter
): Unit = {
val _ = retType // unused, TODO, check remove
val addToMap = marshal.callback(idCpp.method(classAsMethodName + "__add"))
val keyTyRef = getContainerElTypeRef(tm, 0, ident)
val valTyRef = getContainerElTypeRef(tm, 1, ident)
Expand Down Expand Up @@ -397,8 +406,8 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
classAsMethodName: String,
w: IndentWriter
): Unit = {
val createMap =
marshal.callback(idCpp.method(classAsMethodName + "__create"))
val _ = retType // unused, TODO, check remove
marshal.callback(idCpp.method(classAsMethodName + "__create"))
val addToMap = marshal.callback(idCpp.method(classAsMethodName + "__add"))
val keyTyRef = getContainerElTypeRef(tm, 0, ident)
declareObjectUniquePointerHandle(tm, classAsMethodName, w)
Expand Down Expand Up @@ -428,8 +437,8 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
getReturnType: String,
addCArgs: String
): Unit = {
val _ = (tm, ident, retType) // unused, TODO, check remove
val handle = "DjinniObjectHandle *"

var ret = ""
var cArgs = ""
if (getName != "") {
Expand Down Expand Up @@ -462,8 +471,8 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
getReturnType: String,
addCArgs: String
): Unit = {
val _ = (tm, ident, retType) // unused, TODO, check remove
val handle = "struct DjinniObjectHandle *"

var ret = ""
var cArgs = ""
if (getName != "") {
Expand Down Expand Up @@ -550,6 +559,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
deleteMethod: String,
w: IndentWriter
): Unit = {
val _ = handle // unused, TODO, check remove
w.wl(
"djinni::Handle" + t(optHandle) + " " + djinniWrapper + "::fromCpp" + p(
spec.cppOptionalTemplate + t(retType) + " dc"
Expand Down Expand Up @@ -579,6 +589,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
deleteMethod: String,
w: IndentWriter
): Unit = {
val _ = reinterpret // unused, TODO, check remove
w.wl(
spec.cppOptionalTemplate + t(retTypeStr) + djinniWrapper + "::toCpp" + p(
"djinni::Handle" + t(optHandle) + " dh"
Expand Down Expand Up @@ -609,6 +620,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
retType: String,
w: IndentWriter
): Unit = {
val _ = (handle, optHandle) // unused, TODO, check remove
w.wl(
"static " + "djinni::Handle" + t(cppHandle) + " fromCpp" + p(
cppMarshal.fqParamType(tm) + " dc"
Expand Down Expand Up @@ -641,6 +653,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
h: mutable.TreeSet[String],
hpp: mutable.TreeSet[String]
): Unit = {
val _ = className // unused, TODO, check remove
// className is the composed idl named of the container type
val handle = "DjinniObjectHandle"
val handlePtr = handle + " *"
Expand Down Expand Up @@ -763,6 +776,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
h: mutable.TreeSet[String],
hpp: mutable.TreeSet[String]
): Unit = {
val _ = className // unused, TODO, check remove
// className is the composed idl named of the container type
val handle = "DjinniObjectHandle"
val handlePtr = "DjinniObjectHandle *"
Expand Down Expand Up @@ -934,6 +948,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
h: mutable.TreeSet[String],
hpp: mutable.TreeSet[String]
): Unit = {
val _ = className // unused, TODO, check remove
// className is the composed idl named of the container type
val handle = "DjinniObjectHandle"
val handlePtr = "DjinniObjectHandle *"
Expand Down Expand Up @@ -1059,13 +1074,13 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
}

class CRefs(ident: Ident, origin: String) {
var hpp = mutable.TreeSet[String]()
var h = mutable.TreeSet[String]()
var hpp: mutable.TreeSet[String] = mutable.TreeSet[String]()
var h: mutable.TreeSet[String] = mutable.TreeSet[String]()

def collect(ty: TypeRef, justCollect: Boolean) {
def collect(ty: TypeRef, justCollect: Boolean): Unit = {
collect(ty.resolved, justCollect)
}
def collect(tm: MExpr, justCollect: Boolean) {
def collect(tm: MExpr, justCollect: Boolean): Unit = {
tm.args.foreach(t => collect(t, justCollect))
collect(tm.base, justCollect)

Expand Down Expand Up @@ -1093,7 +1108,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
}
}
}
def collect(m: Meta, justCollect: Boolean) = if (justCollect)
def collect(m: Meta, justCollect: Boolean): Unit = if (justCollect)
for (r <- marshal references (m, ident)) r match {
case ImportRef(arg) =>
if (arg.endsWith(".hpp\"") || !arg.contains("."))
Expand All @@ -1109,6 +1124,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
methods: Seq[Interface.Method],
w: IndentWriter
): Unit = {
val _ = cClassWrapper // unused, TODO, check remove
for (m <- methods) {
val ret = marshal.cReturnType(m.ret, false)
val cArgs = getCArgTypes(m, marshal.djinniObjectHandle + " * ", false)
Expand All @@ -1132,7 +1148,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
prefix: String,
number: Int,
w: IndentWriter
) = {
): Unit = {
val recordAsMethodName = idCpp.method(ident.name)
var field_number = number
for (f <- r.fields) {
Expand Down Expand Up @@ -1167,7 +1183,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
prefix: String,
number: Int,
w: IndentWriter
) = {
): Unit = {
val recordAsMethodName = idCpp.method(ident.name)
var field_number = number
for (f <- r.fields) {
Expand Down Expand Up @@ -1207,7 +1223,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
prefix: String,
number: Int,
w: IndentWriter
) = {
): IndentWriter = {
val recordAsFqClassType = withCppNs(idCpp.ty(ident.name))
val recordAsMethodName = idCpp.method(ident.name)
var field_number = number
Expand Down Expand Up @@ -1263,7 +1279,8 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
prefix: String,
number: Int,
w: IndentWriter
) = {
): IndentWriter = {
val _ = (prefix, number) // unused, TODO, check remove
val recordAsMethodName = idCpp.method(ident.name)

for (f <- r.fields) {
Expand Down Expand Up @@ -1306,7 +1323,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
includes: Iterable[String],
create: Boolean,
f: IndentWriter => Unit
) {
): Unit = {
if (create)
createFile(
spec.cWrapperOutFolder.get,
Expand Down Expand Up @@ -1363,6 +1380,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
create: Boolean,
f: IndentWriter => Unit
): Unit = {
val _ = cppClass // unused, TODO, check remove
if (create)
createFile(
spec.cWrapperHeaderOutFolder.get,
Expand Down Expand Up @@ -1400,6 +1418,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
create: Boolean,
f: IndentWriter => Unit
): Unit = {
val _ = cppClass // unused, TODO, check remove
// hpp file contains definition of DjinniStruct wrapper over cpp shared_ptr
// meant to facilitate interuse of interfaces across files
if (create)
Expand Down Expand Up @@ -1546,6 +1565,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
w: IndentWriter,
className: String
): Unit = {
val _ = ident // unused, TODO, check remove
w.wl("struct " + marshal.wrappedName(className) + " final {").nested {
w.wl(
marshal.wrappedName(className) + p(
Expand Down Expand Up @@ -1756,7 +1776,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
djinniWrapper: String,
cMethodName: String,
w: IndentWriter
) = {
): IndentWriter = {
w.wl(
"struct " + djinniWrapper + " * " + " make_proxy_object_from_handle_" + cMethodName + p(
"struct " + marshal.djinniObjectHandle + " * " + "c_ptr"
Expand Down Expand Up @@ -2148,7 +2168,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {

def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum): Unit = {
val refs = new CRefs(ident, origin)
writeCHeader(marshal.dh + ident.name, origin, "", refs.h, true, w => {})
writeCHeader(marshal.dh + ident.name, origin, "", refs.h, true, _ => {})

writeCppHeader(
marshal.dh + ident.name,
Expand Down
Loading
Loading