Improve detecting of common builder by paths

This commit is contained in:
Ivan Kravets
2022-07-09 21:36:37 +03:00
parent 31a24e1652
commit 7637286efa

View File

@ -143,7 +143,7 @@ class LibBuilderBase:
self._deps_are_processed = False self._deps_are_processed = False
self._circular_deps = [] self._circular_deps = []
self._processed_files = [] self._processed_search_files = []
# reset source filter, could be overridden with extra script # reset source filter, could be overridden with extra script
self.env["SRC_FILTER"] = "" self.env["SRC_FILTER"] = ""
@ -154,20 +154,27 @@ class LibBuilderBase:
def __repr__(self): def __repr__(self):
return "%s(%r)" % (self.__class__, self.path) return "%s(%r)" % (self.__class__, self.path)
def __contains__(self, path): def __contains__(self, child_path):
p1 = self.path return self.is_common_builder(self.path, child_path)
p2 = path
def is_common_builder(self, root_path, child_path):
if IS_WINDOWS: if IS_WINDOWS:
p1 = p1.lower() root_path = root_path.lower()
p2 = p2.lower() child_path = child_path.lower()
if p1 == p2: if root_path == child_path:
return True return True
if os.path.commonprefix([p1 + os.path.sep, p2]) == p1 + os.path.sep: if (
os.path.commonprefix([root_path + os.path.sep, child_path])
== root_path + os.path.sep
):
return True return True
# try to resolve paths # try to resolve paths
p1 = os.path.os.path.realpath(p1) root_path = os.path.realpath(root_path)
p2 = os.path.os.path.realpath(p2) child_path = os.path.realpath(child_path)
return os.path.commonprefix([p1 + os.path.sep, p2]) == p1 + os.path.sep return (
os.path.commonprefix([root_path + os.path.sep, child_path])
== root_path + os.path.sep
)
@property @property
def name(self): def name(self):
@ -879,6 +886,12 @@ class ProjectAsLibBuilder(LibBuilderBase):
if export_projenv: if export_projenv:
env.Export(dict(projenv=self.env)) env.Export(dict(projenv=self.env))
def __contains__(self, child_path):
for root_path in (self.include_dir, self.src_dir, self.test_dir):
if root_path and self.is_common_builder(root_path, child_path):
return True
return False
@property @property
def include_dir(self): def include_dir(self):
include_dir = self.env.subst("$PROJECT_INCLUDE_DIR") include_dir = self.env.subst("$PROJECT_INCLUDE_DIR")
@ -888,6 +901,10 @@ class ProjectAsLibBuilder(LibBuilderBase):
def src_dir(self): def src_dir(self):
return self.env.subst("$PROJECT_SRC_DIR") return self.env.subst("$PROJECT_SRC_DIR")
@property
def test_dir(self):
return self.env.subst("$PROJECT_TEST_DIR")
def get_search_files(self): def get_search_files(self):
items = [] items = []
build_type = self.env.GetBuildType() build_type = self.env.GetBuildType()