-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixhudson.py
56 lines (46 loc) · 1.68 KB
/
fixhudson.py
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
"""
https://gist.github.com/4100575
Usage: python fixhudson.py [path_to_avrtoolchain]
"""
import os
import subprocess
def which(executable):
""" Mimics Linux / Unix Command: which """
from os.path import join, isfile
for path in os.environ['PATH'].split(os.pathsep):
target = join(path, executable)
if isfile(target) or isfile(target + '.exe'):
return path
return None
def strip_avrlibs(path_to_avrtoolchain):
path = os.path.join(path_to_avrtoolchain, "avr/lib")
if not os.path.isdir(path):
return False
for root, dirs, files in os.walk(path):
names = [name for name in files if name.endswith((".o", ".a"))]
if names:
cmd = "avr-strip -g " + " ".join(names)
subprocess.Popen(cmd, cwd=root)
def strip_avr32libs(path_to_avrtoolchain):
path = os.path.join(path_to_avrtoolchain, "avr32/lib")
if not os.path.isdir(path):
return False
for root, dirs, files in os.walk(path):
names = [name for name in files if name.endswith((".o", ".a"))]
if names:
cmd = "avr32-strip -g " + " ".join(names)
subprocess.Popen(cmd, cwd=root)
if __name__ == "__main__":
import sys
if len(sys.argv) == 1:
path_to_avrgcc = which("avr-gcc")
if not path_to_avrgcc:
path_to_avrgcc = which("avr32-gcc")
if not path_to_avrgcc:
sys.exit(1)
path_to_avrtoolchain = os.path.join(path_to_avrgcc, "..")
else:
path_to_avrtoolchain = sys.argv[1]
os.environ["PATH"] += os.pathsep + os.path.join(path_to_avrtoolchain, "bin")
strip_avrlibs(path_to_avrtoolchain)
strip_avr32libs(path_to_avrtoolchain)