quaint-telephone-89068
12/09/2022, 5:14 AM./pants package (and particularly packaging pex_binary) doesn't handle updating dist/ when export has changed from a file to a directory, or vice versa, and the old form still exists in dist/.
This can occur if ./pants package has been run to export a pex_binary(layout="zipapp") to dist/ in the past, and then the target is updated to pex_binary(layout="packed") and packaged again, without clearing dist/.
Preferably pants would overwrite the existing dist/ entry harder, so the switch is transparent.
Reproducer: https://gist.github.com/huonw/5cc8fcc78bfbaad05209bfb2fd55ac2a (Output marked by #>)
(_edit_: see #17758 (comment) below for a less fiddly version using export-codegen and experimental_shell_command)
git clone <mailto:git@gist.github.com|git@gist.github.com>:5cc8fcc78bfbaad05209bfb2fd55ac2a.git
cd 5cc8fcc78bfbaad05209bfb2fd55ac2a
# first: file replaced by a directory
./pants package ::
file dist/pex.pex
#> dist/pex.pex: Zip archive data, ...
# switch to packed layout
sed -i '' 's/# layout/layout/' BUILD
# BUG:
./pants package ::
#> Exception: Error opening file .../dist/pex.pex/.bootstrap for writing: Os { code: 20, kind: NotADirectory, message: "Not a directory" }
# second: directory replaced by a file
rm -rf dist/
./pants package ::
file dist/pex.pex
#> dist/pex.pex: directory
# switch back
sed -i '' 's/layout/# layout/' BUILD
# BUG:
./pants package ::
#> Exception: Error opening file .../dist/pex.pex for writing: Os { code: 21, kind: IsADirectory, message: "Is a directory" }
Pants version
2.14.0, 2.16.0.dev0
OS
macOS
Additional info
https://gist.github.com/huonw/5cc8fcc78bfbaad05209bfb2fd55ac2a
pantsbuild/pants