Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port_binary_distributable.tcl: Allow multiple ports to be queried in a single run #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 40 additions & 19 deletions jobs/port_binary_distributable.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
# -*- 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
# \
if type -fp port-tclsh >/dev/null; then exec port-tclsh "$0" "$@"; else exec /usr/bin/tclsh "$0" "$@"; fi
# $Id$
#
# Check that binaries of a port are distributable by looking at its license
# and the licenses of its dependencies.
#
# Expected format: A {B C} means the license is A plus either B or C.
#
# Exit status:
# 0: distributable
# 1: non-distributable
# 0: all specified ports are distributable
# 1: at least one of the specified ports is not distributable
# 2: error


set MY_VERSION 0.1
set MY_VERSION 0.2

array set portsSeen {}

Expand Down Expand Up @@ -100,7 +99,7 @@ array set license_conflicts \
zpl-1 {agpl cecill gpl}"

proc printUsage {} {
puts "Usage: $::argv0 \[-hvV\] port-name \[variants...\]"
puts "Usage: $::argv0 \[-hvV\] port-name \[variants...\] \[port-name \[variants...\] ...\]"
puts " -h This help"
puts " -v verbose output"
puts " -V show version and MacPorts version being used"
Expand Down Expand Up @@ -160,6 +159,9 @@ proc remove_version {license} {

proc check_licenses {portName variantInfo verbose} {
global license_good license_conflicts
if {$verbose} {
set variantSettings [join_variantInfo $variantInfo]
}
array set portSeen {}
set top_info [infoForPort $portName $variantInfo]
if {$top_info eq {}} {
Expand Down Expand Up @@ -187,7 +189,7 @@ proc check_licenses {portName variantInfo verbose} {
lappend top_license_names $sub_names
if {!$any_good} {
if {$verbose} {
puts "\"$portName\" is not distributable because its license \"$lic\" is not known to be distributable"
puts "\"$portName$variantSettings\" is not distributable because its license \"$lic\" is not known to be distributable"
}
return 1
}
Expand Down Expand Up @@ -251,13 +253,13 @@ proc check_licenses {portName variantInfo verbose} {

if {!$any_good} {
if {$verbose} {
puts "\"$portName\" is not distributable because its dependency \"$aPort\" has license \"$lic\" which is not known to be distributable"
puts "\"$portName$variantSettings\" is not distributable because its dependency \"$aPort\" has license \"$lic\" which is not known to be distributable"
}
return 1
}
if {!$any_compatible} {
if {$verbose} {
puts "\"$portName\" is not distributable because its license \"$top_lic\" conflicts with license \"$full_lic\" of dependency \"$aPort\""
puts "\"$portName$variantSettings\" is not distributable because its license \"$top_lic\" conflicts with license \"$full_lic\" of dependency \"$aPort\""
}
return 1
}
Expand All @@ -277,20 +279,28 @@ proc check_licenses {portName variantInfo verbose} {
}

if {$verbose} {
puts "\"$portName\" is distributable"
puts "\"$portName$variantSettings\" is distributable"
}
return 0
}

proc split_variants {variants} {
set result {}
set l [regexp -all -inline -- {([-+])([[:alpha:]_]+[\w\.]*)} $variants]
set l [regexp -all -inline -- {(?:[[:space:]]|^)([-+])([[:alpha:]_]+[\w\.]*)(?:[[:space:]]|$)} $variants]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether I understand this change. Why would it be necessary to match the spaces explicitly now, but was not before?

Copy link
Contributor Author

@ryandesign ryandesign Dec 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing in a port name like youtube-dl was incorrectly being processed as a variant -dl. This change ensures that we are matching a + or - at the beginning of the entry only, not somewhere in the middle.

Before, this was guaranteed to be the case, because we were only calling split_variants on a list of strings that definitely began with a + or -. (Well, we were relying on the user to supply the variants in that format.) But now I am calling it with entries that could be a variant or could be a port, and I'm using the return value to determine which it was.

foreach { match sign variant } $l {
lappend result $variant $sign
}
return $result
}

proc join_variantInfo {variantInfo} {
set result {}
foreach {variant sign} $variantInfo {
append result " $sign$variant"
}
return $result
}

# Begin

set verbose 0
Expand Down Expand Up @@ -331,15 +341,26 @@ if {[llength $::argv] == 0} {
printUsage
exit 2
}
set portName [lindex $::argv 0]
set ::argv [lrange $::argv 1 end]

array set variantInfo {}
foreach variantSetting $::argv {
set variant [split_variants $variantSetting]
foreach {variantName flag} $variant {
set variantInfo($variantName) $flag

set exitCode 0
set argvIndex 0

while {$argvIndex < [llength $::argv]} {
set portName [lindex $::argv $argvIndex]
incr argvIndex
array set variantInfo {}
while {$argvIndex < [llength $::argv]} {
set variant [split_variants [lindex $::argv $argvIndex]]
if {$variant eq ""} {
break
}
foreach {variantName variantFlag} $variant {
set variantInfo($variantName) $variantFlag
}
incr argvIndex
}
set exitCode [max $exitCode [check_licenses $portName [array get variantInfo] $verbose]]
unset variantInfo
}

exit [check_licenses $portName [array get variantInfo] $verbose]
exit $exitCode