bzip2/install_links.py
Dylan Baker ab22254684 Meson: install symlinks or copies of binaries
On most system symlinks are fine, but on windows symlinks are tricky at
best, or unsupported for older versions of windows. To avoid those
problems we'll just copy the binary if the host or build machine is
windows. This uses a small helper python script to make this all
easier to use and understand.
2019-07-01 14:53:21 -07:00

41 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python3
"""Create a symlink or a copy of an installed file."""
import argparse
import os
import shutil
def main():
parser = argparse.ArgumentParser()
parser.add_argument('bindir')
parser.add_argument('source')
parser.add_argument('dest', nargs='+')
parser.add_argument('--use-links', action='store_true')
args = parser.parse_args()
os.chdir(os.environ['MESON_INSTALL_DESTDIR_PREFIX'])
os.chdir(args.bindir)
# Windows doesn't really use symlinks, just copy in that case. Windows
# before vista (xp) doesn't have symlinks at all.
if args.use_links:
func = os.symlink
verb = 'Linking'
else:
func = shutil.copy
verb = 'Copying'
# at least os.symlink will fail if the destination already exists, just
# remove the dest if it already exists.
for dest in args.dest:
if os.path.exists(dest):
os.unlink(dest)
func(args.source, dest)
print('{} {} to {}'.format(verb, args.source, dest))
if __name__ == "__main__":
main()