Browse Source

Add support for FILES_PREMIRRORS

This lets us prefer certain alternative paths to the default in
particular cases, such as use of ${libdir}/bin in the case of a multilib
build to avoid bindir conflicts.

Signed-off-by: Christopher Larson <chris_larson@mentor.com>
Christopher Larson 3 years ago
parent
commit
be4fae984d
3 changed files with 42 additions and 18 deletions
  1. 2 0
      classes/external-common.bbclass
  2. 4 4
      classes/external-toolchain.bbclass
  3. 36 14
      lib/oe/external.py

+ 2 - 0
classes/external-common.bbclass

@@ -59,6 +59,8 @@ EXTERNAL_INSTALL_SOURCE_PATHS = "\
 "
 "
 
 
 # Potential locations within the external toolchain sysroot
 # Potential locations within the external toolchain sysroot
+FILES_PREMIRRORS ?= ""
+
 FILES_MIRRORS = "\
 FILES_MIRRORS = "\
     ${bindir}/|/usr/${baselib}/bin/\n \
     ${bindir}/|/usr/${baselib}/bin/\n \
     ${base_libdir}/|/usr/${baselib}/\n \
     ${base_libdir}/|/usr/${baselib}/\n \

+ 4 - 4
classes/external-toolchain.bbclass

