[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:
+17
-13
@@ -1,21 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* 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.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.cli.common.arguments
|
package org.jetbrains.kotlin.cli.common.arguments
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.cli.common.arguments.DevModeOverwritingStrategies.ALL
|
||||||
|
import org.jetbrains.kotlin.cli.common.arguments.DevModeOverwritingStrategies.OLDER
|
||||||
|
|
||||||
class K2JSDceArguments : CommonToolArguments() {
|
class K2JSDceArguments : CommonToolArguments() {
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic private val serialVersionUID = 0L
|
@JvmStatic private val serialVersionUID = 0L
|
||||||
@@ -48,4 +40,16 @@ class K2JSDceArguments : CommonToolArguments() {
|
|||||||
)
|
)
|
||||||
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||||
var devMode: Boolean by FreezableVar(false)
|
var devMode: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
|
@Argument(
|
||||||
|
value = "-Xdev-mode-overwriting-strategy",
|
||||||
|
valueDescription = "{$OLDER|$ALL}",
|
||||||
|
description = "Overwriting strategy during copy dependencies in development mode"
|
||||||
|
)
|
||||||
|
var devModeOverwritingStrategy: String? by NullableStringFreezableVar(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
object DevModeOverwritingStrategies {
|
||||||
|
const val OLDER = "older"
|
||||||
|
const val ALL = "all"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* 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.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.cli.js.dce
|
package org.jetbrains.kotlin.cli.js.dce
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.CLITool
|
import org.jetbrains.kotlin.cli.common.CLITool
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
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.arguments.K2JSDceArguments
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
@@ -63,7 +53,13 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
|||||||
return if (!arguments.devMode) {
|
return if (!arguments.devMode) {
|
||||||
performDce(files, arguments, messageCollector)
|
performDce(files, arguments, messageCollector)
|
||||||
} else {
|
} 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
|
ExitCode.OK
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,21 +92,22 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
|||||||
return ExitCode.OK
|
return ExitCode.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun copyFiles(files: List<InputFile>) {
|
private fun copyFiles(files: List<InputFile>, overwriteOnlyOlderFiles: Boolean) {
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
copyResource(file.resource, File(file.outputPath))
|
copyResource(file.resource, File(file.outputPath), overwriteOnlyOlderFiles)
|
||||||
file.sourceMapResource?.let { sourceMap ->
|
file.sourceMapResource?.let { sourceMap ->
|
||||||
val sourceMapTarget = File(file.outputPath + ".map")
|
val sourceMapTarget = File(file.outputPath + ".map")
|
||||||
val inputFile = File(sourceMap.name)
|
val inputFile = File(sourceMap.name)
|
||||||
if (!inputFile.exists() || !mapSourcePaths(inputFile, sourceMapTarget)) {
|
if (!inputFile.exists() || !mapSourcePaths(inputFile, sourceMapTarget)) {
|
||||||
copyResource(sourceMap, sourceMapTarget)
|
copyResource(sourceMap, sourceMapTarget, overwriteOnlyOlderFiles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun copyResource(resource: InputResource, targetFile: File) {
|
private fun copyResource(resource: InputResource, targetFile: File, overwriteOnlyOlderFiles: Boolean) {
|
||||||
if (targetFile.exists() && resource.lastModified() < targetFile.lastModified()) return
|
// TODO shouldn't it be "<="?
|
||||||
|
if (overwriteOnlyOlderFiles && targetFile.exists() && resource.lastModified() < targetFile.lastModified()) return
|
||||||
|
|
||||||
targetFile.parentFile.mkdirs()
|
targetFile.parentFile.mkdirs()
|
||||||
resource.reader().use { input ->
|
resource.reader().use { input ->
|
||||||
|
|||||||
Vendored
Vendored
+2
@@ -1,5 +1,7 @@
|
|||||||
Usage: kotlin-dce-js <options> <source files>
|
Usage: kotlin-dce-js <options> <source files>
|
||||||
where advanced options include:
|
where advanced options include:
|
||||||
|
-Xdev-mode-overwriting-strategy={older|all}
|
||||||
|
Overwriting strategy during copy dependencies in development mode
|
||||||
-Xprint-reachability-info Print declarations marked as reachable
|
-Xprint-reachability-info Print declarations marked as reachable
|
||||||
|
|
||||||
Advanced options are non-standard and may be changed or removed without any notice.
|
Advanced options are non-standard and may be changed or removed without any notice.
|
||||||
@@ -976,6 +976,11 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/cli/js-dce"), Pattern.compile("^(.+)\\.args$"), null, false);
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/cli/js-dce"), Pattern.compile("^(.+)\\.args$"), null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("dceExtraHelp.args")
|
||||||
|
public void testDceExtraHelp() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/js-dce/dceExtraHelp.args");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("dceHelp.args")
|
@TestMetadata("dceHelp.args")
|
||||||
public void testDceHelp() throws Exception {
|
public void testDceHelp() throws Exception {
|
||||||
runTest("compiler/testData/cli/js-dce/dceHelp.args");
|
runTest("compiler/testData/cli/js-dce/dceHelp.args");
|
||||||
@@ -996,11 +1001,6 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
runTest("compiler/testData/cli/js-dce/invalidFilename.args");
|
runTest("compiler/testData/cli/js-dce/invalidFilename.args");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("jsExtraHelp.args")
|
|
||||||
public void testJsExtraHelp() throws Exception {
|
|
||||||
runTest("compiler/testData/cli/js-dce/jsExtraHelp.args");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("nonExistingSourcePath.args")
|
@TestMetadata("nonExistingSourcePath.args")
|
||||||
public void testNonExistingSourcePath() throws Exception {
|
public void testNonExistingSourcePath() throws Exception {
|
||||||
runTest("compiler/testData/cli/js-dce/nonExistingSourcePath.args");
|
runTest("compiler/testData/cli/js-dce/nonExistingSourcePath.args");
|
||||||
|
|||||||
Reference in New Issue
Block a user