-def rchop(thestring, ending):
- if thestring.endswith(ending):
- return thestring[:-len(ending)]
- return thestring
-
-class TermuxBuildFile(object):
- def __init__(self, path):
- self.path = path
-
- def _get_dependencies(self):
- pkg_dep_prefix = 'TERMUX_PKG_DEPENDS='
- pkg_build_dep_prefix = 'TERMUX_PKG_BUILD_DEPENDS='
- subpkg_dep_prefix = 'TERMUX_SUBPKG_DEPENDS='
- comma_deps = ''
-
- with open(self.path, encoding="utf-8") as f:
- prefix = None
- for line in f:
- if line.startswith(pkg_dep_prefix):
- prefix = pkg_dep_prefix
- elif line.startswith(pkg_build_dep_prefix):
- prefix = pkg_build_dep_prefix
- elif line.startswith(subpkg_dep_prefix):
- prefix = subpkg_dep_prefix
- else:
- continue
-
- comma_deps += line[len(prefix):].replace('"', '').replace("'", '').replace("\n", ",")
-
- # Remove trailing ',' that is otherwise replacing the final newline
- comma_deps = comma_deps[:-1]
- if not comma_deps:
- # no deps found
- return set()
-
- return set([
- # Replace parenthesis to handle version qualifiers, as in "gcc (>= 5.0)":
- rchop(re.sub(r'\(.*?\)', '', dep).strip(), '-dev') for dep in comma_deps.split(',')
- ])
-
+def parse_build_file_dependencies(path):
+ "Extract the dependencies of a build.sh or *.subpackage.sh file."
+ pkg_dep_prefix = 'TERMUX_PKG_DEPENDS='
+ pkg_build_dep_prefix = 'TERMUX_PKG_BUILD_DEPENDS='
+ subpkg_dep_prefix = 'TERMUX_SUBPKG_DEPENDS='
+ dependencies = []
+
+ with open(path, encoding="utf-8") as build_script:
+ prefix = None
+ for line in build_script:
+ if line.startswith(pkg_dep_prefix):
+ prefix = pkg_dep_prefix
+ elif line.startswith(pkg_build_dep_prefix):
+ prefix = pkg_build_dep_prefix
+ elif line.startswith(subpkg_dep_prefix):
+ prefix = subpkg_dep_prefix
+ else:
+ continue
+
+ dependencies_string = line[len(prefix):]
+ for char in "\"'\n":
+ dependencies_string = dependencies_string.replace(char, '')
+
+ for dependency_value in dependencies_string.split(','):
+ # Replace parenthesis to ignore version qualifiers as in "gcc (>= 5.0)":
+ dependency_value = re.sub(r'\(.*?\)', '', dependency_value).strip()
+ dependency_value = re.sub('-dev$', '', dependency_value)
+ dependencies.append(dependency_value)
+
+ return set(dependencies)