source: trunk/base/src/package1.0/portsrpm.tcl @ 42662

Last change on this file since 42662 was 42662, checked in by raimue@…, 12 years ago

Merged revisions 34469,34852,34854-34855,34900,36952-36956,37507-37508,37511-37512,41040,41042-41046,41138-41139,41142-41143,41145,41151,41403,41458,41462-41463,42575,42626,42640-42641,42659 via svnmerge from
https://svn.macosforge.org/repository/macports/branches/variant-descs-14482/base

........

r34469 | raimue@… | 2008-02-26 07:08:09 +0100 (Tue, 26 Feb 2008) | 3 lines


port/port.tcl:
Reading from .config/variant_descriptions actually works

........

r34852 | raimue@… | 2008-03-09 02:45:22 +0100 (Sun, 09 Mar 2008) | 4 lines


macports1.0/macports.tcl:
New API: macports::getsourceconfigdir
Returns the path to .config for a porturl.

........

r34854 | raimue@… | 2008-03-09 03:11:27 +0100 (Sun, 09 Mar 2008) | 3 lines


port/port.tcl:
Use new API macports::getsourceconfigdir

........

r34855 | raimue@… | 2008-03-09 03:12:54 +0100 (Sun, 09 Mar 2008) | 3 lines


port/port.tcl:
Treat variant descriptions as strings to avoid problems with braces

........

r34900 | raimue@… | 2008-03-10 16:54:25 +0100 (Mon, 10 Mar 2008) | 3 lines


port/port.tcl:
Rename variable

........

r36952 | raimue@… | 2008-05-21 04:20:27 +0200 (Wed, 21 May 2008) | 3 lines


port/port.tcl:
Remove get_variant_desc, this will now be done in port1.0/portutil.tcl instead

........

r36953 | raimue@… | 2008-05-21 04:22:04 +0200 (Wed, 21 May 2008) | 3 lines


macports1.0/macports.tcl:
Give the worker access to variable porturl and proc getsourceconfigdir

........

r36954 | raimue@… | 2008-05-21 04:23:37 +0200 (Wed, 21 May 2008) | 3 lines


port1.0/tests:
Fix the portutil test after r36953

........

r36955 | raimue@… | 2008-05-21 05:01:11 +0200 (Wed, 21 May 2008) | 3 lines


macports1.0/macports.tcl:
Give worker access to getprotocol and getportdir as they are needed for getsourceconfigdir

........

r36956 | raimue@… | 2008-05-21 05:02:23 +0200 (Wed, 21 May 2008) | 3 lines


port1.0/portutil.tcl:
New proc variant_desc, reads global variant description file

........

r37507 | raimue@… | 2008-06-10 16:04:54 +0200 (Tue, 10 Jun 2008) | 4 lines


port1.0/portutil.tcl:
Don't warn about a missing description if it is set global,
but warn if the variant overrides the global description

........

r37508 | raimue@… | 2008-06-10 16:14:03 +0200 (Tue, 10 Jun 2008) | 3 lines


macports1.0/macports.tcl:
Use .resources instead of .config as it is a bit clearer, see #14553

........

r37511 | raimue@… | 2008-06-10 17:22:12 +0200 (Tue, 10 Jun 2008) | 5 lines


port1.0/portutil.tcl:
Switch back to this format:
name {description}
So this could be easily extended if ever needed.

........

r37512 | raimue@… | 2008-06-10 17:27:48 +0200 (Tue, 10 Jun 2008) | 3 lines


port1.0/portutil.tcl:
Add a warning if global variant description file could not be opened

........

r41040 | raimue@… | 2008-10-21 13:06:39 +0200 (Tue, 21 Oct 2008) | 4 lines


macports/macport.tcl:

  • New flag "default" for sources to indicate fallback for resources (group)
  • Add parameter to getsourceconfigdir to get path for a requested file

........

r41042 | raimue@… | 2008-10-21 13:11:44 +0200 (Tue, 21 Oct 2008) | 3 lines


macports1.0/macports.tcl:
Rename getsourceconfigdir to getportresourcepath

........

r41043 | raimue@… | 2008-10-21 13:15:16 +0200 (Tue, 21 Oct 2008) | 3 lines


port1.0/portutil.tcl:
Use getportresourcepath for the group files

........

