TDengine/test/new_test_framework/utils/pathFinding.py
WANG Xu c52c68aa4f
sync: apply remaining build system changes from monorepo (main)
The following commits could not be applied individually due to context
differences between the monorepo and the public repo's build files.
They have been applied as a cumulative diff to ensure the final state
matches the monorepo exactly:

- chore: sync CI files with 3.0 branch to eliminate merge conflicts (rd-public/tsdb!271)
- revert(refactor): dynamically link taosd taosudf taosmqtt against libtaosnative.so to reduce binary size (revert #183) (rd-public/tsdb!282)
- fix(docs): autofix formatting issues across all doc files (rd-public/tsdb!296)
- feat: support -DBUILD_SANITIZER=true on windows for debug build (rd-public/tsdb!291)
- feat(build): build cache, mirror, and sccache optimizations (rd-public/tsdb!326)
- docs: update image for three replica (rd-public/tsdb!324)
- enh: shared storage on windows (rd-public/tsdb!333)
- fix(cmake): convert ext_libs3 from git clone to URL tarball download (rd-public/tsdb!360)
- feat: dual-source deps and comprehensive docs/packaging (cherry-pick to main) (rd-public/tsdb!352)
- fix(cmake): guard DOWNLOAD_EXTRACT_TIMESTAMP for CMake < 3.24 and fix duplicate Cargo.lock entry (rd-public/tsdb!369)
- fix: test case execution failure in pytest.sh (rd-public/tsdb!338)
- enh: built-in compilation support for Python UDF plugins use abi3 (rd-public/tsdb!325)
2026-05-23 14:11:50 +08:00

151 lines
No EOL
5.3 KiB
Python

###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import os
from .log import *
def find_proj_root(start_path=None):
"""Find project root directory, supporting multiple CI layouts.
Detects:
- TDinternal CI: /home/TDinternal/... → /home/TDinternal
- tsdb CI: /mnt/tsdb/source/taos-community/... → /mnt/tsdb
- TDengine OSS: /home/TDengine/... → /home/TDengine
Args:
start_path: Starting path for detection. Defaults to os.getcwd().
Returns:
str: The project root path (where sim/, debug/ etc. are located).
"""
path = start_path or os.getcwd()
parts = path.split(os.sep)
for marker in ("TDinternal", "taos-community", "TDengine"):
if marker in parts:
idx = parts.index(marker)
if marker == "taos-community":
# tsdb layout: .../source/taos-community → root is two levels up
if idx >= 2 and parts[idx - 1] == "source":
return os.sep.join(parts[:idx - 1])
return os.sep.join(parts[:idx])
return os.sep.join(parts[:idx + 1])
raise ValueError("Cannot determine project root from path: " + path)
def find_proj_path(start_path=None):
"""Find the source code project path for os.walk to locate binaries.
Detects:
- taos-community: /mnt/tsdb/source/taos-community/... → /mnt/tsdb/
(root level, so os.walk finds debug/build/bin/)
- community: /home/TDinternal/community/... → /home/TDinternal/
- TDengine: /home/TDengine/... → /home/TDengine/
- fallback: .../test/... → up to test parent
Args:
start_path: Starting path for detection. Defaults to caller's __file__ dir.
Returns:
str: The project path suitable for os.walk to find taosd/taosBenchmark.
"""
selfPath = start_path or os.path.dirname(os.path.realpath(__file__))
norm_path = selfPath.replace("\\", "/")
if "taos-community" in norm_path:
idx = norm_path.find("source/taos-community")
if idx != -1:
return os.path.normpath(norm_path[:idx])
idx = norm_path.find("taos-community")
if idx != -1:
return os.path.normpath(norm_path[:idx])
elif "community" in norm_path:
idx = norm_path.find("community")
if idx != -1:
return os.path.normpath(norm_path[:idx])
elif "TDengine" in norm_path:
idx = norm_path.find("TDengine")
if idx != -1:
return os.path.normpath(norm_path[: idx + len("TDengine")])
idx = norm_path.find("test")
if idx != -1:
return os.path.normpath(norm_path[:idx])
return os.path.normpath(os.path.dirname(selfPath))
class TDFindPath:
"""This class is for finding path within TDengine
"""
def __init__(self):
self.file = os.path.realpath(__file__)
def init(self, file):
"""[summary]
Args:
file (str): the file location you want to start the query. Generally using __file__
"""
self.file = file
def getTaosdemoPath(self):
"""for finding the path of directory containing taosdemo
Returns:
str: the path to directory containing taosdemo
"""
selfPath = os.path.dirname(os.path.realpath(self.file))
projPath = find_proj_path(selfPath)
for root, dirs, files in os.walk(projPath):
if ".git" in root:
continue
if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath):
buildPath = root[:len(root)-len("/build/bin")]
break
if (buildPath == ""):
tdLog.exit("taosd not found!")
else:
tdLog.info(f"taosd found in {buildPath}")
return buildPath + "/build/bin/"
def getTDenginePath(self):
"""for finding the root path of TDengine
Returns:
str: the root path of TDengine
"""
selfPath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(self.file)))))
return selfPath
if ("community" in selfPath):
projPath = selfPath[:selfPath.find("community")]
else:
projPath = selfPath[:selfPath.find("test")]
print(projPath)
for root, dirs, files in os.walk(projPath):
if ".git" in root:
continue
if ("sim" in dirs):
print(root)
rootRealPath = os.path.realpath(root)
if (rootRealPath == ""):
tdLog.exit("TDengine not found!")
else:
tdLog.info(f"TDengine found in {rootRealPath}")
return rootRealPath
tdFindPath = TDFindPath()