Skip to content

Commit 825bc8b

Browse files
committed
Use symlinks instead of moving build directory
sbt relies on stable paths for its incremental compilation cache. The buildpack previously moved the entire build directory to a temporary location to provide a stable path, then moved it back at the end. This change replaces the expensive move operations with a symlink, providing the same stable path for sbt while keeping files in their original location. This eliminates the need to rewrite PATH and GEM_PATH variables to account for the directory move.
1 parent ad380bf commit 825bc8b

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed

bin/compile

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,11 @@ metrics::setup
3434

3535
if is_app_dir "${APP_BUILD_DIR}"; then
3636
BUILD_DIR="/tmp/scala_buildpack_build_dir"
37-
mv "${APP_BUILD_DIR}" "${BUILD_DIR}"
37+
ln -s "${APP_BUILD_DIR}" "${BUILD_DIR}"
3838
else
3939
BUILD_DIR="${APP_BUILD_DIR}"
4040
fi
4141

42-
# When multiple buildpacks are used, earlier buildpacks may add executables to PATH
43-
# and GEM_PATH that reference APP_BUILD_DIR. Since we've moved the build directory to
44-
# a temp location, we must rewrite these environment variables to replace APP_BUILD_DIR
45-
# with the new BUILD_DIR so that executables added by earlier buildpacks remain accessible.
46-
PATH=${PATH//"${APP_BUILD_DIR}"/"${BUILD_DIR}"}
47-
export PATH
48-
if [[ -n "${GEM_PATH:-}" ]]; then
49-
GEM_PATH=${GEM_PATH//"${APP_BUILD_DIR}"/"${BUILD_DIR}"}
50-
export GEM_PATH
51-
fi
52-
5342
util::export_env_dir "${ENV_DIR}" "." "JAVA_OPTS"
5443

5544
# Used by openjdk::install_openjdk_via_jvm_common_buildpack to determine which JVM common buildpack to use
@@ -277,9 +266,9 @@ cat <<-EOF >"${profile_script}"
277266
export PATH="\$SBT_HOME/bin:\$PATH"
278267
EOF
279268

280-
# Move compiled app back to where Heroku expects it
269+
# Remove symlink if we created one
281270
if is_app_dir "${APP_BUILD_DIR}"; then
282-
mv "${BUILD_DIR}" "${APP_BUILD_DIR}"
271+
rm "${BUILD_DIR}"
283272
fi
284273

285274
# write export script

test/spec/cache_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@
1313
remote: -----> Running: sbt compile stage
1414
remote: Downloading sbt launcher for 1.11.7:
1515
remote: From https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/1.11.7/sbt-launch-1.11.7.jar
16-
remote: To /tmp/scala_buildpack_build_dir/.sbt_home/launchers/1.11.7/sbt-launch.jar
16+
remote: To /tmp/[^/]+/.sbt_home/launchers/1.11.7/sbt-launch.jar
1717
remote: Downloading sbt launcher 1.11.7 md5 hash:
1818
remote: From https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/1.11.7/sbt-launch-1.11.7.jar.md5
19-
remote: To /tmp/scala_buildpack_build_dir/.sbt_home/launchers/1.11.7/sbt-launch.jar.md5
20-
remote: /tmp/scala_buildpack_build_dir/.sbt_home/launchers/1.11.7/sbt-launch.jar: OK
19+
remote: To /tmp/[^/]+/.sbt_home/launchers/1.11.7/sbt-launch.jar.md5
20+
remote: /tmp/[^/]+/.sbt_home/launchers/1.11.7/sbt-launch.jar: OK
2121
remote: \\[info\\] \\[launcher\\] getting org.scala-sbt sbt 1.11.7 \\(this may take some time\\)...
2222
remote: \\[info\\] \\[launcher\\] getting Scala 2.12.20 \\(for sbt\\)...
2323
remote: \\[info\\] welcome to sbt 1.11.7 \\(Azul Systems, Inc. Java 21.0.[0-9]+\\)
24-
remote: \\[info\\] loading global plugins from /tmp/scala_buildpack_build_dir/.sbt_home/plugins
25-
remote: \\[info\\] compiling 1 Scala source to /tmp/scala_buildpack_build_dir/.sbt_home/plugins/target/scala-2.12/sbt-1.0/classes ...
24+
remote: \\[info\\] loading global plugins from /tmp/[^/]+/.sbt_home/plugins
25+
remote: \\[info\\] compiling 1 Scala source to /tmp/[^/]+/.sbt_home/plugins/target/scala-2.12/sbt-1.0/classes ...
2626
remote: \\[info\\] Non-compiled module 'compiler-bridge_2.12' for Scala 2.12.20. Compiling...
2727
remote: \\[info\\] Compilation completed in .*s.
2828
remote: \\[info\\] done compiling
29-
remote: \\[info\\] loading settings for project scala_buildpack_build_dir-build from plugins.sbt...
30-
remote: \\[info\\] loading project definition from /tmp/scala_buildpack_build_dir/project
29+
remote: \\[info\\] loading settings for project [^\\s]+-build from plugins.sbt...
30+
remote: \\[info\\] loading project definition from /tmp/[^/]+/project
3131
remote: \\[info\\] loading settings for project root from build.sbt...
3232
remote: \\[info\\] __ __
3333
remote: \\[info\\] \\\\ \\\\ ____ / /____ _ __ __
@@ -42,10 +42,10 @@
4242
remote: \\[info\\] https://www.playframework.com/sponsors
4343
remote: \\[info\\]
4444
remote: \\[info\\] Executing in batch mode. For better performance use sbt's shell
45-
remote: \\[info\\] compiling 7 Scala sources and 1 Java source to /tmp/scala_buildpack_build_dir/target/scala-2.13/classes ...
45+
remote: \\[info\\] compiling 7 Scala sources and 1 Java source to /tmp/[^/]+/target/scala-2.13/classes ...
4646
remote: \\[info\\] done compiling
4747
remote: \\[success\\] Total time: .* s, completed .*
48-
remote: \\[info\\] Wrote /tmp/scala_buildpack_build_dir/target/scala-2.13/sbt-0-11-7-play-3-x-scala-2-13-x_2.13-1.0-SNAPSHOT.pom
48+
remote: \\[info\\] Wrote /tmp/[^/]+/target/scala-2.13/sbt-0-11-7-play-3-x-scala-2-13-x_2.13-1.0-SNAPSHOT.pom
4949
remote: \\[success\\] Total time: .*
5050
remote: -----> Collecting dependency information
5151
remote: -----> Dropping ivy cache from the slug
@@ -68,9 +68,9 @@
6868
remote: -----> Installing Azul Zulu OpenJDK 21.0.[0-9]+
6969
remote: -----> Running: sbt compile stage
7070
remote: \\[info\\] welcome to sbt 1.11.7 \\(Azul Systems, Inc. Java 21.0.[0-9]+\\)
71-
remote: \\[info\\] loading global plugins from /tmp/scala_buildpack_build_dir/.sbt_home/plugins
72-
remote: \\[info\\] loading settings for project scala_buildpack_build_dir-build from plugins.sbt...
73-
remote: \\[info\\] loading project definition from /tmp/scala_buildpack_build_dir/project
71+
remote: \\[info\\] loading global plugins from /tmp/[^/]+/.sbt_home/plugins
72+
remote: \\[info\\] loading settings for project [^\\s]+-build from plugins.sbt...
73+
remote: \\[info\\] loading project definition from /tmp/[^/]+/project
7474
remote: \\[info\\] loading settings for project root from build.sbt...
7575
remote: \\[info\\] __ __
7676
remote: \\[info\\] \\\\ \\\\ ____ / /____ _ __ __
@@ -86,7 +86,7 @@
8686
remote: \\[info\\]
8787
remote: \\[info\\] Executing in batch mode. For better performance use sbt's shell
8888
remote: \\[success\\] Total time: .* s, completed .*
89-
remote: \\[info\\] Wrote /tmp/scala_buildpack_build_dir/target/scala-2.13/sbt-0-11-7-play-3-x-scala-2-13-x_2.13-1.0-SNAPSHOT.pom
89+
remote: \\[info\\] Wrote /tmp/[^/]+/target/scala-2.13/sbt-0-11-7-play-3-x-scala-2-13-x_2.13-1.0-SNAPSHOT.pom
9090
remote: \\[success\\] Total time: .*
9191
remote: -----> Collecting dependency information
9292
remote: -----> Dropping ivy cache from the slug

0 commit comments

Comments
 (0)