@@ -9,29 +9,44 @@ load("@aspect_bazel_lib//lib:tar.bzl", "tar_lib")
99# https://salsa.debian.org/md/usrmerge/-/tree/master/debian?ref_type=heads
1010_VALIDATE_SYMLINKS = """\
1111 BEGIN {
12+ # Mapping from root-level path to expected symlink destination.
13+ # Taken from https://github.com/floppym/merge-usr/blob/15dd02207bdee7ca6720d7024e8c0ffdc166ed23/merge-usr#L17-L25
14+ # Note: both /bin and /sbin must point to usr/bin on Debian (sbin is merged into bin).
15+ expected["./bin"] = "usr/bin"
16+ expected["./sbin"] = "usr/bin"
17+ expected["./lib"] = "usr/lib"
18+ expected["./lib32"] = "usr/lib32"
19+ expected["./lib64"] = "usr/lib64"
20+ expected["./libx32"] = "usr/libx32"
1221 prefixes = "./bin|./sbin|./lib|./lib32|./lib64|./libx32"
1322}
1423{
15- if ($0 ~ "^(" prefixes ")" && $0 !~ /type=link/) {
16- VIOLATIONS[$0] = $1
17- next
24+ path = $1
25+ if (path in expected) {
26+ if ($0 !~ /type=link/) {
27+ VIOLATIONS[path] = path " is not a symlink (must link to " expected[path] ")"
28+ } else if (match($0, /link=([^ \\ t]+)/, dest) && dest[1] != expected[path]) {
29+ VIOLATIONS[path] = path " symlinks to '" dest[1] "' instead of '" expected[path] "'"
30+ }
31+ } else if ($0 ~ ("^(" prefixes ")/")) {
32+ VIOLATIONS[path] = path " found under a merged-usr symlink path (should not exist)"
1833 }
1934}
2035END {
2136 for (violation in VIOLATIONS) {
22- print "VIOLATION: " VIOLATIONS[violation] " violates usr-merge convention."
23- print violation
37+ print "VIOLATION: " VIOLATIONS[violation] " violates usr-merge convention."
38+ print violation
2439 }
2540 if (length(VIOLATIONS) > 0) {
2641 exit 1
2742 }
28- print "" > "{validation_output}"
43+ print "" > validation_output_file
2944}
3045
3146"""
3247
3348def _validate_usr_symlink_impl (target , ctx ):
34- if target .label .name .find ("debian13 " ) = = - 1 :
49+ if target .label .name .find ("debian12 " ) ! = - 1 :
3550 return []
3651
3752 if not hasattr (ctx .rule .files , "tars" ):
@@ -61,7 +76,9 @@ def _validate_usr_symlink_impl(target, ctx):
6176 inputs = [output ],
6277 outputs = [validation_output ],
6378 arguments = [
64- _VALIDATE_SYMLINKS .replace ("{validation_output}" , validation_output .path ),
79+ "-v" ,
80+ "validation_output_file=" + validation_output .path ,
81+ _VALIDATE_SYMLINKS ,
6582 output .path ,
6683 ],
6784 mnemonic = "ValidateUsrSymlinks" ,
0 commit comments