|
| 1 | +import org.treesitter.build.Utils |
| 2 | + |
| 3 | +plugins { |
| 4 | + id 'java' |
| 5 | + id 'signing' |
| 6 | + id 'maven-publish' |
| 7 | +} |
| 8 | + |
| 9 | +group = 'io.github.bonede' |
| 10 | +version = libVersion |
| 11 | + |
| 12 | +repositories { |
| 13 | + mavenCentral() |
| 14 | +} |
| 15 | + |
| 16 | +dependencies { |
| 17 | + testImplementation platform(libs.junit.bom) |
| 18 | + testImplementation 'org.junit.jupiter:junit-jupiter' |
| 19 | + implementation project(":tree-sitter") |
| 20 | +} |
| 21 | + |
| 22 | +test { |
| 23 | + useJUnitPlatform() |
| 24 | +} |
| 25 | + |
| 26 | +def libName = "tree-sitter-hocon" |
| 27 | + |
| 28 | + |
| 29 | +java { |
| 30 | + withJavadocJar() |
| 31 | + withSourcesJar() |
| 32 | +} |
| 33 | + |
| 34 | +publishing { |
| 35 | + repositories { |
| 36 | + maven { |
| 37 | + name = "MavenCentral" |
| 38 | + def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" |
| 39 | + def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" |
| 40 | + credentials { |
| 41 | + username = ossrhUsername |
| 42 | + password = ossrhPassword |
| 43 | + } |
| 44 | + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl |
| 45 | + } |
| 46 | + } |
| 47 | + publications { |
| 48 | + maven(MavenPublication) { |
| 49 | + from components.java |
| 50 | + pom { |
| 51 | + name = libName |
| 52 | + url = 'https://github.com/bonede/tree-sitter-ng' |
| 53 | + description = "Next generation Tree Sitter Java binding" |
| 54 | + licenses { |
| 55 | + license { |
| 56 | + name = 'MIT' |
| 57 | + } |
| 58 | + } |
| 59 | + scm { |
| 60 | + connection = 'scm:git:https://github.com/bonede/tree-sitter-ng.git' |
| 61 | + developerConnection = 'scm:git:https://github.com/bonede/tree-sitter-ng.git' |
| 62 | + url = 'https://github.com/bonede/tree-sitter-ng' |
| 63 | + } |
| 64 | + developers { |
| 65 | + developer { |
| 66 | + id = 'bonede' |
| 67 | + name = 'Wang Liang' |
| 68 | + email = 'bonede@qq.com' |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | + |
| 77 | +signing { |
| 78 | + sign configurations.archives |
| 79 | + sign publishing.publications |
| 80 | +} |
| 81 | +tasks.register('downloadSource') { |
| 82 | + group = "build setup" |
| 83 | + description = "Download parser source" |
| 84 | + def zipUrl = "https://github.com/antosha417/tree-sitter-hocon/archive/refs/heads/master.zip" |
| 85 | + def downloadDir = Utils.libDownloadDir(project, libName) |
| 86 | + def zip = Utils.libZipFile(project, libName, libVersion) |
| 87 | + def parserCFile = Utils.libParserCFile(project, libName, libVersion) |
| 88 | + inputs.files(layout.projectDirectory.file("gradle.properties")) |
| 89 | + outputs.files(parserCFile) |
| 90 | + doLast { |
| 91 | + download.run { |
| 92 | + src zipUrl |
| 93 | + dest zip |
| 94 | + overwrite false |
| 95 | + } |
| 96 | + copy { |
| 97 | + from zipTree(zip) |
| 98 | + into downloadDir |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | +} |
| 103 | + |
| 104 | +tasks.register("buildNative") { |
| 105 | + group = "build" |
| 106 | + description = "Build parser native modules" |
| 107 | + dependsOn "downloadSource", rootProject.bootstrap |
| 108 | + def jniSrcDir = Utils.jniSrcDir(project) |
| 109 | + def outDir = Utils.jniOutDir(project) |
| 110 | + def jniCFile = Utils.jniCFile(project, "org_treesitter_TreeSitterHocon.c") |
| 111 | + def parserCFile = Utils.libParserCFile(project, libName, libVersion) |
| 112 | + def libSrcDir = Utils.libSrcDir(project, libName, libVersion) |
| 113 | + def jniInclude = Utils.jniIncludeDir(project) |
| 114 | + |
| 115 | + def targets = Utils.treeSitterTargets(project) |
| 116 | + def outputFiles = targets.collect() |
| 117 | + { t -> Utils.jniOutFile(project, t, libName)} |
| 118 | + def srcFiles = project.fileTree(libSrcDir) { |
| 119 | + include(Utils.libFiles()) |
| 120 | + }.toList() |
| 121 | + outputs.files(outputFiles) |
| 122 | + def inputFiles = srcFiles + [parserCFile, rootProject.layout.projectDirectory.file("gradle.properties")] |
| 123 | + inputs.files(inputFiles) |
| 124 | + doLast{ |
| 125 | + mkdir(outDir) |
| 126 | + targets.each {target -> |
| 127 | + def jniMdInclude = Utils.jniMdInclude(project, target) |
| 128 | + def jniOutFile = Utils.jniOutFile(project, target, libName) |
| 129 | + def files = project.fileTree(libSrcDir) { |
| 130 | + include(Utils.libFiles()) |
| 131 | + }.toList() |
| 132 | + def cmd = [ |
| 133 | + rootProject.downloadZig.zigExe, "c++", |
| 134 | + "-g0", |
| 135 | + "-shared", |
| 136 | + "-target", target, |
| 137 | + "-I", libSrcDir, |
| 138 | + "-I", jniInclude, |
| 139 | + "-I", jniMdInclude, |
| 140 | + "-o", jniOutFile, |
| 141 | + jniCFile, |
| 142 | + ] |
| 143 | + |
| 144 | + cmd.addAll(files) |
| 145 | + exec{ |
| 146 | + workingDir jniSrcDir |
| 147 | + commandLine(cmd) |
| 148 | + } |
| 149 | + } |
| 150 | + Utils.removeWindowsDebugFiles(project) |
| 151 | + } |
| 152 | +} |
0 commit comments