Skip to content
  • Oliver Smith's avatar
    APKBUILD parser: recognize all top-level variables (MR 2300) · 85ee201c
    Oliver Smith authored
    A common pattern in APKBUILDs, is to introduce custom variables prefixed
    with underscores that get then used in makedepends and other variables.
    
    For example:
    
      _wlrootsmakedepends="
    	eudev-dev
      	# ...
      	"
      makedepends="
      	# ...
      	$_wlrootsmakedepends
      	"
    
    Adjust the APKBUILD parser code, so it parses all top-level variables
    and can use them further below when referenced inside other variables.
    Before returning the parsed APKBUILD data, remove all variables that are
    not in pmbootstrap's list of known APKBUILD parsing attributes (so the
    result is the same).
    
    I've compared "pmbootstrap apkbuild_parse" (which parses all APKBUILDs
    in the currently checked out pmaports dir), before and after this
    change, and the result is the same except for having more variables
    successfully replaced.
    
    - Performance Note-
    This new implementation is actually faster than the previous one,
    because we don't need to iterate through all known keys on each line of
    the APKBUILDs. On my machine, average of 3 runs, parsing all APKBUILDs
    of current pmaports master takes about half as long as with the previous
    implementation.
    
      $ time pmbootstrap -q apkbuild_parse >/dev/null
    
    -> old code: 0.954
    -> new code: 0.483
    85ee201c