Is there tool that reports how much of a project i...
# multiplatform
t
Is there tool that reports how much of a project is common code and how much is platform dependent?
a
Can you elaborate a bit, what do you mean?
t
I have a project and I'm curious how much of my code is in commonMain and how much is not in commonMain. Of course the project is somewhat complicated, so it is not a simple
wc
command.
a
I don't know such tool, but you may write a simple Gradle task that will count LOC (for example) and measure ratio between commonMain and other source sets. Something like this:
Copy code
tasks.register("measureCommonMainPercentage") {
    doLast {
        var totalMainCodeLength = 0L
        var commonMainCodeLength = 0L
        for (sourceSet in kotlin.sourceSets) {
            sourceSet.name.endsWith("Test") && continue
            val sourceSetLoc = sourceSet.kotlin.sourceDirectories.asFileTree.files.sumOf { it.length() }
            if (sourceSet.name == "commonMain") commonMainCodeLength = sourceSetLoc
            totalMainCodeLength += sourceSetLoc
        }

        println("Common Main Percentage: ${commonMainCodeLength*100 / totalMainCodeLength}")
    }
}
of course this is just an illustration.
thank you color 1
t
Thanks. I might try to add this to my Gradle plugin and calculate some statistics for each module and then summarize.
a
You may also try using tools that calculate LOCs more accurately with different statistic that you may be interested in. my sample was just an illustration of how you can iterate through Kotlin Source Sets and apply some metrics.
t
I couldn't resist, my most platform heavy module us 71% (actual UI fragments), my UI widgets module is 97%. And I think SVG, strings etc is in it atm.
🔥 1
Thanks, this is quite fine for now, I don't need better for a while if ever I think.