New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Changeset 79636


Ignore:
Timestamp:
06/21/11 15:33:34 (4 years ago)
Author:
cal@…
Message:

rev-upgrade: Quickly hacked code to call otool -L on the files marked binary and parse it's output using regexes.
Tested to find and report missing libs.
TODO: Test compatibility version, maybe get to work with .a files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gsoc11-rev-upgrade/base/src/macports1.0/macports.tcl

    r79541 r79636  
    35193519    set files [registry::file search active 1 binary -null] 
    35203520    if {[llength $files] > 0} { 
    3521         ui_msg "---> Updating database of binaries" 
    3522         set i 1 
    3523         foreach f $files { 
    3524             ui_debug "Updating binary flag for file $i of [llength $files]: [$f path]" 
    3525             incr i 
    3526             $f binary [fileIsBinary [$f path]] 
     3521        registry::write { 
     3522            try { 
     3523                ui_msg "---> Updating database of binaries" 
     3524                set i 1 
     3525                foreach f $files { 
     3526                    ui_debug "Updating binary flag for file $i of [llength $files]: [$f path]" 
     3527                    incr i 
     3528                    $f binary [fileIsBinary [$f path]] 
     3529                } 
     3530            } catch {*} { 
     3531                ui_msg "Updating database of binaries failed" 
     3532                throw 
     3533            } 
    35273534        } 
    35283535    } 
     
    35363543        # http://www.opensource.apple.com/source/cctools/cctools-800/otool/main.c 
    35373544        # as if it was called with otool -L, thus using 
    3538         # http://www.opensource.apple.com/source/cctools/cctools-698/libstuff/ofile.c 
     3545        # http://www.opensource.apple.com/source/cctools/cctools-800/libstuff/ofile.c 
    35393546        # and print_libraries from 
    35403547        # http://www.opensource.apple.com/source/cctools/cctools-800/otool/ofile_print.c, 
    35413548        # but don't actually print the libs, but write them into a list and check them for existance and compatibility. 
    35423549        # Maybe implement a cache for libs that have already been checked (because a lot of software links against similar libs) 
     3550         
     3551        if {[catch {set otool_output [exec /usr/bin/otool -arch all -L [$b path]]} msg]} { 
     3552            ui_warn "Error running otool on file [$b path]: $msg" 
     3553            continue; 
     3554        } 
     3555        set otool_lines [split $otool_output "\n"] 
     3556        set arch "unknown" 
     3557        foreach otool_line $otool_lines { 
     3558            if {1 == [regexp -nocase {^Archive} $otool_line]} { 
     3559                ui_info "Ignoring archive file [$b path]" 
     3560                break; 
     3561            } 
     3562            if {1 == [regexp -nocase {\(architecture ([^\s]+)\)} $otool_line match arch]} { 
     3563                switch $arch { 
     3564                    x86_64 {} 
     3565                    i386 {} 
     3566                    ppc {} 
     3567                    ppc64 {} 
     3568                    default { 
     3569                        ui_warn "Unknown architecture $arch" 
     3570                    } 
     3571                } 
     3572                continue; 
     3573            } 
     3574            if {$arch == "unknown"} { 
     3575                ui_warn "Unspecified architecture in file [$b path]" 
     3576                break; 
     3577            } 
     3578            if {1 == [regexp -nocase {^\t([^\s]+) \(compatibility version ([^,]+), current version ([^)]+)\)} $otool_line match file comp_version curr_version]} { 
     3579                if {$file == [$b path]} { 
     3580                    # This is a self-referencing entry 
     3581                    continue; 
     3582                } 
     3583                ui_debug "Linked against: $file, architecture $arch, version $curr_version, compatibility version $comp_version" 
     3584                set lib_found false 
     3585                if {[catch {set lib_otool_output [exec /usr/bin/otool -arch $arch -L $file]}] == 0} { 
     3586                    set lib_otool_lines [split $lib_otool_output "\n"] 
     3587                    foreach lib_otool_line $lib_otool_lines { 
     3588                        if {1 == [regexp -nocase {^\t([^\s]+) \(compatibility version ([^,]+), current version ([^)]+)\)} $lib_otool_line match lib_file lib_comp_version lib_curr_version]} { 
     3589                            if {$file == $lib_file} { 
     3590                                set lib_found true 
     3591                                if {$curr_version != $lib_curr_version} { 
     3592                                    if {$comp_version != $lib_comp_version} { 
     3593                                        ui_warn "Incompatibly library version: Expected $comp_version, but got $lib_comp_version!" 
     3594                                    } 
     3595                                } 
     3596                            } 
     3597                        } 
     3598                    } 
     3599                } 
     3600                if {$lib_found == false} { 
     3601                    ui_warn "Missing dependency $file!" 
     3602                } 
     3603                continue; 
     3604            } 
     3605            ui_warn "unparseable line in otool output: $otool_line" 
     3606        } 
    35433607    } 
    35443608    return 0; 
Note: See TracChangeset for help on using the changeset viewer.