|
|
9a80954 |
From 6caca72e63add35ef066cca1dbeae6857ec34b2b Mon Sep 17 00:00:00 2001
|
|
|
9a80954 |
From: Dalibor Pospisil <dapospis@redhat.com>
|
|
|
9a80954 |
Date: Mon, 8 Jun 2020 17:11:51 +0200
|
|
|
9a80954 |
Subject: [PATCH 2/2] enahanced library search
|
|
|
9a80954 |
|
|
|
9a80954 |
---
|
|
|
9a80954 |
src/libraries.sh | 71 ++++++++++++++++++++++++++++++++++++++----------
|
|
|
9a80954 |
1 file changed, 56 insertions(+), 15 deletions(-)
|
|
|
9a80954 |
|
|
|
9a80954 |
diff --git a/src/libraries.sh b/src/libraries.sh
|
|
|
9a80954 |
index 2ccc02e..b40b513 100644
|
|
|
9a80954 |
--- a/src/libraries.sh
|
|
|
9a80954 |
+++ b/src/libraries.sh
|
|
|
9a80954 |
@@ -98,7 +98,7 @@ __INTERNAL_rlLibraryTraverseUpwards() {
|
|
|
9a80954 |
while [ "$DIRECTORY" != "/" ]
|
|
|
9a80954 |
do
|
|
|
9a80954 |
DIRECTORY="$( dirname $DIRECTORY )"
|
|
|
9a80954 |
- if [ -d "$DIRECTORY/$COMPONENT" ]
|
|
|
9a80954 |
+ if [[ -d "$DIRECTORY/$COMPONENT" || -d "$DIRECTORY/libs/$COMPONENT/$LIBRARY" ]]
|
|
|
9a80954 |
then
|
|
|
9a80954 |
|
|
|
9a80954 |
local CANDIDATE="$DIRECTORY/$COMPONENT/Library/$LIBRARY/lib.sh"
|
|
|
9a80954 |
@@ -114,6 +114,14 @@ __INTERNAL_rlLibraryTraverseUpwards() {
|
|
|
9a80954 |
LIBFILE="$CANDIDATE"
|
|
|
9a80954 |
break
|
|
|
9a80954 |
fi
|
|
|
9a80954 |
+
|
|
|
9a80954 |
+ local CANDIDATE="$DIRECTORY/libs/$COMPONENT/$LIBRARY/lib.sh"
|
|
|
9a80954 |
+ if [ -f "$CANDIDATE" ]
|
|
|
9a80954 |
+ then
|
|
|
9a80954 |
+ LIBFILE="$CANDIDATE"
|
|
|
9a80954 |
+ break
|
|
|
9a80954 |
+ fi
|
|
|
9a80954 |
+
|
|
|
9a80954 |
fi
|
|
|
9a80954 |
done
|
|
|
9a80954 |
}
|
|
|
9a80954 |
@@ -139,6 +147,20 @@ __INTERNAL_rlLibrarySearchInRoot(){
|
|
|
9a80954 |
return
|
|
|
9a80954 |
fi
|
|
|
9a80954 |
|
|
|
9a80954 |
+ local CANDIDATE="$BEAKERLIB_LIBRARY_PATH/$COMPONENT/$LIBRARY/lib.sh"
|
|
|
9a80954 |
+ if [ -f "$CANDIDATE" ]
|
|
|
9a80954 |
+ then
|
|
|
9a80954 |
+ LIBFILE="$CANDIDATE"
|
|
|
9a80954 |
+ return
|
|
|
9a80954 |
+ fi
|
|
|
9a80954 |
+
|
|
|
9a80954 |
+ local CANDIDATE="$BEAKERLIB_LIBRARY_PATH/libs/$COMPONENT/$LIBRARY/lib.sh"
|
|
|
9a80954 |
+ if [ -f "$CANDIDATE" ]
|
|
|
9a80954 |
+ then
|
|
|
9a80954 |
+ LIBFILE="$CANDIDATE"
|
|
|
9a80954 |
+ return
|
|
|
9a80954 |
+ fi
|
|
|
9a80954 |
+
|
|
|
9a80954 |
rlLogDebug "rlImport: Library not found in $BEAKERLIB_LIBRARY_PATH"
|
|
|
9a80954 |
}
|
|
|
9a80954 |
|
|
|
9a80954 |
@@ -151,16 +173,20 @@ __INTERNAL_rlLibrarySearch() {
|
|
|
9a80954 |
|
|
|
9a80954 |
if [ -n "$BEAKERLIB_LIBRARY_PATH" ]
|
|
|
9a80954 |
then
|
|
|
9a80954 |
- rlLogDebug "rlImport: BEAKERLIB_LIBRARY_PATH is set: trying to search in it"
|
|
|
9a80954 |
-
|
|
|
9a80954 |
- __INTERNAL_rlLibrarySearchInRoot "$COMPONENT" "$LIBRARY" "$BEAKERLIB_LIBRARY_PATH"
|
|
|
9a80954 |
- if [ -n "$LIBFILE" ]
|
|
|
9a80954 |
- then
|
|
|
9a80954 |
- local VERSION="$(__INTERNAL_extractLibraryVersion "$LIBFILE" "$COMPONENT/$LIBRARY")"
|
|
|
9a80954 |
- VERSION=${VERSION:+", version '$VERSION'"}
|
|
|
9a80954 |
- rlLogInfo "rlImport: Found '$COMPONENT/$LIBRARY'$VERSION in BEAKERLIB_LIBRARY_PATH"
|
|
|
9a80954 |
- return
|
|
|
9a80954 |
- fi
|
|
|
9a80954 |
+ rlLogDebug "rlImport: BEAKERLIB_LIBRARY_PATH='$BEAKERLIB_LIBRARY_PATH'"
|
|
|
9a80954 |
+ local paths=( ${BEAKERLIB_LIBRARY_PATH//:/ } )
|
|
|
9a80954 |
+ while [[ -n "$paths" ]]; do
|
|
|
9a80954 |
+ rlLogDebug "$FUNCNAME(): trying $paths component of BEAKERLIB_LIBRARY_PATH"
|
|
|
9a80954 |
+ __INTERNAL_rlLibrarySearchInRoot "$COMPONENT" "$LIBRARY" "$paths"
|
|
|
9a80954 |
+ if [ -n "$LIBFILE" ]
|
|
|
9a80954 |
+ then
|
|
|
9a80954 |
+ local VERSION="$(__INTERNAL_extractLibraryVersion "$LIBFILE" "$COMPONENT/$LIBRARY")"
|
|
|
9a80954 |
+ VERSION=${VERSION:+", version '$VERSION'"}
|
|
|
9a80954 |
+ rlLogInfo "rlImport: Found '$COMPONENT/$LIBRARY'$VERSION in BEAKERLIB_LIBRARY_PATH"
|
|
|
9a80954 |
+ return
|
|
|
9a80954 |
+ fi
|
|
|
9a80954 |
+ paths=( "${paths[@]:1}" )
|
|
|
9a80954 |
+ done
|
|
|
9a80954 |
else
|
|
|
9a80954 |
rlLogDebug "rlImport: No BEAKERLIB_LIBRARY_PATH set: trying default"
|
|
|
9a80954 |
fi
|
|
|
9a80954 |
@@ -213,10 +239,25 @@ The library search mechanism is based on Beaker test hierarchy system, i.e.:
|
|
|
9a80954 |
|
|
|
9a80954 |
/component/type/test-name/test-file
|
|
|
9a80954 |
|
|
|
9a80954 |
-When test-file calls rlImport with 'foo/bar' parameter, the directory path
|
|
|
9a80954 |
-is traversed upwards, and a check for presence of the test /foo/Library/bar/
|
|
|
9a80954 |
-will be performed. This means this function needs to be called from
|
|
|
9a80954 |
-the test hierarchy, not e.g. the /tmp directory.
|
|
|
9a80954 |
+When test-file calls rlImport with 'foo/bar' parameter, the libraries are searched
|
|
|
9a80954 |
+in following locations:
|
|
|
9a80954 |
+these are the possible path prefixes
|
|
|
9a80954 |
+
|
|
|
9a80954 |
+ - colon-separated paths from $BEAKERLIB_LIBRARY_PATH
|
|
|
9a80954 |
+ - /mnt/tests
|
|
|
9a80954 |
+ - /usr/share/beakerlib-libraries
|
|
|
9a80954 |
+
|
|
|
9a80954 |
+the next component of the path is one of the following:
|
|
|
9a80954 |
+
|
|
|
9a80954 |
+ - /foo/Library/bar
|
|
|
9a80954 |
+ - /*/foo/Library/bar
|
|
|
9a80954 |
+ - /libs/foo/bar
|
|
|
9a80954 |
+
|
|
|
9a80954 |
+the directory path is then constructed as prefix/path/lib.sh
|
|
|
9a80954 |
+If the library is still not found an upwards directory traversal is used, and a
|
|
|
9a80954 |
+check for presence of the library in /foo/Library/bar/ or libs/foo/bar/ is to be
|
|
|
9a80954 |
+performed. This means this function needs to be called from the test hierarchy,
|
|
|
9a80954 |
+not e.g. the /tmp directory.
|
|
|
9a80954 |
|
|
|
9a80954 |
Once library is found, it is sourced and a verifier function is called.
|
|
|
9a80954 |
The verifier function is cunstructed by composing the library prefix and
|
|
|
9a80954 |
--
|
|
|
9a80954 |
2.25.4
|
|
|
9a80954 |
|