New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Changeset 79793


Ignore:
Timestamp:
06/25/11 20:15:55 (4 years ago)
Author:
fotanus@…
Message:

Tested agains real ports and fixed broken checks

Major changes:

  • Add self files to check for dynamic library
  • Get errors form lipo and otool output
  • Change whitelist to work with directories
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gsoc11-post-destroot/base/src/port1.0/portcheckdestroot.tcl

    r79576 r79793  
    1212namespace eval portcheckdestroot { 
    1313} 
    14  
    1514#options 
    1615options destroot.violate_mtree destroot.asroot depends_lib 
     
    3534} 
    3635 
     36# Check if a file is binary file 
     37# TODO: Somewhat probabilistic. Must be a better way. 
     38proc 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. 
     47proc portcheckdestroot::escape_chars {str} { 
     48    return [regsub {\+} $str {\+}] 
     49} 
     50 
    3751# List all links on a directory recursively. This function is for internal use. 
    3852proc portcheckdestroot::links_list {dir} { 
     
    4054} 
    4155 
    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. 
     57proc 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. 
    4362proc portcheckdestroot::files_list {dir} { 
    4463    return [types_list $dir "f"] 
     
    4665 
    4766# List all files of a type on a directory recursively. This function is for internal use. 
    48 proc portcheckdestroot::types_list {dir type} { 
     67proc portcheckdestroot::types_list {dir type {bin 0} } { 
    4968    set ret {} 
    5069    foreach item [glob -nocomplain -type "d $type" -directory $dir *] { 
     
    5372        } else { 
    5473            #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            } 
    5681        } 
    5782    } 
     
    200225# Check for dynamic links that aren't in the dependency list 
    201226proc portcheckdestroot::checkdestroot_libs {} { 
    202     global destroot destroot.depends_lib subport depends_lib UI_PREFIX 
     227    global destroot prefix UI_PREFIX subport 
    203228    ui_notice "$UI_PREFIX Checking for wrong dynamic links" 
    204229 
    205     #Files 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/} 
    208233 
    209234    #Get dependencies files list. 
     
    212237        lappend dep_files [get_files [exec port contents $dep]] 
    213238    } 
    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] 
    215241 
    216242    #Get package files 
    217243    foreach file [files_list $destroot] { 
    218         if { [file executable "$file"] } { 
     244        if { [binary? "$file"] } { 
    219245            #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" 
    229257                        } 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                            } 
    231276                        } 
    232277                    } 
     
    241286    global destroot 
    242287    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] 
    245290            # 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                    } 
    249298                } 
    250299            } 
     
    254303 
    255304# 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] 
     305proc portcheckdestroot::get_lipo_arches { file } { 
     306    if { [ catch { set lipo_output [exec lipo -info $file 2>/dev/null] } ] } { 
     307        return "ignore" 
     308    } 
    258309    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. 
     313proc 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"] 
    259318} 
    260319 
Note: See TracChangeset for help on using the changeset viewer.