@@ -13,6 +13,17 @@ public interface PostBuildHook {
1313
1414 String NONE = "<none>" ;
1515
16+ /// Suppresses the hook to break recursion. A hook like `zunit` runs the test
17+ /// suite, whose integration tests call `App.build`, which would fire the hook
18+ /// again — unbounded recursion. Set as an env var on every hook-spawned child
19+ /// (inherited by all descendants), or as a system property by in-process
20+ /// callers (tests) that must build without re-triggering the hook.
21+ String SKIP_MARKER = "ZB_IN_POST_BUILD_HOOK" ;
22+
23+ static boolean hookSuppressed () {
24+ return Boolean .parseBoolean (System .getenv (SKIP_MARKER )) || Boolean .getBoolean (SKIP_MARKER );
25+ }
26+
1627 static Optional <String > configuredHook () {
1728 var hook = Configuration .POST_BUILD_HOOK .get (NONE );
1829 if (NONE .equals (hook ) || hook .isBlank ()) {
@@ -39,6 +50,7 @@ static void execute(String command, Path sourceDir, Path jarDir, String jarFileN
3950 .inheritIO ()
4051 .directory (Path .of ("." ).toFile ());
4152 var env = processBuilder .environment ();
53+ env .put (SKIP_MARKER , "true" );
4254 env .put ("ZB_JAR_PATH" , jarDir .resolve (jarFileName ).toString ());
4355 env .put ("ZB_SOURCE_DIR" , sourceDir .toString ());
4456 env .put ("ZB_JAR_DIR" , jarDir .toString ());
@@ -59,6 +71,9 @@ static void execute(String command, Path sourceDir, Path jarDir, String jarFileN
5971 }
6072
6173 static void runIfConfigured (Path sourceDir , Path jarDir , String jarFileName ) {
74+ if (hookSuppressed ()) {
75+ return ;
76+ }
6277 configuredHook ().ifPresent (hook -> execute (hook , sourceDir , jarDir , jarFileName ));
6378 }
6479}
0 commit comments