From baf50821d349fcd54d2617c034f035b68d76844d Mon Sep 17 00:00:00 2001 From: alexander-yevsyukov Date: Fri, 1 Nov 2024 17:12:13 +0000 Subject: [PATCH 1/2] Fix not-ignoring `build` dirs under `src` --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5ceea721..abace8fa 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ # Gradle build files **/build/** +!**/src/**/build/** # Do not ignore `build` dependency objects under `buildSrc`. !**/buildSrc/src/main/kotlin/io/spine/dependency/build/** From 182cbc5bdf77cbf16e42eb2a2d3d5342c32a6422 Mon Sep 17 00:00:00 2001 From: alexander-yevsyukov Date: Fri, 1 Nov 2024 18:13:20 +0000 Subject: [PATCH 2/2] Update `.gitignore` when migrating `buildSrc` Also: * Improve filtering of dirs. --- scripts/buildSrc-migration.kts | 62 +++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/scripts/buildSrc-migration.kts b/scripts/buildSrc-migration.kts index 69c2569b..f4d80f12 100644 --- a/scripts/buildSrc-migration.kts +++ b/scripts/buildSrc-migration.kts @@ -164,7 +164,7 @@ private val packages = buildMap { /** * Directories to be excluded from the traversal. */ -private val excludedDirs = setOf( +private val excludedTopLevelDirs = setOf( ".git", ".github", ".github-workflows", @@ -177,13 +177,24 @@ private val excludedDirs = setOf( "config" ) +private val excludedPaths = setOf( + "buildSrc/.gradle", + "buildSrc/build", + "scripts/publish-documentation/buildSrc", +) + /** - * Excludes top-level project directory names from the traversal. + * Excludes from the traversal directories that should not be processed. + * + * 1. Top-level project directory with the names listed in [excludedTopLevelDirs]. + * 2. `scripts/publish-documentation/buildSrc` directory, which is a symlink. */ private val File.isExcluded: Boolean - get() = if (parent == ".") - name in excludedDirs - else false + get() = if (parent == ".") { + name in excludedTopLevelDirs + } else { + excludedPaths.any { path.contains(it) } + } /** * Extensions of files to be processed. @@ -203,8 +214,8 @@ fun applyDependencyReplacements() { } .filter { it.isFile && it.extension in extensions } .forEach { - val outcome = it.applyDependencyReplacements(allReplacements) - if (outcome) { + val fileUpdated = it.applyDependencyReplacements(allReplacements) + if (fileUpdated) { println(" ${it.name} -> Modified.") } } @@ -233,4 +244,39 @@ private fun File.applyDependencyReplacements(map: Map): Boolean return anythingReplaced } -applyDependencyReplacements() +private fun fixNotIgnoringBuildDirs() { + val gitIgnore = File(".gitignore") + val text = gitIgnore.readText() + val nl = System.lineSeparator() + + val buildDirectories = "!**/src/**/build/" + val includeBuildDirs = "$buildDirectories$nl" + val includeBuildDirFiles = "$buildDirectories**$nl" + + if (text.contains(includeBuildDirFiles)) { + // Already processed. + return + } + + val updatedText = if (text.contains(includeBuildDirs)) { + text.replace( + includeBuildDirs, + "$buildDirectories**$nl" + ) + } else { + val ignoreFilesUnderBuild = "**/build/**$nl" + text.replace( + ignoreFilesUnderBuild, + "$ignoreFilesUnderBuild$includeBuildDirFiles" + ) + } + + gitIgnore.writeText(updatedText) +} + +fun main() { + applyDependencyReplacements() + fixNotIgnoringBuildDirs() +} + +main()