Skip to content

Commit 1535a29

Browse files
committed
Add tidy support for snapshots
This let's us specify exactly which snapshot a given note to update after snapshot is for. Closes #2483
1 parent cb6451c commit 1535a29

File tree

3 files changed

+49
-34
lines changed

3 files changed

+49
-34
lines changed

src/etc/get-snapshot.py

-34
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,6 @@ def unpack_snapshot(triple, dl_path):
3232
tar.close()
3333
shutil.rmtree(download_unpack_base)
3434

35-
def determine_curr_snapshot(triple):
36-
i = 0
37-
platform = get_platform(triple)
38-
39-
found_file = False
40-
found_snap = False
41-
hsh = None
42-
date = None
43-
rev = None
44-
45-
f = open(snapshotfile)
46-
for line in f.readlines():
47-
i += 1
48-
parsed = parse_line(i, line)
49-
if (not parsed): continue
50-
51-
if found_snap and parsed["type"] == "file":
52-
if parsed["platform"] == platform:
53-
hsh = parsed["hash"]
54-
found_file = True
55-
break;
56-
elif parsed["type"] == "snapshot":
57-
date = parsed["date"]
58-
rev = parsed["rev"]
59-
found_snap = True
60-
61-
if not found_snap:
62-
raise Exception("no snapshot entries in file")
63-
64-
if not found_file:
65-
raise Exception("no snapshot file found for platform %s, rev %s" %
66-
(platform, rev))
67-
68-
return full_snapshot_name(date, rev, platform, hsh)
6935

7036
# Main
7137

src/etc/snapshot.py

+38
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,41 @@ def in_tar_name(fn):
194194
shutil.move(file0, file1)
195195

196196
return file1
197+
198+
def determine_curr_snapshot_info(triple):
199+
i = 0
200+
platform = get_platform(triple)
201+
202+
found_file = False
203+
found_snap = False
204+
hsh = None
205+
date = None
206+
rev = None
207+
208+
f = open(snapshotfile)
209+
for line in f.readlines():
210+
i += 1
211+
parsed = parse_line(i, line)
212+
if (not parsed): continue
213+
214+
if found_snap and parsed["type"] == "file":
215+
if parsed["platform"] == platform:
216+
hsh = parsed["hash"]
217+
found_file = True
218+
break;
219+
elif parsed["type"] == "snapshot":
220+
date = parsed["date"]
221+
rev = parsed["rev"]
222+
found_snap = True
223+
224+
if not found_snap:
225+
raise Exception("no snapshot entries in file")
226+
227+
if not found_file:
228+
raise Exception("no snapshot file found for platform %s, rev %s" %
229+
(platform, rev))
230+
231+
return (date, rev, platform, hsh)
232+
233+
def determine_curr_snapshot(triple):
234+
return full_snapshot_name(*determine_curr_snapshot_info(triple))

src/etc/tidy.py

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import sys, fileinput, subprocess, re
55
from licenseck import *
6+
import snapshot
67

78
err=0
89
cols=100
@@ -52,6 +53,16 @@ def do_license_check(name, contents):
5253
match = re.match(r'^.*//\s*(NOTE.*)$', line)
5354
if match:
5455
report_warn(match.group(1))
56+
match = re.match(r'^.*//\s*SNAP\s+(\w+)', line)
57+
if match:
58+
hsh = match.group(1)
59+
a, b, c, phash = snapshot.determine_curr_snapshot_info()
60+
if not phash.startswith(hsh):
61+
report_err("Snapshot out of date: " + line)
62+
else:
63+
if "SNAP" in line:
64+
report_warn("Unmatched SNAP line: " + line)
65+
5566
if (line.find('\t') != -1 and
5667
fileinput.filename().find("Makefile") == -1):
5768
report_err("tab character")

0 commit comments

Comments
 (0)