From 59edd88d0e0c11123ef900a669c1e53728eeb999 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Mon, 30 Sep 2024 19:20:54 +0100 Subject: [PATCH] Add build directory existence check in compile scripts for Swift projects. --- compiled_starters/swift/.codecrafters/compile.sh | 14 ++++++++++++++ compiled_starters/swift/your_program.sh | 10 ++++++++++ .../swift/01-jm1/code/.codecrafters/compile.sh | 14 ++++++++++++++ solutions/swift/01-jm1/code/your_program.sh | 10 ++++++++++ .../swift/code/.codecrafters/compile.sh | 14 ++++++++++++++ 5 files changed, 62 insertions(+) diff --git a/compiled_starters/swift/.codecrafters/compile.sh b/compiled_starters/swift/.codecrafters/compile.sh index 3eabd63..5b1db13 100755 --- a/compiled_starters/swift/.codecrafters/compile.sh +++ b/compiled_starters/swift/.codecrafters/compile.sh @@ -8,4 +8,18 @@ set -e # Exit on failure +# Check if the build directory exists +if [ -d "/tmp/codecrafters-build-redis-swift" ]; then + echo "Build directory already exists. Proceeding with the build..." + + # This does NOT trigger a rebuild + mv /tmp/codecrafters-build-redis-swift /tmp/codecrafters-build-redis-swift-old + mv /tmp/codecrafters-build-redis-swift-old /tmp/codecrafters-build-redis-swift + + # This DOES trigger a rebuild! inode changes? + # cp -R /tmp/codecrafters-build-redis-swift-old /tmp/codecrafters-build-redis-swift +else + echo "Build directory does not exist." +fi + swift build -c release --build-path /tmp/codecrafters-build-redis-swift diff --git a/compiled_starters/swift/your_program.sh b/compiled_starters/swift/your_program.sh index 1406cde..5b5eb13 100755 --- a/compiled_starters/swift/your_program.sh +++ b/compiled_starters/swift/your_program.sh @@ -14,6 +14,16 @@ set -e # Exit early if any commands fail # - Edit .codecrafters/compile.sh to change how your program compiles remotely ( cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory + if [ -d "/tmp/codecrafters-build-redis-swift" ]; then + echo "Build directory already exists. Proceeding with the build..." + # This does NOT trigger a rebuild + mv /tmp/codecrafters-build-redis-swift /tmp/codecrafters-build-redis-swift-old + mv /tmp/codecrafters-build-redis-swift-old /tmp/codecrafters-build-redis-swift + # This DOES trigger a rebuild! inode changes? + # cp -R /tmp/codecrafters-build-redis-swift-old /tmp/codecrafters-build-redis-swift + else + echo "Build directory does not exist." + fi swift build -c release --build-path /tmp/codecrafters-build-redis-swift ) diff --git a/solutions/swift/01-jm1/code/.codecrafters/compile.sh b/solutions/swift/01-jm1/code/.codecrafters/compile.sh index 3eabd63..5b1db13 100755 --- a/solutions/swift/01-jm1/code/.codecrafters/compile.sh +++ b/solutions/swift/01-jm1/code/.codecrafters/compile.sh @@ -8,4 +8,18 @@ set -e # Exit on failure +# Check if the build directory exists +if [ -d "/tmp/codecrafters-build-redis-swift" ]; then + echo "Build directory already exists. Proceeding with the build..." + + # This does NOT trigger a rebuild + mv /tmp/codecrafters-build-redis-swift /tmp/codecrafters-build-redis-swift-old + mv /tmp/codecrafters-build-redis-swift-old /tmp/codecrafters-build-redis-swift + + # This DOES trigger a rebuild! inode changes? + # cp -R /tmp/codecrafters-build-redis-swift-old /tmp/codecrafters-build-redis-swift +else + echo "Build directory does not exist." +fi + swift build -c release --build-path /tmp/codecrafters-build-redis-swift diff --git a/solutions/swift/01-jm1/code/your_program.sh b/solutions/swift/01-jm1/code/your_program.sh index 1406cde..5b5eb13 100755 --- a/solutions/swift/01-jm1/code/your_program.sh +++ b/solutions/swift/01-jm1/code/your_program.sh @@ -14,6 +14,16 @@ set -e # Exit early if any commands fail # - Edit .codecrafters/compile.sh to change how your program compiles remotely ( cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory + if [ -d "/tmp/codecrafters-build-redis-swift" ]; then + echo "Build directory already exists. Proceeding with the build..." + # This does NOT trigger a rebuild + mv /tmp/codecrafters-build-redis-swift /tmp/codecrafters-build-redis-swift-old + mv /tmp/codecrafters-build-redis-swift-old /tmp/codecrafters-build-redis-swift + # This DOES trigger a rebuild! inode changes? + # cp -R /tmp/codecrafters-build-redis-swift-old /tmp/codecrafters-build-redis-swift + else + echo "Build directory does not exist." + fi swift build -c release --build-path /tmp/codecrafters-build-redis-swift ) diff --git a/starter_templates/swift/code/.codecrafters/compile.sh b/starter_templates/swift/code/.codecrafters/compile.sh index 3eabd63..5b1db13 100755 --- a/starter_templates/swift/code/.codecrafters/compile.sh +++ b/starter_templates/swift/code/.codecrafters/compile.sh @@ -8,4 +8,18 @@ set -e # Exit on failure +# Check if the build directory exists +if [ -d "/tmp/codecrafters-build-redis-swift" ]; then + echo "Build directory already exists. Proceeding with the build..." + + # This does NOT trigger a rebuild + mv /tmp/codecrafters-build-redis-swift /tmp/codecrafters-build-redis-swift-old + mv /tmp/codecrafters-build-redis-swift-old /tmp/codecrafters-build-redis-swift + + # This DOES trigger a rebuild! inode changes? + # cp -R /tmp/codecrafters-build-redis-swift-old /tmp/codecrafters-build-redis-swift +else + echo "Build directory does not exist." +fi + swift build -c release --build-path /tmp/codecrafters-build-redis-swift