author | timothy.murphy@nokia.com |
Tue, 11 May 2010 13:33:47 +0100 | |
branch | fix |
changeset 546 | e6381a1f4952 |
child 549 | d633be326c9f |
permissions | -rw-r--r-- |
546
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
1 |
# |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
2 |
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
3 |
# All rights reserved. |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
4 |
# This component and the accompanying materials are made available |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
6 |
# which accompanies this distribution, and is available |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
8 |
# |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
9 |
# Initial Contributors: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
10 |
# Nokia Corporation - initial contribution. |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
11 |
# |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
12 |
# Contributors: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
13 |
# |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
14 |
# Description: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
15 |
# Minimise the dependencies in a C preprocessor dependency file to |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
16 |
# those that CPP could not find. Then add in an assumption about |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
17 |
# where to find them. Output is assumed to be relevant to only one target |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
18 |
# even if multiple dep files are analysed. |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
19 |
# |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
20 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
21 |
import sys |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
22 |
from optparse import OptionParser |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
23 |
import os |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
24 |
import re |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
25 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
26 |
class NoTargetException(Exception): |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
27 |
pass |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
28 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
29 |
def depcrunch(file,extensions,assume): |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
30 |
target_pattern = r"^\s*(\S+):\s+" |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
31 |
target_re = re.compile(target_pattern) |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
32 |
extension_pattern = "[ \t]([^\/\\ \t]+\.(" + "|".join(["("+ t + ")" for t in extensions]) + "))\\b" |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
33 |
extension_re = re.compile(extension_pattern) |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
34 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
35 |
target = None |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
36 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
37 |
deps = [] |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
38 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
39 |
for l in file.xreadlines(): |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
40 |
l = l.replace("\\","/").rstrip("\n\r") |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
41 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
42 |
if not target: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
43 |
t = target_re.match(l) |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
44 |
if t: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
45 |
target = t.groups()[0] |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
46 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
47 |
m = extension_re.match(l) |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
48 |
if m: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
49 |
deps.append(m.groups()[0]) |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
50 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
51 |
if not target: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
52 |
raise NoTargetException() |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
53 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
54 |
if len(deps) > 0: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
55 |
print "%s: \\" % target |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
56 |
for d in deps[:-1]: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
57 |
print " %s \\" % (assume + "/" + d) |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
58 |
print " %s " % (assume + "/" + deps[-1]) |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
59 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
60 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
61 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
62 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
63 |
## Command Line Interface #################################################### |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
64 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
65 |
parser = OptionParser(prog = "depcrunch", |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
66 |
usage = "%prog [-h | options] [<depfile>]") |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
67 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
68 |
parser.add_option("-e", "--extensions", |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
69 |
action="store", dest="extensions", type='string', help="comma separated list of file extensions of missing files to keep in the crunched dep file.") |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
70 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
71 |
parser.add_option("-a", "--assume", |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
72 |
action="store", dest="assume", type='string', help="when cpp reports missing dependencies, assume that they are in this directory") |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
73 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
74 |
(options, args) = parser.parse_args() |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
75 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
76 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
77 |
if not options.extensions: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
78 |
parser.error("you must specify a comma-separated list of file extensions with the -t option.") |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
79 |
sys.exit(1) |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
80 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
81 |
if not options.assume: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
82 |
parser.error("you must specify an 'assumed directory' for correcting missing dependencies with the -a option.") |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
83 |
sys.exit(1) |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
84 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
85 |
depfilename="stdin" |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
86 |
if len(args) > 0: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
87 |
depfilename=args[0] |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
88 |
file = open(depfilename,"r") |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
89 |
else: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
90 |
file = sys.stdin |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
91 |
try: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
92 |
depcrunch(file,options.extensions.split(","), options.assume) |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
93 |
except NoTargetException,e: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
94 |
sys.stderr.write("Target name not found in dependency file"); |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
95 |
sys.exit(2) |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
96 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
97 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
98 |
if file != sys.stdin: |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
99 |
file.close() |
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
100 |
|
e6381a1f4952
fix tests for resources. Add python dependency manipulation because it's understandable to humans.
timothy.murphy@nokia.com
parents:
diff
changeset
|
101 |
sys.exit(0) |