[50935] branches/images-and-archives/base/src

blb at macports.org blb at macports.org
Tue May 12 23:27:03 PDT 2009


Revision: 50935
          http://trac.macports.org/changeset/50935
Author:   blb at macports.org
Date:     2009-05-12 23:27:03 -0700 (Tue, 12 May 2009)
Log Message:
-----------
Add new target 'imagefile'

Modified Paths:
--------------
    branches/images-and-archives/base/src/macports1.0/macports.tcl
    branches/images-and-archives/base/src/port/port.tcl
    branches/images-and-archives/base/src/port1.0/Makefile
    branches/images-and-archives/base/src/port1.0/port.tcl
    branches/images-and-archives/base/src/port1.0/portutil.tcl

Added Paths:
-----------
    branches/images-and-archives/base/src/port1.0/portimagefile.tcl

Modified: branches/images-and-archives/base/src/macports1.0/macports.tcl
===================================================================
--- branches/images-and-archives/base/src/macports1.0/macports.tcl	2009-05-13 06:20:36 UTC (rev 50934)
+++ branches/images-and-archives/base/src/macports1.0/macports.tcl	2009-05-13 06:27:03 UTC (rev 50935)
@@ -799,6 +799,7 @@
     $workername alias registry_deactivate registry::deactivate
     $workername alias registry_register_deps registry::register_dependencies
     $workername alias registry_fileinfo_for_index registry::fileinfo_for_index
+    $workername alias registry_fileinfo_for_file registry::fileinfo_for_file
     $workername alias registry_bulk_register_files registry::register_bulk_files
     $workername alias registry_installed registry::installed
     $workername alias registry_active registry::active
