Skip to content

Commit

Permalink
Add gir-schema (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
sideeffffect authored Oct 21, 2023
1 parent 173bd25 commit cba699d
Show file tree
Hide file tree
Showing 8 changed files with 2,464 additions and 1 deletion.
60 changes: 60 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ lazy val root = project
gtk4,
harfbuzz,
pango,
`gir-schema`,
girepository
)
.settings(
Expand Down Expand Up @@ -233,6 +234,65 @@ lazy val harfbuzz =
.build
)

def generateXsd(
fileName: String,
sourceDirectoryValue: File,
targetDirectoryValue: File
): Unit = {
import com.thaiopensource.relaxng.input.parse.compact.CompactParseInputFormat
import com.thaiopensource.relaxng.output.LocalOutputDirectory
import com.thaiopensource.relaxng.output.xsd.XsdOutputFormat
import com.thaiopensource.util.UriOrFile
import com.thaiopensource.xml.sax.ErrorHandlerImpl

val inputFormat = new CompactParseInputFormat()
val outputFormat = new XsdOutputFormat()
val inputFile = sourceDirectoryValue / "relaxng" / s"$fileName.rnc"
val eh = new ErrorHandlerImpl()
val params = Array[String]()
val sc = inputFormat.load(
UriOrFile.toUri(inputFile.toString),
params,
"xsd",
eh,
null
)
val resultDir = targetDirectoryValue / "xsd"
resultDir.mkdirs()
val result = resultDir / s"$fileName.xsd"
val od = new LocalOutputDirectory(
sc.getMainUri,
result,
".xsd",
"UTF-8",
72,
2
)
outputFormat.output(sc, od, params, "rnc", eh)
}

lazy val generateXsd = TaskKey[Unit]("generateXsd")

lazy val `gir-schema` = project
.in(file("gir-schema"))
.configure(pkgConfigured("gir-schema"))
.enablePlugins(ScalaxbPlugin)
.settings(
Compile / generateXsd := {
generateXsd(
"gir",
(Compile / sourceDirectory).value,
(Compile / sourceDirectory).value
)
},
Compile / scalaxb / scalaxbPackageName := "com.indoorvivants.gnome.gir_schema",
libraryDependencies ++= List(
"javax.xml.bind" % "jaxb-api" % "2.3.1",
"org.scala-lang.modules" %% "scala-parser-combinators" % "2.2.0",
"org.scala-lang.modules" %% "scala-xml" % "2.1.0"
)
)

def pkgConfig(pkg: String, arg: String) = {
import sys.process.*
s"pkg-config --$arg $pkg".!!.trim.split(" ").toList
Expand Down
9 changes: 9 additions & 0 deletions gir-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# gir-schema

To update the schema, run

```
# alternatively can be sourced from /usr/share/gir-1.0/gir-1.2.rnc
curl https://gitlab.gnome.org/GNOME/gobject-introspection/-/raw/main/docs/gir-1.2.rnc > gir-schema/src/main/relaxng/gir.rnc
sbt gir-schema/generateXsd
```
Loading

0 comments on commit cba699d

Please sign in to comment.