Problem
The current stub.sh generator script fails to run correctly on certain platforms:
- Windows: Requires CRLF line endings for the Batch portion of the polyglot script
- macOS: Newer versions require a valid shebang
Context
The original polyglot script was generated via sbt-assembly's defaultUniversalScript, which handled mixed line endings and shebang injection.
Having a stub.sh with mixed line endings is not possible because of Git line endings normalization.
Proposed Solution
The stub should be generated dynamically during the build process using a Bazel genrule. This allows to explicitly write CRLF bytes for the Windows section while keeping LF for the Unix section.
- Create a
stub genrule: This rule constructs the script line-by-line, enforcing the correct line endings.
genrule(
name = "stub",
outs = ["stub.sh"],
cmd = """
printf '#!/usr/bin/env sh\n' > $@
printf '@ 2>/dev/null # 2>nul & echo off & goto BOF\n' >> $@
printf ':\n' >> $@
printf 'exec java -jar $${JAVA_OPTS:-} "$$0" "$$@"\n' >> $@
printf 'exit\n' >> $@
printf '\n' >> $@
printf ':BOF\r\n' >> $@
printf '@echo off\r\n' >> $@
printf 'java -jar %%JAVA_OPTS%% "%%~dpnx0" %%*\r\n' >> $@
printf 'exit /B %%errorlevel%%\r\n' >> $@
""",
)
- Update the
generator rule: Depend on the generated stub and concatenate it with the deploy jar.
genrule(
name = "generator",
srcs = [":stub", "//src:djinni_deploy.jar"],
outs = ["djinni"],
cmd = "cat $(location :stub) $(location //src:djinni_deploy.jar) > $@ && chmod +x $@",
executable = True
)
If this solution is appropriate, I can provide a pull request with the changes.
Problem
The current
stub.shgenerator script fails to run correctly on certain platforms:Context
The original polyglot script was generated via sbt-assembly's
defaultUniversalScript, which handled mixed line endings and shebang injection.Having a
stub.shwith mixed line endings is not possible because of Git line endings normalization.Proposed Solution
The stub should be generated dynamically during the build process using a Bazel
genrule. This allows to explicitly write CRLF bytes for the Windows section while keeping LF for the Unix section.stubgenrule: This rule constructs the script line-by-line, enforcing the correct line endings.generatorrule: Depend on the generated stub and concatenate it with the deploy jar.If this solution is appropriate, I can provide a pull request with the changes.