Skip to content

Commit

Permalink
fix: try to tune R8 starting command line for Mac-based CI/CD
Browse files Browse the repository at this point in the history
Signed-off-by: Artyom Shendrik <[email protected]>
  • Loading branch information
amal committed Jan 22, 2024
1 parent 1923b81 commit ea0e810
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 74 deletions.
1 change: 1 addition & 0 deletions checks/gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ version = libs.versions.version.get()
setupGradlePlugin {
allWarningsAsErrors = true
shrinkArtifacts = true
shrinkingConfig.useBothShrinkers = true

// FIXME: Verify to work on CI under 3 main OSes
// shrinkingConfig.useBothShrinkers.set(true)
Expand Down
2 changes: 2 additions & 0 deletions checks/gradle-plugin/pg/proguard.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@

# ProGuard-only configuration.
-skipnonpubliclibraryclasses

-keepkotlinmetadata
32 changes: 22 additions & 10 deletions checks/gradle-plugin/pg/rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
-dontnote javax.annotation.**
-dontnote javax.inject.**
-dontnote javax.xml.**
-dontnote kotlin.**
-dontnote org.jetbrains.annotations.**
-dontnote org.jetbrains.kotlin.**
-dontnote org.jetbrains.org.objectweb.asm.**
-dontnote org.w3c.dom.**
-dontnote org.xml.sax.**

-dontnote kotlin.**
# Kotlin metadata warnings
-dontwarn kotlin.**
-dontwarn org.gradle.**

#-ignorewarnings
#-forceprocessing
#-addconfigurationdebugging # Can cause malformed classes with R8!
#-whyareyoukeeping class **

-verbose

Expand All @@ -30,24 +36,30 @@
-mergeinterfacesaggressively

# Horizontal class merging increases size of the artifact.
# https://www.guardsquare.com/manual/configuration/optimizations
#-optimizations !library/*,!class/*,!field/*,!method/*,!code/*
-optimizations !class/merging/horizontal

#-whyareyoukeeping class **

#-adaptclassstrings
-adaptresourcefilenames **.properties,**.gif,**.jpg,**.png,**.webp,**.svg,**.ttf,**.otf,**.txt,**.xml
-adaptresourcefilecontents **.properties,**.MF

# For library projects.
# See https://www.guardsquare.com/manual/configuration/examples#library
-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Signature,Exceptions,*Annotation*,
#-renamesourcefileattribute SourceFile

# https://stackoverflow.com/a/69523469/1816338
-keepattributes Signature,Exceptions,
RuntimeVisible*Annotations,AnnotationDefault,
InnerClasses,PermittedSubclasses,EnclosingMethod,
Deprecated,SourceFile,LineNumberTable
Deprecated,SourceFile,SourceDir,LineNumberTable,
Synthetic,MethodParameters

-include keep-api-autogenerated.pro
-include ../../../fluxo-kmp-conf/pg/assumenosideeffects.pro

-keepclassmembers,allowoptimization enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
# Keep and adapt Kotlin metadata with ProGuard, allow reflection to work.
#-keep class kotlin.Metadata
# Kotlin suspend functions
#-keep class kotlin.coroutines.Continuation
2 changes: 1 addition & 1 deletion fluxo-kmp-conf/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ setupGradlePlugin(
githubProject = "fluxo-kt/fluxo-kmp-conf"
enableSpotless = true
setupCoroutines = false
shrinkArtifacts = true
shrinkArtifacts = !isCI().get()
shrinkingConfig.useR8 = true
//shrinkingConfig.r8FullMode.set(true)
experimentalLatestCompilation = true
Expand Down
4 changes: 0 additions & 4 deletions fluxo-kmp-conf/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,19 @@
<ID>LongMethod:SetupAndroidLint.kt$internal fun Project.setupAndroidLint( conf: FluxoConfigurationExtensionImpl, ignoredBuildTypes: List&lt;String>, ignoredFlavors: List&lt;String>, )</ID>
<ID>LongMethod:SetupTestsReport.kt$internal fun FluxoKmpConfContext.setupTestsReport()</ID>
<ID>LongMethod:TestReportsMergeTask.kt$TestReportsMergeTask$@TaskAction fun merge()</ID>
<ID>MagicNumber:ExternalToolRunner.kt$ExternalToolRunner$4096</ID>
<ID>MaxLineLength:DependencyGuardPlugin.kt$/** @see com.dropbox.gradle.plugins.dependencyguard.internal.ConfigurationValidators.isClasspathConfig */</ID>
<ID>MaxLineLength:LoadAndApplyPluginIfNotApplied.kt$"You may want to add it to the classpath in the root build.gradle.kts instead! $example"</ID>
<ID>MaxLineLength:LoadAndApplyPluginIfNotApplied.kt$logger.v("Found plugin '$pluginId' class on the classpath for '${project.path}': $className")</ID>
<ID>MaxLineLength:PropsAndEnv.kt$if</ID>
<ID>MaxLineLength:SetupMultiplatform.kt$*</ID>
<ID>MaxLineLength:SetupTestsReport.kt$if</ID>
<ID>MaximumLineLength:LoadAndApplyPluginIfNotApplied.kt$ </ID>
<ID>MaximumLineLength:PropsAndEnv.kt$ </ID>
<ID>MaximumLineLength:SetupTestsReport.kt$ </ID>
<ID>NestedBlockDepth:KotlinSourceSetsReportTask.kt$KotlinSourceSetsReportTask.KotlinSourceSetsModel$fun buildTrees(): List&lt;GraphNode></ID>
<ID>NestedBlockDepth:LoadAndApplyPluginIfNotApplied.kt$private fun FluxoKmpConfContext.getPluginIdAndVersion( id: String, version: String?, catalogPluginIds: Array&lt;out String>? = null, catalogPluginId: String?, logger: Logger, catalogVersionIds: Array&lt;out String>?, catalogVersionId: String?, ): Triple&lt;String, String?, String?></ID>
<ID>NestedBlockDepth:LoadAndApplyPluginIfNotApplied.kt$private fun FluxoKmpConfContext.loadPluginArtifactAndGetClass( pluginId: String, pluginVersion: String?, className: String?, catalogPluginAlias: String?, lookupClassName: Boolean, canLoadDynamically: Boolean, project: Project, ): Class&lt;*>?</ID>
<ID>NestedBlockDepth:TestReportsMergeTask.kt$TestReportsMergeTask$@TaskAction fun merge()</ID>
<ID>ReturnCount:KotlinSourceSetsReportTask.kt$KotlinSourceSetsReportTask.KotlinSourceSetsModel$private fun GraphNode.isReachableThrough(node: GraphNode): Boolean</ID>
<ID>ReturnCount:KotlinSourceSetsReportTask.kt$KotlinSourceSetsReportTask.SourceSetNodeRenderer$context(StyledTextOutput) @Suppress("CyclomaticComplexMethod") override fun renderAttrs(node: RenderableNode, parent: RenderableNode?)</ID>
<ID>SpacingAroundParens:ShrinkerKeepRulesFromApiTask.kt$(</ID>
<ID>SpreadOperator:GradleFileUtils.kt$(*dirs.ioFiles())</ID>
<ID>SwallowedException:DependencyHandlerUtils.kt$e: Throwable</ID>
<ID>UnusedPrivateMember:SetupAndroid.kt$private fun Project.configureMonkeyLauncherTasks()</ID>
Expand Down
41 changes: 20 additions & 21 deletions fluxo-kmp-conf/src/main/kotlin/fluxo/external/ExternalToolRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal class ExternalToolRunner(

val exitCodeIsNormal = result.exitValue == 0
if (checkExitCodeIsNormal && !exitCodeIsNormal) {
throwError(tool, args, workingDir, result, outFile, errFile, doLogToConsole)
throwError(tool, args, workingDir, result, outFile, errFile)
}

if (processStdout != null) {
Expand Down Expand Up @@ -121,7 +121,6 @@ internal class ExternalToolRunner(
result: ExecResult,
outFile: File,
errFile: File,
doLogToConsole: Boolean,
) {
val errMsg = buildString {
appendLine("External tool execution failed:")
Expand All @@ -134,32 +133,32 @@ internal class ExternalToolRunner(
val errSize = readableByteSize(errFile)
appendLine("* Error log ($errSize): ${errFile.absolutePath}")

// Print output in the error message if it was not printed before.
if (!doLogToConsole) {
if (!alwaysPrintErrorOutput) {
val error = errFile.readText().trim()
if (error.isNotEmpty()) {
appendLine("\nStandard error output:")
appendLine(error)
}
}

var out = outFile.readText().trim()
if (out.isNotEmpty()) {
if (out.length > 4096) {
out = "(truncated)\n ..." + out.takeLast(4096).trimStart()
}
appendLine("\nTool output:")
appendLine(out)
}
}
// Always pint stderr and stdout if the tool failed.
// Stderr can be duplicated with 'alwaysPrintErrorOutput',
// but it's better to output it twice than not to output it at all.
appendLogFile(errFile, "Standard error output")
appendLogFile(outFile, "Tool output")
}
throw GradleException(errMsg)
}

private fun StringBuilder.appendLogFile(file: File, title: String) {
val out = file.readText().trim()
if (out.isEmpty()) {
return
}
appendLine("\n* ").append(title).append(':')
if (out.length > LOG_LIMIT) {
append("(truncated)\n ...").appendLine(out.takeLast(LOG_LIMIT).trimStart())
} else {
appendLine(out)
}
}

private fun currentTimeStamp() = LocalDateTime.now().format(TIME_STAMP_PATTERN)

private companion object {
private val TIME_STAMP_PATTERN = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss")
private const val LOG_LIMIT = 4096
}
}
16 changes: 9 additions & 7 deletions fluxo-kmp-conf/src/main/kotlin/fluxo/gradle/CliArgUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import org.gradle.api.provider.Provider
internal fun <T : Any?> MutableCollection<String>.cliArg(
name: String,
value: T?,
fn: (T) -> String = defaultToString(),
base: File? = null,
fn: (T) -> String = defaultToString(base = base),
) {
if (value is Boolean) {
if (value) add(name)
Expand All @@ -20,20 +21,21 @@ internal fun <T : Any?> MutableCollection<String>.cliArg(
internal fun <T : Any?> MutableCollection<String>.cliArg(
name: String,
value: Provider<T>,
fn: (T) -> String = defaultToString(),
base: File? = null,
fn: (T) -> String = defaultToString(base = base),
) {
cliArg(name, value.orNull, fn)
cliArg(name = name, value = value.orNull, base = base, fn = fn)
}

internal fun MutableCollection<String>.javaOption(value: String) {
cliArg("--java-options", "'$value'")
cliArg(name = "--java-options", value = "'$value'")
}

private fun <T : Any?> defaultToString(): (T) -> String =
private fun <T : Any?> defaultToString(base: File? = null): (T) -> String =
{
val asString = when (it) {
is FileSystemLocation -> it.asFile.normalizedPath()
is File -> it.normalizedPath()
is FileSystemLocation -> it.asFile.normalizedPath(base)
is File -> it.normalizedPath(base)
else -> it.toString()
}
"\"$asString\""
Expand Down
Loading

0 comments on commit ea0e810

Please sign in to comment.