Skip to content

Commit

Permalink
Add link check to make sdist.
Browse files Browse the repository at this point in the history
This will cause `make sdist` to fail on platforms which create
hard links of symbolic links as regular files, such as MacOS (Darwin).

This prevents accidental creation of an sdist tarball without
the necessary symbolic links.
  • Loading branch information
mattclay committed Oct 12, 2018
1 parent e43869c commit 19c0511
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ install_manpages:
gzip -9 $(wildcard ./docs/man/man1/ansible*.1)
cp $(wildcard ./docs/man/man1/ansible*.1.gz) $(PREFIX)/man/man1/

.PHONY: sdist_check
sdist_check:
$(PYTHON) packaging/sdist/check-link-behavior.py

.PHONY: sdist
sdist: clean docs
sdist: sdist_check clean docs
$(PYTHON) setup.py sdist

.PHONY: sdist_upload
Expand Down
51 changes: 51 additions & 0 deletions packaging/sdist/check-link-behavior.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python
"""Checks for link behavior required for sdist to retain symlinks."""

from __future__ import (absolute_import, division, print_function)

__metaclass__ = type

import os
import platform
import shutil
import sys
import tempfile


def main():
"""Main program entry point."""
temp_dir = tempfile.mkdtemp()

target_path = os.path.join(temp_dir, 'file.txt')
symlink_path = os.path.join(temp_dir, 'symlink.txt')
hardlink_path = os.path.join(temp_dir, 'hardlink.txt')

try:
with open(target_path, 'w'):
pass

os.symlink(target_path, symlink_path)
os.link(symlink_path, hardlink_path)

if not os.path.islink(symlink_path):
abort('Symbolic link not created.')

if not os.path.islink(hardlink_path):
# known issue on MacOS (Darwin)
abort('Hard link of symbolic link created as a regular file.')
finally:
shutil.rmtree(temp_dir)


def abort(reason):
"""
:type reason: str
"""
sys.exit('ERROR: %s\n'
'This will prevent symbolic links from being preserved in the resulting tarball.\n'
'Aborting creation of sdist on platform: %s'
% (reason, platform.system()))


if __name__ == '__main__':
main()

0 comments on commit 19c0511

Please sign in to comment.