Changeset 79793
- Timestamp:
- 06/25/11 20:15:55 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gsoc11-post-destroot/base/src/port1.0/portcheckdestroot.tcl
r79576 r79793 12 12 namespace eval portcheckdestroot { 13 13 } 14 15 14 #options 16 15 options destroot.violate_mtree destroot.asroot depends_lib … … 35 34 } 36 35 36 # Check if a file is binary file 37 # TODO: Somewhat probabilistic. Must be a better way. 38 proc portcheckdestroot::binary? filename { 39 set f [open $filename] 40 set data [read $f 1024] 41 close $f 42 expr {[string first \x00 $data]>=0} 43 } 44 45 46 # escape chars in order to be usable as regexp. This function is for internal use. 47 proc portcheckdestroot::escape_chars {str} { 48 return [regsub {\+} $str {\+}] 49 } 50 37 51 # List all links on a directory recursively. This function is for internal use. 38 52 proc portcheckdestroot::links_list {dir} { … … 40 54 } 41 55 42 # List all links on a directory recursively. This function is for internal use. 56 # List all binary files on a directory recursively. This function is for internal use. 57 proc portcheckdestroot::bin_list {dir} { 58 return [types_list $dir "f" 1] 59 } 60 61 # List all files on a directory recursively. This function is for internal use. 43 62 proc portcheckdestroot::files_list {dir} { 44 63 return [types_list $dir "f"] … … 46 65 47 66 # List all files of a type on a directory recursively. This function is for internal use. 48 proc portcheckdestroot::types_list {dir type } {67 proc portcheckdestroot::types_list {dir type {bin 0} } { 49 68 set ret {} 50 69 foreach item [glob -nocomplain -type "d $type" -directory $dir *] { … … 53 72 } else { 54 73 #is from the correct type 55 lappend ret $item 74 if { $bin } { 75 if { [binary? $item] } { 76 lappend ret $item 77 } 78 } else { 79 lappend ret $item 80 } 56 81 } 57 82 } … … 200 225 # Check for dynamic links that aren't in the dependency list 201 226 proc portcheckdestroot::checkdestroot_libs {} { 202 global destroot destroot.depends_lib subport depends_lib UI_PREFIX227 global destroot prefix UI_PREFIX subport 203 228 ui_notice "$UI_PREFIX Checking for wrong dynamic links" 204 229 205 #F iles that don't need to be alerted if not on dependencies.206 #TODO: Compile these files (and move for configuration folder?)207 set dep_whitelist {/usr/lib/ libSystem.B.dylib}230 #Folders that don't need to be alerted if not on dependencies. 231 #TODO: Compile whitelist folders 232 set dep_whitelist {/usr/lib/ /System/Library/ /lib/} 208 233 209 234 #Get dependencies files list. … … 212 237 lappend dep_files [get_files [exec port contents $dep]] 213 238 } 214 set dep_files [concat $dep_files $dep_whitelist] 239 set self_files [bin_list $destroot$prefix] 240 set dep_files [concat $dep_files $self_files] 215 241 216 242 #Get package files 217 243 foreach file [files_list $destroot] { 218 if { [ file executable"$file"] } {244 if { [binary? "$file"] } { 219 245 #Check it dinamic links with otool 220 foreach line [split [exec -keepnewline otool -L $file] "\n"] { 221 #match they with dependency files 222 if { [regexp {\(.*} $line] } { 223 set lib [string trim [regsub {\(.*} $line ""]] 224 if { [regexp $lib $file] } { 225 ui_debug "skipping, should be the file itself" 226 } else { 227 if { [regexp $lib [join $dep_files]] } { 228 ui_debug "$lib binary dependency is met" 246 set otool_output [get_otool_libs $file] 247 if { $otool_output == "ignore" } { 248 ui_debug "Ignoring $file otool output" 249 } else { 250 foreach line [get_otool_libs $file] { 251 #match they with dependency files 252 if { [regexp {\(.*} $line] } { 253 set lib [string trim [regsub {\(.*} $line ""]] 254 #match against itself 255 if { [regexp [escape_chars $lib] $file] } { 256 ui_debug "skipping, should be the file itself" 229 257 } else { 230 return -code error "$lib binary dependencies are NOT met" 258 #match against dependencies or self files 259 if { [regexp [escape_chars $lib] [join $dep_files]] } { 260 ui_debug "$lib binary dependency is met" 261 } else { 262 #match file folder agains whitelist 263 set found 0 264 foreach dep $dep_whitelist { 265 if { [regexp "^$dep" [regsub $prefix $lib ""]] } { 266 set found 1 267 break 268 } 269 } 270 if { $found } { 271 ui_debug "$lib binary dependency folder is on whitelist" 272 } else { 273 return -code error "$lib binary dependencies are NOT met" 274 } 275 } 231 276 } 232 277 } … … 241 286 global destroot 242 287 foreach file [files_list $destroot] { 243 if { [ file executable"$file"] } {244 set lipo_arches [ checkdestroot_get_lipo_arches $file]288 if { [binary? "$file"] } { 289 set lipo_arches [get_lipo_arches $file] 245 290 # Chekcs if every arch is present on the lipo output 246 foreach arch $archs { 247 if { [regexp $arch $lipo_arches] == 0 } { 248 return -code error "$file supports the arch $arch, and should not" 291 if { $lipo_arches == "ignore" } { 292 ui_debug "Ignoring arch check for $file" 293 } else { 294 foreach arch $archs { 295 if { [regexp $arch $lipo_arches] == 0 } { 296 return -code error "$file supports the arch $arch, and should not" 297 } 249 298 } 250 299 } … … 254 303 255 304 # Recover the arches from a file, from it's lipo output. For internal use only. 256 proc portcheckdestroot::checkdestroot_get_lipo_arches { file } { 257 set lipo_output [exec lipo -info $file] 305 proc portcheckdestroot::get_lipo_arches { file } { 306 if { [ catch { set lipo_output [exec lipo -info $file 2>/dev/null] } ] } { 307 return "ignore" 308 } 258 309 return [regsub "Architectures in the.*are:" $lipo_output ""] 310 } 311 312 # Recover the arches from a file, from it's lipo output. For internal use only. 313 proc portcheckdestroot::get_otool_libs { file } { 314 if { [ catch { set output [exec -keepnewline otool -L $file 2>/dev/null] } ] } { 315 return "ignore" 316 } 317 return [split $output "\n"] 259 318 } 260 319
Note: See TracChangeset
for help on using the changeset viewer.

