[JS DCE] Add an ability to define overwriting strategy when copying dependencies in dev-mode
* CLI option "-Xdev-mode-overwriting-strategy" * System Property "kotlin.js.dce.devmode.overwriting.strategy" Possible values: "older", "all". #KT-36349 Fixed
This commit is contained in:
@@ -1,23 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.js.dce
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.CLITool
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.arguments.DevModeOverwritingStrategies
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSDceArguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
@@ -63,7 +53,13 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
||||
return if (!arguments.devMode) {
|
||||
performDce(files, arguments, messageCollector)
|
||||
} else {
|
||||
copyFiles(files)
|
||||
val devModeOverwritingStrategy =
|
||||
arguments.devModeOverwritingStrategy ?:
|
||||
System.getProperty("kotlin.js.dce.devmode.overwriting.strategy", DevModeOverwritingStrategies.OLDER)
|
||||
|
||||
val overwriteOnlyOlderFiles = devModeOverwritingStrategy == DevModeOverwritingStrategies.OLDER
|
||||
|
||||
copyFiles(files, overwriteOnlyOlderFiles)
|
||||
ExitCode.OK
|
||||
}
|
||||
}
|
||||
@@ -96,21 +92,22 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
||||
return ExitCode.OK
|
||||
}
|
||||
|
||||
private fun copyFiles(files: List<InputFile>) {
|
||||
private fun copyFiles(files: List<InputFile>, overwriteOnlyOlderFiles: Boolean) {
|
||||
for (file in files) {
|
||||
copyResource(file.resource, File(file.outputPath))
|
||||
copyResource(file.resource, File(file.outputPath), overwriteOnlyOlderFiles)
|
||||
file.sourceMapResource?.let { sourceMap ->
|
||||
val sourceMapTarget = File(file.outputPath + ".map")
|
||||
val inputFile = File(sourceMap.name)
|
||||
if (!inputFile.exists() || !mapSourcePaths(inputFile, sourceMapTarget)) {
|
||||
copyResource(sourceMap, sourceMapTarget)
|
||||
copyResource(sourceMap, sourceMapTarget, overwriteOnlyOlderFiles)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun copyResource(resource: InputResource, targetFile: File) {
|
||||
if (targetFile.exists() && resource.lastModified() < targetFile.lastModified()) return
|
||||
private fun copyResource(resource: InputResource, targetFile: File, overwriteOnlyOlderFiles: Boolean) {
|
||||
// TODO shouldn't it be "<="?
|
||||
if (overwriteOnlyOlderFiles && targetFile.exists() && resource.lastModified() < targetFile.lastModified()) return
|
||||
|
||||
targetFile.parentFile.mkdirs()
|
||||
resource.reader().use { input ->
|
||||
|
||||
Reference in New Issue
Block a user