Minor improvements to the ProjectAsLibBuilder

This commit is contained in:
Ivan Kravets
2022-06-25 20:10:18 +03:00
parent 86c4bd69d2
commit 300b7b2138
2 changed files with 35 additions and 29 deletions

View File

@ -332,9 +332,7 @@ class LibBuilderBase:
if not LibBuilderBase._INCLUDE_DIRS_CACHE:
LibBuilderBase._INCLUDE_DIRS_CACHE = [
self.env.Dir(d)
for d in ProjectAsLibBuilder(
self.envorigin, "$PROJECT_DIR"
).get_include_dirs()
for d in ProjectAsLibBuilder.get_instance().get_include_dirs()
]
for lb in self.env.GetLibBuilders():
LibBuilderBase._INCLUDE_DIRS_CACHE.extend(
@ -766,6 +764,24 @@ class PlatformIOLibBuilder(LibBuilderBase):
return os.path.abspath(self._manifest.get("build").get("includeDir"))
return LibBuilderBase.include_dir.fget(self) # pylint: disable=no-member
def get_include_dirs(self):
include_dirs = super().get_include_dirs()
# backwards compatibility with PlatformIO 2.0
if (
"build" not in self._manifest
and self._has_arduino_manifest()
and not os.path.isdir(os.path.join(self.path, "src"))
and os.path.isdir(os.path.join(self.path, "utility"))
):
include_dirs.append(os.path.join(self.path, "utility"))
for path in self.env.get("CPPPATH", []):
if path not in self.envorigin.get("CPPPATH", []):
include_dirs.append(self.env.subst(path))
return include_dirs
@property
def src_dir(self):
if "srcDir" in self._manifest.get("build", {}):
@ -841,32 +857,23 @@ class PlatformIOLibBuilder(LibBuilderBase):
def is_frameworks_compatible(self, frameworks):
return util.items_in_list(frameworks, self._manifest.get("frameworks") or ["*"])
def get_include_dirs(self):
include_dirs = super().get_include_dirs()
# backwards compatibility with PlatformIO 2.0
if (
"build" not in self._manifest
and self._has_arduino_manifest()
and not os.path.isdir(os.path.join(self.path, "src"))
and os.path.isdir(os.path.join(self.path, "utility"))
):
include_dirs.append(os.path.join(self.path, "utility"))
for path in self.env.get("CPPPATH", []):
if path not in self.envorigin.get("CPPPATH", []):
include_dirs.append(self.env.subst(path))
return include_dirs
class ProjectAsLibBuilder(LibBuilderBase):
_INSTANCE = None
def __init__(self, env, *args, **kwargs):
# backup original value, will be reset in base.__init__
project_src_filter = env.get("SRC_FILTER")
super().__init__(env, *args, **kwargs)
self.env["SRC_FILTER"] = project_src_filter
@classmethod
def get_instance(cls, *args, **kwargs):
if not cls._INSTANCE:
cls._INSTANCE = ProjectAsLibBuilder(*args, **kwargs)
return cls._INSTANCE
@property
def include_dir(self):
include_dir = self.env.subst("$PROJECT_INCLUDE_DIR")
@ -1129,7 +1136,7 @@ def ConfigureProjectLibBuilder(env):
if lb.depbuilders:
_print_deps_tree(lb, level + 1)
project = ProjectAsLibBuilder(env, "$PROJECT_DIR")
project = ProjectAsLibBuilder.get_instance(env, "$PROJECT_DIR")
env.Export(dict(projenv=project.env))
ldf_mode = LibBuilderBase.lib_ldf_mode.fget(project) # pylint: disable=no-member

View File

@ -141,23 +141,22 @@ def ProcessProgramDeps(env):
def ProcessProjectDeps(env):
project_lib_builder = env.ConfigureProjectLibBuilder()
projenv = project_lib_builder.env
plb = env.ConfigureProjectLibBuilder()
# prepend project libs to the beginning of list
env.Prepend(LIBS=project_lib_builder.build())
env.Prepend(LIBS=plb.build())
# prepend extra linker related options from libs
env.PrependUnique(
**{
key: project_lib_builder.env.get(key)
key: plb.env.get(key)
for key in ("LIBS", "LIBPATH", "LINKFLAGS")
if project_lib_builder.env.get(key)
if plb.env.get(key)
}
)
if "test" in env.GetBuildType():
build_files_before_nums = len(env.get("PIOBUILDFILES", []))
projenv.BuildSources(
plb.env.BuildSources(
"$BUILD_TEST_DIR", "$PROJECT_TEST_DIR", "$PIOTEST_SRC_FILTER"
)
if len(env.get("PIOBUILDFILES", [])) - build_files_before_nums < 1:
@ -168,7 +167,7 @@ def ProcessProjectDeps(env):
env.Exit(1)
if "test" not in env.GetBuildType() or env.GetProjectOption("test_build_src"):
projenv.BuildSources(
plb.env.BuildSources(
"$BUILD_SRC_DIR", "$PROJECT_SRC_DIR", env.get("SRC_FILTER")
)