r41044 | raimue@… | 2008-10-21 13:19:47 +0200 (Tue, 21 Oct 2008) | 3 lines


port1.0/portlint.tcl:
Use getresourcepath for group files

........

r41045 | raimue@… | 2008-10-21 13:20:36 +0200 (Tue, 21 Oct 2008) | 3 lines


port1.0/portmain.tcl:
Add a note that we should get rid of $portresourcepath in favor of [getportresourcepath]

........

r41046 | raimue@… | 2008-10-21 13:40:29 +0200 (Tue, 21 Oct 2008) | 3 lines


port1.0/portutil.tcl:
Missed one instance of getsourceconfigdir

........

r41138 | raimue@… | 2008-10-25 20:52:50 +0200 (Sat, 25 Oct 2008) | 3 lines


port1.0/portutil.tcl:
Use getportresourcepath for global variant descriptions

........

r41139 | raimue@… | 2008-10-25 21:23:15 +0200 (Sat, 25 Oct 2008) | 3 lines


port1.0/portmain.tcl:
Correct XXX tag

........

r41142 | raimue@… | 2008-10-25 23:11:30 +0200 (Sat, 25 Oct 2008) | 3 lines


port1.0/portfetch.tcl:
Use getportresourcepath

........

r41143 | raimue@… | 2008-10-25 23:12:04 +0200 (Sat, 25 Oct 2008) | 3 lines


port1.0/portdestroot.tcl:
Use getportresourcepath

........

r41145 | raimue@… | 2008-10-26 00:04:15 +0200 (Sun, 26 Oct 2008) | 3 lines


macports1.0/macports.tcl:
Fix a problem with URLs not using the file protocol

........

r41151 | raimue@… | 2008-10-26 03:09:54 +0100 (Sun, 26 Oct 2008) | 3 lines


macports1.0/macports.tcl:
Fix issues introduced in r41145, the file exists check was wrong

........

r41403 | raimue@… | 2008-11-01 22:59:21 +0100 (Sat, 01 Nov 2008) | 3 lines


port1.0/portutil.tcl:
Add a debug output which group files are used

........

r41458 | blb@… | 2008-11-03 22:58:28 +0100 (Mon, 03 Nov 2008) | 2 lines


Add [default] tag and description to sources.conf

........

r41462 | blb@… | 2008-11-04 02:12:28 +0100 (Tue, 04 Nov 2008) | 2 lines


No longer need to install resources with base

........

r41463 | blb@… | 2008-11-04 02:14:49 +0100 (Tue, 04 Nov 2008) | 4 lines


