forked from JetBrains/resharper-fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
288 lines (241 loc) · 9.79 KB
/
build.gradle.kts
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
import com.jetbrains.rider.generator.gradle.RdgenParams
import com.jetbrains.rider.generator.nova.GenerationSpec
import groovy.lang.Closure
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.internal.jvm.Jvm
import org.jetbrains.intellij.tasks.PublishTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.intellij.IntelliJPlugin
import org.jetbrains.intellij.tasks.PrepareSandboxTask
import org.jetbrains.kotlin.daemon.common.toHexString
import org.jetbrains.grammarkit.tasks.*
buildscript {
repositories {
maven { setUrl("https://cache-redirector.jetbrains.com/www.myget.org/F/rd-snapshots/maven") }
mavenCentral()
}
dependencies {
classpath("com.jetbrains.rd:rd-gen:0.183.29")
}
}
plugins {
id("org.jetbrains.kotlin.jvm") version "1.2.41"
id("org.jetbrains.intellij") version "0.3.2"
id("org.jetbrains.grammarkit") version "2018.1.7"
}
apply {
plugin("com.jetbrains.rdgen")
plugin("org.jetbrains.grammarkit")
}
repositories {
mavenCentral()
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
val baseVersion = "2018.3"
val buildCounter = ext.properties["build.number"] ?: "9999"
version = "$baseVersion.$buildCounter"
intellij {
type = "RD"
// Download a version of Rider to compile and run with. Either set `version` to
// 'LATEST-TRUNK-SNAPSHOT' or 'LATEST-EAP-SNAPSHOT' or a known version.
// This will download from www.jetbrains.com/intellij-repository/snapshots or
// www.jetbrains.com/intellij-repository/releases, respectively.
// Note that there's no guarantee that these are kept up to date
// version = 'LATEST-TRUNK-SNAPSHOT'
// If the build isn't available in intellij-repository, use an installed version via `localPath`
// localPath = '/Users/matt/Library/Application Support/JetBrains/Toolbox/apps/Rider/ch-1/171.4089.265/Rider EAP.app/Contents'
// localPath = "C:\\Users\\Ivan.Shakhov\\AppData\\Local\\JetBrains\\Toolbox\\apps\\Rider\\ch-0\\171.4456.459"
// localPath = "C:\\Users\\ivan.pashchenko\\AppData\\Local\\JetBrains\\Toolbox\\apps\\Rider\\ch-0\\dev"
// localPath 'build/riderRD-173-SNAPSHOT'
val dir = file("build/rider")
if (dir.exists()) {
logger.lifecycle("*** Using Rider SDK from local path " + dir.absolutePath)
localPath = dir.absolutePath
} else {
logger.lifecycle("*** Using Rider SDK from intellij-snapshots repository")
version = "$baseVersion-SNAPSHOT"
}
intellijRepo = "https://www.jetbrains.com/intellij-repository"
downloadSources = false
updateSinceUntilBuild = false
// Workaround for https://youtrack.jetbrains.com/issue/IDEA-179607
setPlugins("rider-plugins-appender")
}
val repoRoot = projectDir.parentFile!!
val resharperPluginPath = File(repoRoot, "ReSharper.FSharp")
val buildConfiguration = ext.properties["BuildConfiguration"] ?: "Debug"
val libFiles = listOf(
"FSharp.Common/bin/$buildConfiguration/net461/FSharp.Core.dll",
"FSharp.Common/bin/$buildConfiguration/net461/FSharp.Compiler.Service.dll", // todo: add pdb after next repack
"FSharp.Psi.Features/bin/$buildConfiguration/net461/Fantomas.dll")
val pluginFiles = listOf(
"FSharp.ProjectModelBase/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.ProjectModelBase",
"FSharp.Common/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.Common",
"FSharp.Psi/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.Psi",
"FSharp.Psi.Features/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.Psi.Features",
"Daemon.FSharp/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.Daemon.Cs",
"Services.FSharp/bin/$buildConfiguration/net461/JetBrains.ReSharper.Plugins.FSharp.Services.Cs")
val nugetPackagesPath by lazy {
val sdkPath = intellij.ideaDependency.classes
println("SDK path: $sdkPath")
val path = File(sdkPath, "lib/ReSharperHostSdk")
println("NuGet packages: $path")
if (!path.isDirectory) error("$path does not exist or not a directory")
return@lazy path
}
val riderSdkPackageVersion by lazy {
val sdkPackageName = "JetBrains.Rider.SDK"
val regex = Regex("${Regex.escape(sdkPackageName)}\\.([\\d\\.]+.*)\\.nupkg")
val version = nugetPackagesPath
.listFiles()
.mapNotNull { regex.matchEntire(it.name)?.groupValues?.drop(1)?.first() }
.singleOrNull() ?: error("$sdkPackageName package is not found in $nugetPackagesPath (or multiple matches)")
println("$sdkPackageName version is $version")
return@lazy version
}
val nugetConfigPath = File(repoRoot, "NuGet.Config")
val riderSdkVersionPropsPath = File(resharperPluginPath, "RiderSdkPackageVersion.props")
val riderFSharpTargetsGroup = "rider-fsharp"
fun File.writeTextIfChanged(content: String) {
val bytes = content.toByteArray()
if (!exists() || readBytes().toHexString() != bytes.toHexString()) {
println("Writing $path")
writeBytes(bytes)
}
}
configure<RdgenParams> {
val csOutput = File(repoRoot, "Resharper.FSharp/src/FSharp.ProjectModelBase/src/Protocol")
val ktOutput = File(repoRoot, "rider-fsharp/src/main/java/com/jetbrains/rider/plugins/fsharp/protocol")
verbose = true
hashFolder = "build/rdgen"
logger.info("Configuring rdgen params")
classpath({
logger.info("Calculating classpath for rdgen, intellij.ideaDependency is ${intellij.ideaDependency}")
val sdkPath = intellij.ideaDependency.classes
val rdLibDirectory = File(sdkPath, "lib/rd").canonicalFile
"$rdLibDirectory/rider-model.jar"
})
sources(File(repoRoot, "rider-fsharp/protocol/src/kotlin/model"))
packages = "model"
generator {
language = "kotlin"
transform = "asis"
root = "com.jetbrains.rider.model.nova.ide.IdeRoot"
namespace = "com.jetbrains.rider.model"
directory = "$ktOutput"
}
generator {
language = "csharp"
transform = "reversed"
root = "com.jetbrains.rider.model.nova.ide.IdeRoot"
namespace = "JetBrains.Rider.Model"
directory = "$csOutput"
}
}
tasks {
withType<PrepareSandboxTask> {
var files = libFiles + pluginFiles.map { "$it.dll" } + pluginFiles.map { "$it.pdb" }
files = files.map { "$resharperPluginPath/src/$it" }
if (name == IntelliJPlugin.PREPARE_TESTING_SANDBOX_TASK_NAME) {
val testHostPath = "$resharperPluginPath/test/src/FSharp.Tests.Host/bin/$buildConfiguration/net461"
val testHostName = "$testHostPath/JetBrains.ReSharper.Plugins.FSharp.Tests.Host"
files += listOf("$testHostName.dll", "$testHostName.pdb")
}
files.forEach {
from(it, { into("${intellij.pluginName}/dotnet") })
}
into("${intellij.pluginName}/projectTemplates") {
from("projectTemplates")
}
doLast {
files.forEach {
val file = file(it)
if (!file.exists()) throw RuntimeException("File $file does not exist")
logger.warn("$name: ${file.name} -> $destinationDir/${intellij.pluginName}/dotnet")
}
}
}
val generateFSharpLexer = task<GenerateLexer>("generateFSharpLexer") {
source = "src/main/java/com/jetbrains/rider/ideaInterop/fileTypes/fsharp/lexer/_FSharpLexer.flex"
targetDir = "src/main/java/com/jetbrains/rider/ideaInterop/fileTypes/fsharp/lexer"
targetClass = "_FSharpLexer"
purgeOldFiles = true
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
dependsOn(generateFSharpLexer, "rdgen")
}
withType<Test> {
useTestNG()
testLogging {
showStandardStreams = true
exceptionFormat = TestExceptionFormat.FULL
}
val rerunSuccessfulTests = false
outputs.upToDateWhen { !rerunSuccessfulTests }
ignoreFailures = true
}
"writeRiderSdkVersionProps" {
group = riderFSharpTargetsGroup
doLast {
riderSdkVersionPropsPath.writeTextIfChanged("""<Project>
<PropertyGroup>
<RiderSDKVersion>[$riderSdkPackageVersion]</RiderSDKVersion>
</PropertyGroup>
</Project>
""")
}
}
"writeNuGetConfig" {
group = riderFSharpTargetsGroup
doLast {
nugetConfigPath.writeTextIfChanged("""<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="resharper-sdk" value="$nugetPackagesPath" />
</packageSources>
</configuration>
""")
}
}
"assemble" {
doLast {
logger.lifecycle("Plugin version: $version")
logger.lifecycle("##teamcity[buildNumber '$version']")
}
}
"prepare" {
group = riderFSharpTargetsGroup
dependsOn("rdgen", "writeNuGetConfig", "writeRiderSdkVersionProps")
doLast {
exec {
executable = "dotnet"
args = listOf("restore", "$resharperPluginPath/ReSharper.FSharp.sln")
}
}
}
"buildReSharperPlugin" {
group = riderFSharpTargetsGroup
dependsOn("prepare")
doLast {
exec {
executable = "msbuild"
args = listOf("$resharperPluginPath/ReSharper.FSharp.sln")
}
}
}
task<Wrapper>("wrapper") {
gradleVersion = "4.7"
distributionType = Wrapper.DistributionType.ALL
distributionUrl = "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
}
defaultTasks("prepare")
// workaround for https://youtrack.jetbrains.com/issue/RIDER-18697
dependencies {
testCompile("xalan", "xalan", "2.7.2")
}