fix test_cmake_as_package fail

Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
This commit is contained in:
Jerry Yu 2021-12-02 13:51:26 +08:00
parent eb96fb508e
commit e6369b0061
3 changed files with 61 additions and 14 deletions

View file

@ -17,12 +17,15 @@
# limitations under the License.
import os
import inspect
def looks_like_mbedtls_root(path: str) -> bool:
"""Whether the given directory looks like the root of the Mbed TLS source tree."""
return all(os.path.isdir(os.path.join(path, subdir))
for subdir in ['include', 'library', 'programs', 'tests'])
def chdir_to_root() -> None:
"""Detect the root of the Mbed TLS source tree and change to it.
@ -36,3 +39,21 @@ def chdir_to_root() -> None:
os.chdir(d)
return
raise Exception('Mbed TLS source tree not found')
def guess_mbedtls_root():
"""Guess mbedTLS source code directory.
Return the first possible mbedTLS root directory
"""
dirs = set({})
for i in inspect.stack():
path = os.path.dirname(i.filename)
for d in ['.', os.path.pardir, os.path.join(*([os.path.pardir]*2))]:
d = os.path.abspath(os.path.join(path, d))
if d in dirs:
continue
dirs.add(d)
if looks_like_mbedtls_root(d):
return d
raise Exception('Mbed TLS source tree not found')