@@ -1318,7 +1319,7 @@
     set dlist {}
     if {$target == "configure" || $target == "build"
         || $target == "test"
-        || $target == "destroot" || $target == "install"
+        || $target == "destroot" || $target == "imagefile" || $target == "install"
         || $target == "archive"
         || $target == "dmg" || $target == "mdmg"
         || $target == "pkg" || $target == "mpkg"
@@ -1911,6 +1912,7 @@
         
         test        -
         destroot    -
+        imagefile   -
         install     -
         archive     -
         dmg         -

Modified: branches/images-and-archives/base/src/port/port.tcl
===================================================================
--- branches/images-and-archives/base/src/port/port.tcl	2009-05-13 06:20:36 UTC (rev 50934)
+++ branches/images-and-archives/base/src/port/port.tcl	2009-05-13 06:27:03 UTC (rev 50935)
@@ -2954,6 +2954,7 @@
     patch       [list action_target         [action_args_const ports]] \
     configure   [list action_target         [action_args_const ports]] \
     build       [list action_target         [action_args_const ports]] \
+    imagefile   [list action_target         [action_args_const ports]] \
     destroot    [list action_target         [action_args_const ports]] \
     install     [list action_target         [action_args_const ports]] \
     clean       [list action_target         [action_args_const ports]] \

Modified: branches/images-and-archives/base/src/port1.0/Makefile
===================================================================
--- branches/images-and-archives/base/src/port1.0/Makefile	2009-05-13 06:20:36 UTC (rev 50934)
+++ branches/images-and-archives/base/src/port1.0/Makefile	2009-05-13 06:27:03 UTC (rev 50935)
@@ -2,7 +2,7 @@
 
 SRCS=	port.tcl portchecksum.tcl portconfigure.tcl portextract.tcl	    \
 	portfetch.tcl portmain.tcl portbuild.tcl portpatch.tcl portutil.tcl \
-	portinstall.tcl portdepends.tcl portdestroot.tcl portlint.tcl \
+	portimagefile.tcl portinstall.tcl portdepends.tcl portdestroot.tcl portlint.tcl \
 	portclean.tcl porttest.tcl portactivate.tcl portsubmit.tcl \
 	port_autoconf.tcl portstartupitem.tcl porttrace.tcl portlivecheck.tcl \
 	portdistcheck.tcl portmirror.tcl portload.tcl portunload.tcl \

Modified: branches/images-and-archives/base/src/port1.0/port.tcl
===================================================================
--- branches/images-and-archives/base/src/port1.0/port.tcl	2009-05-13 06:20:36 UTC (rev 50934)
+++ branches/images-and-archives/base/src/port1.0/port.tcl	2009-05-13 06:27:03 UTC (rev 50935)
@@ -42,6 +42,7 @@
 package require portconfigure 1.0
 package require portbuild 1.0
 package require portdestroot 1.0
+package require portimagefile 1.0
 package require portinstall 1.0
 package require portactivate 1.0
 package require portclean 1.0

Added: branches/images-and-archives/base/src/port1.0/portimagefile.tcl
===================================================================
--- branches/images-and-archives/base/src/port1.0/portimagefile.tcl	                        (rev 0)
+++ branches/images-and-archives/base/src/port1.0/portimagefile.tcl	2009-05-13 06:27:03 UTC (rev 50935)
@@ -0,0 +1,204 @@
+# portimagefile.tcl
+# $Id$
+#
+# Copyright (c) 2009 The MacPorts Project
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. Neither the name of The MacPorts Project nor the names of its contributors
+#    may be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+package provide portimagefile 1.0
+package require portutil 1.0
+
+set org.macports.imagefile [target_new org.macports.imagefile portimagefile::imagefile_main]
+target_provides ${org.macports.imagefile} imagefile
+target_requires ${org.macports.imagefile} main fetch checksum extract patch configure build destroot
+target_prerun ${org.macports.imagefile} portimagefile::imagefile_start
+
+namespace eval portimagefile {
+}
+
+# define options
+options imagefile.imagespath
+
+# set defaults
+default imagefile.imagespath {[file join $portdbpath images]}
+
+set_ui_prefix
+
+proc portimagefile::imagefile_start {args} {
+    global UI_PREFIX portname portversion portrevision portvariants
+    ui_msg "$UI_PREFIX [format [msgcat::mc "Imaging %s @%s_%s%s"] $portname $portversion $portrevision $portvariants]"
+
+    return 0
+}
+
+
+proc portimagefile::imagefile_main {args} {
+    global portname portversion portrevision portvariants epoch destpath
+    global workpath portpath os.platform os.arch
+    set startpwd [pwd]
+    if {[catch {_cd $destpath} err]} {
+        ui_error $err
+        return
+    }
+    if {[catch {set tarcmd [binaryInPath tar]} err]} {
+        ui_error $err
+        return
+    }
+    if {[catch {set bzipcmd [binaryInPath bzip2]} err]} {
+        ui_error $err
+        return
+    }
+    set imageworkpath [file join $workpath image]
+    file mkdir $imageworkpath
+    ui_debug "Creating files.tar.bz2"
+    if {[catch {system "$tarcmd -cvf - * | $bzipcmd -c > [file join $imageworkpath files.tar.bz2]"} err]} {
+        ui_error $err
+        return
+    }
+    # Copy Portfile into imageworkpath to be included in image file
+    file copy [file join $portpath Portfile] [file join $imageworkpath "+PORTFILE"]
+    create_image_receipt $imageworkpath
+    _cd $imageworkpath
+    set macport_filename "${portname}-${epoch}-${portversion}_${portrevision}${portvariants}.${os.platform}.${os.arch}.macport"
+    set macport_file [file join $workpath $macport_filename]
+    ui_debug "Creating $macport_filename"
+    if {[catch {system "$tarcmd -cvf $macport_file *"} err]} {
+        ui_error $err
+        return
+    }
+
+    install_register_imagefile $macport_file
+
+    _cd $startpwd
+
+    return 0
+}
+
+
+# Create a +IMAGERECEIPT file which contains all information necessary
+# to register the port in the MacPorts registry
+proc portimagefile::create_image_receipt {imageworkpath} {
+    global portname portversion portrevision portvariants epoch categories
+    global homepage maintainers depends_run depends_lib prefix package-install
+    global description long_description destpath
+    set fd [open [file join $imageworkpath "+IMAGERECEIPT"] w]
+    set variablelist {portname portversion portrevision portvariants epoch categories homepage maintainers depends_run depends_lib prefix package-install description long_description}
+    foreach onevar $variablelist {
+        if {[info exists $onevar]} {
+            puts $fd "$onevar [string map {\n \\n} [set $onevar]]"
+        }
+    }
+    puts $fd "contents [filelist_for_path $destpath]"
+    close $fd
+
+    return 0
+}
+
+
+# Build up a list of information which describes each file within the
+# destroot, which matches that information which is found in receipts.
+proc portimagefile::filelist_for_path {startpath} {
+    if {[string index $startpath end] == "/"} {
+        set startpath [string range $startpath 0 end-1]
+    }
+    set filelist {}
+    fs-traverse element $startpath {
+        if {![file isdirectory $element]} {
+            # registry_fileinfo_for_file only works on files which exist
+            # so we must run it against the stuff in the destroot, then strip
+            # out that path to get to what will be the final install path
+            set fileinfo [registry_fileinfo_for_file $element]
+            lappend filelist [regsub -all "$startpath" $fileinfo ""]
+        }
+    }
+
+    return $filelist
+}
+
+
+# Install (copy to imagefile.imagespath) an imagefile and register
+# it as installed in the MacPorts registry.  This makes no assumptions
+# about how the imagefile was created/acquired
+proc portimagefile::install_register_imagefile {imagefile} {
+    global imagefile.imagespath prefix
+    set mytempdir [mkdtemp /tmp/mpimageXXXXXXXX]
+    set startpwd [pwd]
+    try {
+        if {[catch {_cd $mytempdir} err]} {
+            throw MACPORTS $err
+        }
+        if {[catch {set tarcmd [binaryInPath tar]} err]} {
+            throw MACPORTS $err
+        }
+        if {[catch {system "$tarcmd -xvf $imagefile +IMAGERECEIPT"} err]} {
+            throw MACPORTS $err
+        }
+        if {[catch {set fd [open "+IMAGERECEIPT" r]} err]} {
+            throw MACPORTS "Can't open image receipt: $err"
+        }
+        array set imagevars [list]
+        while {[gets $fd line] >= 0} {
+            set imagevars([lindex $line 0]) [lrange $line 1 end]
+        }
+        close $fd
+        set requiredvars {portname portversion portrevision portvariants epoch categories contents prefix}
+        foreach required $requiredvars {
+            if {![info exists imagevars($required)]} {
+                throw MACPORTS "Image receipt missing required variable $required"
+            }
+        }
+
+        if {$imagevars(prefix) != $prefix} {
+            throw MACPORTS "Image prefix ($imagevars(prefix)) does not match ours ($prefix)"
+        }
+        set portimagepath [file join ${imagefile.imagespath} $imagevars(portname)]
+        if {![file isdirectory $portimagepath]} {
+            file mkdir $portimagepath
+        }
+        ui_debug "Installing and registering [file tail $imagefile]"
+        file copy -force $imagefile $portimagepath
+
+        set regref [registry_new $imagevars(portname) $imagevars(portversion) $imagevars(portrevision) $imagevars(portvariants) $imagevars(epoch)]
+        registry_prop_store $regref categories $imagevars(categories)
+        registry_prop_store $regref contents $imagevars(contents)
+        foreach propname [array names imagevars] {
+            if {[lsearch -exact $requiredvars $propname] >= 0} {
+                continue
+            }
+            registry_prop_store $regref $propname $imagevars($propname)
+        }
+        registry_write $regref
+    } catch {* errorCode errorMessage } {
+        ui_error $errorMessage
+    } finally {
+        _cd $startpwd
+        file delete -force $mytempdir
+    }
+
+    return 0
+}
+

Modified: branches/images-and-archives/base/src/port1.0/portutil.tcl
===================================================================
--- branches/images-and-archives/base/src/port1.0/portutil.tcl	2009-05-13 06:20:36 UTC (rev 50934)
+++ branches/images-and-archives/base/src/port1.0/portutil.tcl	2009-05-13 06:27:03 UTC (rev 50935)
@@ -1252,6 +1252,7 @@
                     if {$target != "activate"
                       && $target != "archive"
                       && $target != "fetch"
+                      && $target != "imagefile"
                       && $target != "install"} {
                         porttrace::trace_enable_fence
                     }
@@ -1271,6 +1272,7 @@
 
                             test        -
                             destroot    -
+                            imagefile   -
                             install     -
                             archive     -
                             dmg         -
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090512/38ed4a4a/attachment-0001.html>


More information about the macports-changes mailing list