Skip to content

Commit

Permalink
ignore attributes created with 'declare'
Browse files Browse the repository at this point in the history
This never actually worked. Furthermore, makepkg can't support this, so
neither should we. Usage of 'declare' in the global section will Just
Work™.
  • Loading branch information
falconindy committed Oct 12, 2014
1 parent 5b87b6d commit def0dff
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pkgbuild_introspection.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ extract_function_var() {
local funcname=$1 attr=$2 isarray=$3 outputvar=$4 attr_regex= decl= r=1

if (( isarray )); then
printf -v attr_regex '^[[:space:]]*(declare( -[[:alpha:]])*)? %q\+?=\(' "$2"
printf -v attr_regex '^[[:space:]]* %s\+?=\(' "$2"
else
printf -v attr_regex '^[[:space:]]*(declare( -[[:alpha:]])*)? %q\+?=[^(]' "$2"
printf -v attr_regex '^[[:space:]]* %s\+?=[^(]' "$2"
fi

while read -r; do
# strip leading whitespace and any usage of declare
decl=${REPLY##*([[:space:]])?(declare +(-+([[:alpha:]]) ))}
decl=${REPLY##*([[:space:]])}
eval "${decl/#$attr/$outputvar}"

# entering this loop at all means we found a match, so notify the caller.
Expand Down
38 changes: 38 additions & 0 deletions test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ def test_PackageAttributeOverrides(self):
self.assertEqual(['bar'], pb['applejack']['depends'])
self.assertEqual(['foo'], pb['pinkiepie']['depends'])

def test_HandlesDeclareInGlobalAttrs(self):
pb = testutil.parse_pkgbuild('''
declare pkgbase=ponies
declare -a pkgname=('applejack' 'pinkiepie')
declare depends=('foo')
package_applejack() {
depends=('bar')
}
''')
self.assertPackageNamesEqual(pb, ['applejack', 'pinkiepie'])
self.assertEqual(['bar'], pb['applejack']['depends'])
self.assertEqual(['foo'], pb['pinkiepie']['depends'])

def test_PackageAttributeAppends(self):
pb = testutil.parse_pkgbuild('''
pkgbase=ponies
Expand Down Expand Up @@ -130,6 +143,31 @@ def test_HandlesMultiLineArrays(self):
self.assertPackageNamesEqual(pb, ['ponies'])
self.assertEqual(['foo', 'bar', 'baz'], pb['ponies']['depends'])

@unittest.expectedFailure
def test_HandlesMultiLineValuesInFunctions(self):
pb = testutil.parse_pkgbuild('''
pkgname=ponies
package_ponies() {
optdepends=('some:
program')
}
''')
self.assertPackageNamesEqual(pb, ['ponies'])
self.assertRegex(pb['ponies']['optdepends'][0], 'some:.*program')

def test_HandlesRegexyPackageNames(self):
pb = testutil.parse_pkgbuild('''
pkgname=('ponies+cake')
pkgver=1.2.3
package_ponies+cake() {
depends=('pie' 'apples')
}
''')
self.assertPackageNamesEqual(pb, ['ponies+cake'])
self.assertEqual(['pie', 'apples'], pb['ponies+cake']['depends'])
self.assertEqual('1.2.3', pb['ponies+cake']['pkgver'])

def test_HandlesQuotedValues(self):
pb = testutil.parse_pkgbuild('''
pkgname=ponies
Expand Down
3 changes: 2 additions & 1 deletion test/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import tempfile

def OutputOf(*argv):
return subprocess.check_output(argv).decode().rstrip().split('\n')
return subprocess.check_output(
argv, stderr=subprocess.DEVNULL).decode().rstrip().split('\n')

def parse_pkgbuild(pkgbuild_text):
with tempfile.NamedTemporaryFile() as pkgbuild_file:
Expand Down

0 comments on commit def0dff

Please sign in to comment.