Skip to content

Commit cbe07b0

Browse files
committed
Unset the DYLD_LIBRARY_PATH env var when running Sorbet
There are cases where a dev environment can set the `DYLD_LIBRARY_PATH` env variable in a way that loads a version of the C++ standard library that is not compatible with the system version of the library used by Sorbet. This will cause Sorbet to generate corrupted JSON if the --print=symbol-table-json flag is passed. Unsetting this environment variable forces Sorbet to default to the system version of the C++ standard library, preventing this bug.
1 parent 107bee8 commit cbe07b0

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

lib/spoom/context/sorbet.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ module Sorbet
99
# Run `bundle exec srb` in this context directory
1010
#: (*String arg, ?sorbet_bin: String?, ?capture_err: bool) -> ExecResult
1111
def srb(*arg, sorbet_bin: nil, capture_err: true)
12+
# If an environment sets the DYLD_LIBRARY_PATH in a way that depends on a version of the C++
13+
# standard library other than the one used by Sorbet, it will cause Sorbet to generate
14+
# corrupted JSON. Unsetting this environment variable forces Sorbet to default to the system
15+
# version of the C++ standard library.
16+
unset_dyld_library_path = "env -u DYLD_LIBRARY_PATH"
17+
1218
res = if sorbet_bin
13-
exec("#{sorbet_bin} #{arg.join(" ")}", capture_err: capture_err)
19+
exec("#{unset_dyld_library_path} #{sorbet_bin} #{arg.join(" ")}", capture_err: capture_err)
1420
else
15-
bundle_exec("srb #{arg.join(" ")}", capture_err: capture_err)
21+
bundle_exec("#{unset_dyld_library_path} srb #{arg.join(" ")}", capture_err: capture_err)
1622
end
1723

1824
case res.exit_code

0 commit comments

Comments
 (0)