blob: 8f6246cf9afd6e816d130baa4abc514c5c257b4b (
plain)
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
|
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.kotlin.jps.build
import org.jetbrains.jps.builders.storage.BuildDataPaths
import org.jetbrains.jps.incremental.ModuleBuildTarget
import org.jetbrains.jps.incremental.storage.BuildDataManager
import org.jetbrains.kotlin.incremental.KOTLIN_CACHE_DIRECTORY_NAME
import org.jetbrains.kotlin.jps.targets.KotlinModuleBuildTarget
import java.io.File
private val HAS_KOTLIN_MARKER_FILE_NAME = "has-kotlin-marker.txt"
private val REBUILD_AFTER_CACHE_VERSION_CHANGE_MARKER = "rebuild-after-cache-version-change-marker.txt"
abstract class MarkerFile(private val fileName: String, private val paths: BuildDataPaths) {
operator fun get(target: KotlinModuleBuildTarget<*>): Boolean? =
get(target.jpsModuleBuildTarget)
operator fun get(target: ModuleBuildTarget): Boolean? {
val file = target.markerFile
if (!file.exists()) return null
return file.readText().toBoolean()
}
operator fun set(target: KotlinModuleBuildTarget<*>, value: Boolean) =
set(target.jpsModuleBuildTarget, value)
operator fun set(target: ModuleBuildTarget, value: Boolean) {
val file = target.markerFile
if (!file.exists()) {
file.parentFile.mkdirs()
file.createNewFile()
}
file.writeText(value.toString())
}
fun clean(target: KotlinModuleBuildTarget<*>) =
clean(target.jpsModuleBuildTarget)
fun clean(target: ModuleBuildTarget) {
target.markerFile.delete()
}
private val ModuleBuildTarget.markerFile: File
get() {
val directory = File(paths.getTargetDataRoot(this), KOTLIN_CACHE_DIRECTORY_NAME)
return File(directory, fileName)
}
}
class HasKotlinMarker(dataManager: BuildDataManager) : MarkerFile(HAS_KOTLIN_MARKER_FILE_NAME, dataManager.dataPaths)
class RebuildAfterCacheVersionChangeMarker(dataManager: BuildDataManager) :
MarkerFile(REBUILD_AFTER_CACHE_VERSION_CHANGE_MARKER, dataManager.dataPaths)
|