Move the install/ subdir (containing the mtree files) into .../share/macports
from the resources dir (the mtree contains a bit of install-time info, so it
shouldn't be with the resources stuff in the port tree)

........

r42575 | blb@… | 2008-11-25 01:53:05 +0100 (Tue, 25 Nov 2008) | 3 lines


Add script to handle upgrades through configure/make/make install and
the package, so [default] is added as appropriate to sources.conf

........

r42626 | raimue@… | 2008-11-27 02:21:15 +0100 (Thu, 27 Nov 2008) | 3 lines


package1.0/portpkg.tcl, package1.0/portmpkg.tcl:
Remove portresourcepath and use [getportresourcepath] instead

........

r42640 | raimue@… | 2008-11-27 11:49:32 +0100 (Thu, 27 Nov 2008) | 3 lines


package1.0/portrpm.tcl, package1.0/portsrpm.tcl:
Remove reference to portresurcepath which is not used at all

........

r42641 | raimue@… | 2008-11-27 11:52:12 +0100 (Thu, 27 Nov 2008) | 3 lines


port1.0/portmain.tcl:
Remove definition of portresourcepath as it is not used any more

........

r42659 | raimue@… | 2008-11-28 16:44:30 +0100 (Fri, 28 Nov 2008) | 3 lines


macports1.0/macports.tcl:
Rename portresourcepath from .resources to _resources

........

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.9 KB
Line 
1# et:ts=4
2# portsrpm.tcl
3# $Id: portsrpm.tcl 42662 2008-11-28 23:18:50Z raimue@macports.org $
4#
5# Copyright (c) 2002 - 2003 Apple Computer, Inc.
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
17#    may be used to endorse or promote products derived from this software
18#    without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31#
32
33package provide portsrpm 1.0
34package require portutil 1.0
35package require portfetch 1.0
36
37set org.macports.srpm [target_new org.macports.srpm srpm_main]
38target_runtype ${org.macports.srpm} always
39target_provides ${org.macports.srpm} srpm
40target_requires ${org.macports.srpm} checksum
41
42options package.destpath
43
44set_ui_prefix
45
46proc srpm_main {args} {
47    global portname portversion portrevision UI_PREFIX
48   
49    ui_msg "$UI_PREFIX [format [msgcat::mc "Creating SRPM package for %s-%s"] ${portname} ${portversion}]"
50   
51    return [srpm_pkg $portname $portversion $portrevision]
52}
53
54proc srpm_pkg {portname portversion portrevision} {
55    global UI_PREFIX package.destpath portdbpath destpath workpath distpath prefix categories maintainers description long_description homepage epoch portpath distfiles fetch_urls
56        global os.platform os.arch os.version os.major
57   
58    set rpmdestpath ""
59    if {![string equal ${package.destpath} ${workpath}] && ![string equal ${package.destpath} ""]} {
60        set pkgpath ${package.destpath}
61        system "mkdir -p ${pkgpath}/BUILD"
62        system "mkdir -p ${pkgpath}/RPMS"
63        system "mkdir -p ${pkgpath}/SOURCES"
64        system "mkdir -p ${pkgpath}/SPECS"
65        system "mkdir -p ${pkgpath}/SRPMS"
66        set rpmdestpath "--define '_topdir ${pkgpath}'"
67    }
68   
69    foreach dir [list "${prefix}/src/macports/SRPMS" "${prefix}/src/apple/SRPMS" "/usr/src/apple/SRPMS" "/macports/rpms/SRPMS"] {
70        foreach arch {"src" "nosrc"} {
71            set rpmpath "$dir/${portname}-${portversion}-${portrevision}.${arch}.rpm"
72            if {[file readable $rpmpath] && ([file mtime ${rpmpath}] >= [file mtime ${portpath}/Portfile])} {
73                ui_debug "$rpmpath"
74                ui_msg "$UI_PREFIX [format [msgcat::mc "SRPM package for %s-%s is up-to-date"] ${portname} ${portversion}]"
75                return 0
76            }
77        }
78    }
79   
80    set specpath ${workpath}/${portname}-port.spec
81    # long_description, description, or homepage may not exist
82    foreach variable {long_description description homepage categories maintainers} {
83        if {![info exists $variable]} {
84            set pkg_$variable ""
85        } else {
86            set pkg_$variable [set $variable]
87        }
88    }
89    set category   [lindex [split $categories " "] 0]
90    set license    "Unknown"
91    set maintainer $maintainers
92   
93    set dependencies {}
94    # get deplist
95    set deps [make_dependency_list $portname]
96    set deps [lsort -unique $deps]
97    foreach dep $deps {
98        set name [lindex [split $dep /] 0]
99        set vers [lindex [split $dep /] 1]
100        # don't re-package ourself
101        if {$name != $portname} {
102            lappend dependencies "${name} >= ${vers}"
103        }
104    }
105
106    # true = .src.rpm (with distfiles), false = .nosrc.rpm (without distfiles)
107    set src false
108
109    #set sourcespath ${prefix}/src/macports/SOURCES
110    set sourcespath "`rpm --eval %{_sourcedir}`"
111
112    system "cp -p ${portpath}/Portfile ${sourcespath}/$portname-Portfile"
113    system "cd ${portpath} && zip -r -q ${sourcespath}/$portname-files.zip files -x \\*.DS_Store -x files/.svn\\*"
114    foreach dist $distfiles {
115        system "cp -p ${distpath}/${dist} ${sourcespath}/${dist}"
116    }
117   
118    write_port_spec ${specpath} $portname $portversion $portrevision $pkg_description $pkg_long_description $pkg_homepage $category $license $maintainer $distfiles $fetch_urls $dependencies $epoch $src
119    system "rpmbuild -bs -v --nodeps ${rpmdestpath} ${specpath}"
120   
121    return 0
122}
123
124proc make_dependency_list {portname} {
125    set result {}
126    if {[catch {set res [mport_search "^$portname\$"]} error]} {
127                global errorInfo
128                ui_debug "$errorInfo"
129        ui_error "port search failed: $error"
130        return 1
131    }
132    foreach {name array} $res {
133        array set portinfo $array
134       
135        if {[info exists portinfo(depends_build)] || [info exists portinfo(depends_lib)]} {
136            # get the union of depends_build and depends_lib
137            # xxx: only examines the portfile component of the depspec
138            set depends {}
139            if {[info exists portinfo(depends_build)]} { eval "lappend depends $portinfo(depends_build)" }
140            if {[info exists portinfo(depends_lib)]} { eval "lappend depends $portinfo(depends_lib)" }
141           
142            foreach depspec $depends {
143                set dep [lindex [split $depspec :] end]
144               
145                # xxx: nasty hack
146                if {$dep != "XFree86"} {
147                    eval "lappend result [make_dependency_list $dep]"
148                }
149            }
150        }
151        lappend result $portinfo(name)/$portinfo(version)
152        unset portinfo
153    }
154    ui_debug "dependencies for ${portname}: $result"
155    return $result
156}
157
158proc word_wrap {orig Length} {
159    set pos 0
160    set line ""
161    set text ""
162
163    set words [split $orig]
164    set numWords [llength $words]
165    for {set cnt 0} {$cnt < $numWords} {incr cnt} {
166        set w [lindex $words $cnt]
167        set wLen [string length $w]
168
169        if {($pos+$wLen < $Length)} {
170            # append word to current line
171            if {$pos} {append line " "; incr pos}
172            append line $w
173            incr pos $wLen
174        } else {
175            # line full => write buffer and  begin a new line
176            if {[string length $text]} {append text "\n"}
177            append text $line
178            set line $w
179            set pos $wLen
180        }
181    }
182
183    if {[string length $text]} {append text "\n"}
184    if {[string length $line]} {append text $line}
185    return $text
186}
187
188proc write_port_spec {specfile portname portversion portrevision description long_description homepage category license maintainer distfiles fetch_urls dependencies epoch src} {
189    set specfd [open ${specfile} w+]
190    set origportname ${portname}
191    regsub -all -- "\-" $portversion "_" portversion
192    regsub -all -- "\-" $portname "_" portname
193    puts $specfd "\#Spec file generated by MacPorts
194%define distribution MacPorts
195%define vendor MacPorts
196%define packager ${maintainer}
197
198Summary: ${description}
199Name: ${portname}
200Version: ${portversion}
201Release: ${portrevision}
202Group: ${category}
203License: ${license}
204URL: ${homepage}
205BuildRoot: %{_tmppath}/%{name}-%{version}-root
206Source0: ${portname}-Portfile
207Source1: ${portname}-files.zip"
208    if {[expr ${epoch} != 0]} {
209            puts $specfd "Epoch: ${epoch}"
210    }
211    set first 2
212    set count $first
213    puts $specfd "#distfiles"
214    foreach file ${distfiles} {
215   
216        puts -nonewline $specfd "Source${count}: "
217        if {![info exists $fetch_urls]} {
218        foreach {url_var distfile}  ${fetch_urls} {
219            if {[string equal $distfile $file]} {
220                 global portfetch::$url_var
221                 set site [lindex [set $url_var] 0]
222                 set file [portfetch::assemble_url $site $distfile]
223                 break
224            }
225        }
226        }
227        puts $specfd $file
228        if (!$src) {
229            puts $specfd "NoSource: $count"
230        }
231        incr count
232    }
233    puts $specfd "AutoReq: no"
234    if {[llength ${dependencies}] != 0} {
235        foreach require ${dependencies} {
236            puts $specfd "BuildRequires: [regsub -all -- "\-" $require "_"]"
237        }
238    }
239    set wrap_description [word_wrap ${long_description} 72]
240    puts $specfd "
241%description
242$wrap_description
243
244%prep
245%setup -c -a 1 -T
246cp -p %{SOURCE0} Portfile
247#prepare work area
248port fetch
249port checksum
250port extract
251port patch
252
253%build
254port configure
255port build
256
257%install
258rm -rf \$RPM_BUILD_ROOT
259mkdir -p \$RPM_BUILD_ROOT
260port destroot
261port rpm
262
263%clean
264port clean"
265    close $specfd
266}
Note: See TracBrowser for help on using the repository browser.