@@ -73,7 +73,7 @@ python () {
     if not bb.utils.to_boolean(d.getVar('EXTERNAL_AUTO_PROVIDE', d)):
     if not bb.utils.to_boolean(d.getVar('EXTERNAL_AUTO_PROVIDE', d)):
         return
         return
 
 
-    sysroots, mirrors = oe.external.get_file_search_metadata(d)
+    sysroots, mirrors, premirrors = oe.external.get_file_search_metadata(d)
     search_patterns = []
     search_patterns = []
     pattern = d.getVar('EXTERNAL_PROVIDE_PATTERN', True)
     pattern = d.getVar('EXTERNAL_PROVIDE_PATTERN', True)
     if pattern:
     if pattern:
@@ -82,7 +82,7 @@ python () {
         files = oe.external.gather_pkg_files(d)
         files = oe.external.gather_pkg_files(d)
         search_patterns.extend(filter(lambda f: '.debug' not in f, files))
         search_patterns.extend(filter(lambda f: '.debug' not in f, files))
 
 
-    expanded = oe.external.expand_paths(search_patterns, mirrors)
+    expanded = oe.external.expand_paths(search_patterns, mirrors, premirrors)
     paths = oe.external.search_sysroots(expanded, sysroots)
     paths = oe.external.search_sysroots(expanded, sysroots)
     if not any(f for p, f in paths):
     if not any(f for p, f in paths):
         raise bb.parse.SkipPackage('No files found in external toolchain sysroot for: {}'.format(', '.join(search_patterns)))
         raise bb.parse.SkipPackage('No files found in external toolchain sysroot for: {}'.format(', '.join(search_patterns)))
@@ -118,9 +118,9 @@ def external_toolchain_propagate_mode (d, installdest):
 python external_toolchain_do_install () {
 python external_toolchain_do_install () {
     import subprocess
     import subprocess
     installdest = d.getVar('D', True)
     installdest = d.getVar('D', True)
-    sysroots, mirrors = oe.external.get_file_search_metadata(d)
+    sysroots, mirrors, premirrors = oe.external.get_file_search_metadata(d)
     files = oe.external.gather_pkg_files(d)
     files = oe.external.gather_pkg_files(d)
-    oe.external.copy_from_sysroots(files, sysroots, mirrors, installdest)
+    oe.external.copy_from_sysroots(files, sysroots, mirrors, premirrors, installdest)
     if 'do_install_extra' in d:
     if 'do_install_extra' in d:
         bb.build.exec_func('do_install_extra', d)
         bb.build.exec_func('do_install_extra', d)
     external_toolchain_propagate_mode(d, installdest)
     external_toolchain_propagate_mode(d, installdest)

+ 36 - 14
lib/oe/external.py

@@ -29,24 +29,35 @@ def run(d, cmd, *args):
     return 'UNKNOWN'
     return 'UNKNOWN'
 
 
 
 
-def get_file_search_metadata(d):
-    '''Given the metadata, return the mirrors and sysroots to operate against.'''
-
-    mirrors = []
-    for entry in d.getVar('FILES_MIRRORS').replace('\\n', '\n').split('\n'):
+def parse_mirrors(mirrors_string):
+    mirrors, invalid = [], []
+    for entry in mirrors_string.replace('\\n', '\n').split('\n'):
         entry = entry.strip()
         entry = entry.strip()
         if not entry:
         if not entry:
             continue
             continue
         try:
         try:
             pathname, subst = entry.strip().split('|', 1)
             pathname, subst = entry.strip().split('|', 1)
         except ValueError:
         except ValueError:
-            bb.warn('Invalid FILES_MIRRORS entry: {0}'.format(entry))
+            invalid.append(entry)
         mirrors.append(('^' + re.escape(pathname), subst))
         mirrors.append(('^' + re.escape(pathname), subst))
+    return mirrors, invalid
+
+
+def get_file_search_metadata(d):
+    '''Given the metadata, return the mirrors and sysroots to operate against.'''
+
+    premirrors, invalid = parse_mirrors(d.getVar('FILES_PREMIRRORS'))
+    for invalid_entry in invalid:
+        bb.warn('Invalid FILES_MIRRORS entry: {0}'.format(invalid_entry))
+
+    mirrors, invalid = parse_mirrors(d.getVar('FILES_MIRRORS'))
+    for invalid_entry in invalid:
+        bb.warn('Invalid FILES_MIRRORS entry: {0}'.format(invalid_entry))
 
 
     source_paths = [os.path.realpath(p)
     source_paths = [os.path.realpath(p)
                     for p in d.getVar('EXTERNAL_INSTALL_SOURCE_PATHS').split()]
                     for p in d.getVar('EXTERNAL_INSTALL_SOURCE_PATHS').split()]
 
 
-    return source_paths, mirrors
+    return source_paths, mirrors, premirrors
 
 
 
 
 def gather_pkg_files(d):
 def gather_pkg_files(d):
@@ -60,10 +71,10 @@ def gather_pkg_files(d):
     return files
     return files
 
 
 
 
-def copy_from_sysroots(pathnames, sysroots, mirrors, installdest):
+def copy_from_sysroots(pathnames, sysroots, mirrors, premirrors, installdest):
     '''Copy the specified files from the specified sysroots, also checking the
     '''Copy the specified files from the specified sysroots, also checking the
     specified mirror patterns as alternate paths, to the specified destination.'''
     specified mirror patterns as alternate paths, to the specified destination.'''
-    expanded_pathnames = expand_paths(pathnames, mirrors)
+    expanded_pathnames = expand_paths(pathnames, mirrors, premirrors)
     searched_paths = search_sysroots(expanded_pathnames, sysroots)
     searched_paths = search_sysroots(expanded_pathnames, sysroots)
     for path, files in searched_paths:
     for path, files in searched_paths:
         if not files:
         if not files:
@@ -74,13 +85,24 @@ def copy_from_sysroots(pathnames, sysroots, mirrors, installdest):
             subprocess.check_call(['cp', '-PR', '--preserve=mode,timestamps', '--no-preserve=ownership'] + list(files) + [destdir + '/'])
             subprocess.check_call(['cp', '-PR', '--preserve=mode,timestamps', '--no-preserve=ownership'] + list(files) + [destdir + '/'])
             bb.note('Copied `{}`  to `{}/`'.format(', '.join(files), destdir))
             bb.note('Copied `{}`  to `{}/`'.format(', '.join(files), destdir))
 
 
-def expand_paths(pathnames, mirrors):
+def expand_paths(pathnames, mirrors, premirrors):
     '''Apply search/replace to paths to get alternate search paths.
     '''Apply search/replace to paths to get alternate search paths.
 
 
     Returns a generator with tuples of (pathname, expanded_paths).'''
     Returns a generator with tuples of (pathname, expanded_paths).'''
     import re
     import re
     for pathname in pathnames:
     for pathname in pathnames:
-        expanded_paths = [pathname]
+        expanded_paths = []
+
+        for search, replace in premirrors:
+            try:
+                new_pathname = re.sub(search, replace, pathname, count=1)
+            except re.error as exc:
+                bb.warn("Invalid pattern for `%s`" % search)
+                continue
+            if new_pathname != pathname:
+                expanded_paths.append(new_pathname)
+
+        expanded_paths.append(pathname)
 
 
         for search, replace in mirrors:
         for search, replace in mirrors:
             try:
             try:
@@ -102,7 +124,7 @@ def search_sysroots(path_entries, sysroots):
     import itertools
     import itertools
     for path, pathnames in path_entries:
     for path, pathnames in path_entries:
         for sysroot, pathname in ((s, p) for s in sysroots
         for sysroot, pathname in ((s, p) for s in sysroots
-                                         for p in itertools.chain([path], pathnames)):
+                                         for p in pathnames):
             check_path = sysroot + os.sep + pathname
             check_path = sysroot + os.sep + pathname
             found_paths = glob.glob(check_path)
             found_paths = glob.glob(check_path)
             if found_paths:
             if found_paths:
@@ -113,7 +135,7 @@ def search_sysroots(path_entries, sysroots):
 
 
 
 
 def find_sysroot_files(paths, d):
 def find_sysroot_files(paths, d):
-    sysroots, mirrors = get_file_search_metadata(d)
-    expanded = expand_paths(paths, mirrors)
+    sysroots, mirrors, premirrors = get_file_search_metadata(d)
+    expanded = expand_paths(paths, mirrors, premirrors)
     search_results = list(search_sysroots(expanded, sysroots))
     search_results = list(search_sysroots(expanded, sysroots))
     return [v for k, v in search_results]
     return [v for k, v in search_results]