New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Changeset 79576


Ignore:
Timestamp:
06/18/11 19:07:13 (4 years ago)
Author:
fotanus@…
Message:

Added architecture and dynamic library checks

Currently, it uses otool and lipo system calls. We should replace it with
C extensions in order to optimize performance.

File:
1 edited

Legend:

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

    r79307 r79576  
    1414 
    1515#options 
    16 options destroot.violate_mtree destroot.asroot 
     16options destroot.violate_mtree destroot.asroot depends_lib 
    1717 
    1818#defaults 
    1919default destroot.violate_mtree no 
     20default destroot.depends_lib {} 
    2021 
    2122set_ui_prefix 
    22  
    2323 
    2424# Starting procedure from checkdestroot phase. Check for permissions. 
     
    3737# List all links on a directory recursively. This function is for internal use. 
    3838proc portcheckdestroot::links_list {dir} { 
     39    return [types_list $dir "l"] 
     40} 
     41 
     42# List all links on a directory recursively. This function is for internal use. 
     43proc portcheckdestroot::files_list {dir} { 
     44    return [types_list $dir "f"] 
     45} 
     46 
     47# List all files of a type on a directory recursively. This function is for internal use. 
     48proc portcheckdestroot::types_list {dir type} { 
    3949    set ret {} 
    40     foreach item [glob -nocomplain -type {d l} -directory $dir *] { 
     50    foreach item [glob -nocomplain -type "d $type" -directory $dir *] { 
    4151        if {[file isdirectory $item]} { 
    42             set ret [concat $ret [links_list $item]] 
     52            set ret [concat $ret [types_list $item $type]] 
    4353        } else { 
    44             #is link 
     54            #is from the correct type 
    4555            lappend ret $item 
    4656        } 
    4757    } 
    4858    return $ret 
     59} 
     60 
     61# Get files from a list. For internal use only 
     62proc portcheckdestroot::get_files { list } { 
     63    set files {} 
     64    foreach element $list { 
     65        if { [regexp {^/?[A-Za-z0-9\.-]+(/[A-Za-z0-9\.-]+)*$} $element] } { 
     66            if { [file exists $element] } { 
     67                lappend files $element 
     68            } 
     69        } 
     70    } 
     71    return $files 
     72} 
     73 
     74# List dependencies from the current package 
     75proc portcheckdestroot::get_dependencies {} { 
     76    global destroot destroot.depends_lib subport depends_lib 
     77    set deps {} 
     78    if {[info exists depends_lib]} { 
     79        foreach dep [set depends_lib] { 
     80            set dep_portname [_get_dep_port $dep] 
     81            if {$dep_portname != ""} { 
     82                set dep_portname [_get_dep_port $dep] 
     83                lappend deps $dep_portname 
     84            } 
     85        } 
     86    } 
     87    return $deps 
    4988} 
    5089 
     
    159198} 
    160199 
     200# Check for dynamic links that aren't in the dependency list 
     201proc portcheckdestroot::checkdestroot_libs {} { 
     202    global destroot destroot.depends_lib subport depends_lib UI_PREFIX 
     203    ui_notice "$UI_PREFIX Checking for wrong dynamic links" 
     204 
     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} 
     208 
     209    #Get dependencies files list. 
     210    set dep_files {} 
     211    foreach dep [get_dependencies] { 
     212        lappend dep_files [get_files [exec port contents $dep]] 
     213    } 
     214    set dep_files [concat $dep_files $dep_whitelist] 
     215 
     216    #Get package files 
     217    foreach file [files_list $destroot] { 
     218        if { [file executable "$file"] } { 
     219            #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" 
     229                        } else { 
     230                            return -code error "$lib binary dependencies are NOT met" 
     231                        } 
     232                    } 
     233                } 
     234            } 
     235        } 
     236    } 
     237} 
     238 
     239#For the given archs, check if the files from destroot are compatible 
     240proc portcheckdestroot::checkdestroot_arches { archs } { 
     241    global destroot 
     242    foreach file [files_list $destroot] { 
     243        if { [file executable "$file"] } { 
     244            set lipo_arches [checkdestroot_get_lipo_arches $file] 
     245            # 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" 
     249                } 
     250            } 
     251        } 
     252    } 
     253} 
     254 
     255# Recover the arches from a file, from it's lipo output. For internal use only. 
     256proc portcheckdestroot::checkdestroot_get_lipo_arches { file } { 
     257    set lipo_output [exec lipo -info $file] 
     258    return [regsub "Architectures in the.*are:" $lipo_output ""] 
     259} 
     260 
     261# Check for arch constraints 
     262proc portcheckdestroot::checkdestroot_arch {} { 
     263    global UI_PREFIX 
     264    ui_notice "$UI_PREFIX Checking for archs" 
     265    set archs [get_canonical_archs] 
     266    if { "archs" != "noarch" } { 
     267        checkdestroot_arches $archs 
     268    } 
     269} 
     270 
    161271proc portcheckdestroot::checkdestroot_main {args} { 
    162272    global UI_PREFIX 
     
    165275    checkdestroot_symlink 
    166276    checkdestroot_mtree 
     277    checkdestroot_libs 
     278    checkdestroot_arch 
    167279    return 0 
    168280} 
Note: See TracChangeset for help on using the changeset viewer.