[AMDGPU] prevent shrinking udiv/urem if either operand is in (SignedMax,UnsignedMax...
[llvm-project.git] / llvm / utils / gn / build / symlink_or_copy.py
blobd586b8904a41b65b1e36cf6ff3e9633f58c8a585
1 #!/usr/bin/env python3
3 """Symlinks, or on Windows copies, an existing file to a second location.
5 Overwrites the target location if it exists.
6 Updates the mtime on a stamp file when done."""
8 import argparse
9 import errno
10 import os
11 import sys
14 def main():
15 parser = argparse.ArgumentParser(
16 description=__doc__,
17 formatter_class=argparse.RawDescriptionHelpFormatter)
18 parser.add_argument(
19 "--stamp", required=True, help="name of a file whose mtime is updated on run"
21 parser.add_argument("source")
22 parser.add_argument("output")
23 args = parser.parse_args()
25 # FIXME: This should not check the host platform but the target platform
26 # (which needs to be passed in as an arg), for cross builds.
27 if sys.platform != "win32":
28 try:
29 os.makedirs(os.path.dirname(args.output))
30 except OSError as e:
31 if e.errno != errno.EEXIST:
32 raise
33 try:
34 os.symlink(args.source, args.output)
35 except OSError as e:
36 if e.errno == errno.EEXIST:
37 os.remove(args.output)
38 os.symlink(args.source, args.output)
39 else:
40 raise
41 else:
42 import shutil
44 output = args.output + ".exe"
45 source = args.source + ".exe"
46 shutil.copyfile(os.path.join(os.path.dirname(output), source), output)
48 open(args.stamp, "w") # Update mtime on stamp file.
51 if __name__ == "__main__":
52 sys.exit(main())