source: contrib/mp-buildbot/tools/dependencies.tcl

Last change on this file was 152645, checked in by ryandesign@…, 4 years ago

mp-buildbot: add blank line before description

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 6.1 KB
Line 
1#!/usr/bin/env port-tclsh
2# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
3#
4# Writes a list of dependencies for a given port including variants (e.g. if
5# the universal variant is required) to stdout.
6#
7# Copyright (c) 2016 The MacPorts Project.
8# Copyright (c) 2016 Clemens Lang <cal@macports.org>
9#
10# Redistribution and use in source and binary forms, with or without
11# modification, are permitted provided that the following conditions
12# are met:
13# 1. Redistributions of source code must retain the above copyright
14#    notice, this list of conditions and the following disclaimer.
15# 2. Redistributions in binary form must reproduce the above copyright
16#    notice, this list of conditions and the following disclaimer in
17#    the documentation and/or other materials provided with the
18#    distribution.
19# 3. Neither the name of the MacPorts project, nor the names of any contributors
20#    may be used to endorse or promote products derived from this software
21#    without specific prior written permission.
22#
23# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
24# AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
27# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35package require macports
36
37if {[llength $::argv] == 0} {
38    puts stderr "Usage: $argv0 <portname> \[(+|-)variant...\]"
39    exit 1
40}
41
42# initialize macports
43if {[catch {mportinit "" "" ""} result]} {
44   ui_error "$errorInfo"
45   ui_error "Failed to initialize ports sytem: $result"
46   exit 1
47}
48
49# look up the path of the Portfile for the given port
50set portname [lindex $::argv 0]
51#try -pass_signal {...}
52try {
53    set result [mportlookup $portname]
54    if {[llength $result] < 2} {
55        ui_error "No such port: $portname"
56        exit 1
57    }
58} catch {{*} eCode eMessage} {
59    ui_error "mportlookup $portname failed: $eMessage"
60    exit 1
61}
62
63# parse the given variants from the command line
64array set variants {}
65foreach item [lrange $::argv 1 end] {
66    foreach {_ sign variant} [regexp -all -inline -- {([-+])([[:alpha:]_]+[\w\.]*)} $item] {
67        set variants($variant) $sign
68    }
69}
70
71# open the port so we can run dependency calculation
72array set portinfo [lindex $result 1]
73#try -pass_signal {...}
74try {
75    set mport [mportopen $portinfo(porturl) [list subport $portname] [array get variants]]
76} catch {{*} eCode eMessage} {
77    ui_error "mportopen ${portinfo(porturl)} failed: $eMessage"
78    exit 1
79}
80
81# gather a list of dependencies with the correct variants (+universal is dealt
82# with in specific ways)
83if {[mportdepends $mport "activate"] != 0} {
84    ui_error "mportdepends $portname activate failed."
85    exit 1
86}
87
88# sort these dependencies topologically; exclude the given port itself
89set dlist [dlist_append_dependents $macports::open_mports $mport {}]
90dlist_delete dlist $mport
91
92## print dependencies with variants
93proc printdependency {ditem} {
94    global variants
95
96    array set depinfo [mportinfo $ditem]
97
98    # There's a conceptual problem here: We need to calculate the string to
99    # pass to port(1) to build this exact port with its variants, but the
100    # active_variants array does not contain an entry for explicitly
101    # deactivated default_variants.
102    #
103    # To calculate the correct string with the explicitly disabled default
104    # variants, if any, we need the default variants first. Unfortunately the
105    # only way to get the set of default variants is opening the port without
106    # any.
107    #
108    # Given the active_variants of the current dependency calculation and the
109    # ones from a pristine port without variants, calculate the required
110    # string.
111
112    # open the port without variants to determine the default variants
113    if {[llength [array get variants]] > 0} {
114        #try -pass_signal {...}
115        try {
116            set result [mportlookup $depinfo(name)]
117            if {[llength $result] < 2} {
118                ui_error "No such port: $depinfo(name)"
119                exit 1
120            }
121
122            # open the port so we can calculate the default variants
123            array set defaultvariant_portinfo [lindex $result 1]
124            set defaultvariant_mport [mportopen $defaultvariant_portinfo(porturl) [list subport $depinfo(name)] {}]
125            array set defaultvariant_info [mportinfo $defaultvariant_mport]
126            array set default_variants $defaultvariant_info(active_variants)
127            mportclose $defaultvariant_mport
128        }
129    } else {
130        array set default_variants {}
131    }
132
133    set variantstring ""
134    array set active_variants $depinfo(active_variants)
135
136    set relevant_variants [lsort -unique [concat [array names active_variants] [array names default_variants]]]
137    foreach variant $relevant_variants {
138        if {[info exists active_variants($variant)]} {
139            append variantstring "$active_variants($variant)$variant"
140        } else {
141            # the only case where this situation can occur is a default variant that was explicitly disabled
142            append variantstring "-$variant"
143        }
144    }
145
146    puts [string trim "$depinfo(name) $variantstring"]
147}
148dlist_eval $dlist {} [list printdependency]
149
150# close all open ports
151foreach ditem $macports::open_mports {
152    #try -pass_signal {...}
153    try {
154        mportclose $ditem
155    } catch {{*} eCode eMessage} {
156        ui_warn "mportclose [ditem_key $ditem provides] failed: $eMessage"
157    }
158}
159
160# shut down MacPorts
161#try -pass_signal {...}
162try {
163    mportshutdown
164} catch {{*} eCode eMessage} {
165    ui_error "mportshutdown failed: $eMessage"
166    exit 1
167}
Note: See TracBrowser for help on using the repository browser.