[arch-dev-public] [PATCH 1/2] Revert "Reduce the amount of false positives in extravars rule."

Dan McGee dan at archlinux.org
Tue Mar 15 03:36:26 EDT 2011


This reverts the non-test portions of commit
e2044d4583f80cd6283a2f8d0ffa1d6f5d834123.

This is not the proper way to fix this, and we most definitely should
not have to parse, subprocess, or do anything with bash more than once,
especially in a rule. We also shouldn't assume everyone has a perfectly
clean environment with no extra variables exported and defined. Revert
the entire thing, minus the added test, with a better fix on the way.

Signed-off-by: Dan McGee <dan at archlinux.org>
---
 Namcap/rules/extravars.py |   52 ++++++--------------------------------------
 1 files changed, 7 insertions(+), 45 deletions(-)

diff --git a/Namcap/rules/extravars.py b/Namcap/rules/extravars.py
index 0288335..01031f5 100644
--- a/Namcap/rules/extravars.py
+++ b/Namcap/rules/extravars.py
@@ -18,47 +18,8 @@
 # 
 
 import re
-import os
-import subprocess
-import tempfile
 from Namcap.ruleclass import *
 
-BASH_BUILTINS = set([
-	"BASH", "BASHOPTS", "BASH_ALIASES", "BASH_ARGC", "BASH_ARGV", "BASH_CMDS", "BASH_LINENO",
-	"BASH_SOURCE", "BASH_VERSINFO", "BASH_VERSION", "DIRSTACK", "EUID", "GROUPS", "HOSTNAME",
-	"HOSTTYPE", "IFS", "MACHTYPE", "OPTERR", "OPTIND", "OSTYPE", "PATH", "PIPESTATUS", "PPID",
-	"PS1", "PS2", "PS3", "PS4",
-	"PWD", "SHELL", "SHELLOPTS", "SHLVL", "TERM", "UID",
-	])
-
-def find_lowercase_global_vars(pkgbuild):
-	# list the variable names beginning with a lowercase letter
-	varnames = []
-
-	# write an annotated PKGBUILD to a temporary file
-	f = tempfile.NamedTemporaryFile(delete = False)
-	annotated_pkgbuild = pkgbuild + "\ndeclare +x"
-	f.write(annotated_pkgbuild.encode('utf-8'))
-	f.close()
-	# run bash -r on it to list variables
-	cwd = os.getcwd()
-	os.chdir(os.path.dirname(f.name))
-	p = subprocess.Popen(["bash", "-r", os.path.basename(f.name)],
-			stdout = subprocess.PIPE, stderr = subprocess.PIPE)
-	out, err = p.communicate()
-
-	if p.returncode != 0:
-		raise ValueError("parsing PKGBUILD failed")
-	else:
-		for l in out.decode("utf-8", "ignore").splitlines():
-			m = re.match('[\s]*([a-z][a-zA-Z_0-9]*)\+?=', l)
-			if not m:
-				continue
-			varnames.append(m.group(1))
-
-	os.unlink(f.name)
-	return set(varnames)
-
 class package(PkgbuildRule):
 	name = "extravars"
 	description = "Verifies that extra variables start with an underscore"
@@ -70,11 +31,12 @@ class package(PkgbuildRule):
 				 'pkgbase', 'pkgver', 'pkgrel', 'pkgdesc', 'groups',
 				 'url', 'install', 'changelog',
 				 'options', 'optdepends']
-		pkgbuild_vars = find_lowercase_global_vars("\n".join(pkginfo.pkgbuild))
-		nonstdvars = pkgbuild_vars - set(stdvars)
-		self.warnings.extend(
-			[("extra-var-begins-without-underscore %s", varname) for
-				varname in nonstdvars]
-			)
+		for i in pkginfo.pkgbuild:
+			m = re.match('[\s]*([a-z][^\s=]*[^+])=', i)
+			if m:
+				varname = m.group(1)
+				if varname not in stdvars:
+					if not varname.startswith('_'):
+						self.warnings.append(("extra-var-begins-without-underscore %s", varname))
 
 # vim: set ts=4 sw=4 noet:
-- 
1.7.4.1



More information about the arch-dev-public mailing list