forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py.in
80 lines (60 loc) · 1.96 KB
/
install.py.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
import argparse
import filecmp
import os
import shutil
subdirs = set()
prefix = None
def needs_install(src, dst):
# Get canonical destination.
dst_full = os.path.join(prefix, dst)
# Check if destination exists.
if not os.path.exists(dst_full):
# Destination doesn't exist -> installation needed.
return True
# Check if files are different.
if filecmp.cmp(src, dst_full, shallow=False):
# Files are the same -> no installation needed.
return False
# File needs to be installed.
return True
def install(src, dst):
global subdirs
# Ensure destination subdirectory exists, creating it if necessary.
subdir = os.path.dirname(dst)
if subdir not in subdirs:
subdir_full = os.path.join(prefix, subdir)
if not os.path.exists(subdir_full):
os.makedirs(subdir_full)
subdirs.add(subdir)
# Install file, if not up to date.
if needs_install(src, dst):
print("[Installing] %s" % dst)
dst_full = os.path.join(prefix, dst)
if os.path.exists(dst_full):
os.remove(dst_full)
shutil.copy2(src, dst_full)
else:
print("[Up to date] %s" % dst)
def main(args):
global prefix
# Set up options.
parser = argparse.ArgumentParser()
parser.add_argument('prefix', type=str, help='Install prefix')
args = parser.parse_args(args)
# Get install prefix.
prefix = args.prefix
# Because Bazel executes us in a strange working directory and not the
# working directory of the user's shell, enforce that the install
# location is an absolute path so that the user is not surprised.
if not os.path.isabs(prefix):
import sys
sys.stderr.write(
"Install prefix must be an absolute path (got %r)\n"
% prefix)
sys.exit(1)
# Execute the install actions.
<<actions>>
if __name__ == "__main__":
import sys
main(sys.argv[1:])