mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Minor improvements to the ProjectAsLibBuilder
This commit is contained in:
@ -332,9 +332,7 @@ class LibBuilderBase:
|
|||||||
if not LibBuilderBase._INCLUDE_DIRS_CACHE:
|
if not LibBuilderBase._INCLUDE_DIRS_CACHE:
|
||||||
LibBuilderBase._INCLUDE_DIRS_CACHE = [
|
LibBuilderBase._INCLUDE_DIRS_CACHE = [
|
||||||
self.env.Dir(d)
|
self.env.Dir(d)
|
||||||
for d in ProjectAsLibBuilder(
|
for d in ProjectAsLibBuilder.get_instance().get_include_dirs()
|
||||||
self.envorigin, "$PROJECT_DIR"
|
|
||||||
).get_include_dirs()
|
|
||||||
]
|
]
|
||||||
for lb in self.env.GetLibBuilders():
|
for lb in self.env.GetLibBuilders():
|
||||||
LibBuilderBase._INCLUDE_DIRS_CACHE.extend(
|
LibBuilderBase._INCLUDE_DIRS_CACHE.extend(
|
||||||
@ -766,6 +764,24 @@ class PlatformIOLibBuilder(LibBuilderBase):
|
|||||||
return os.path.abspath(self._manifest.get("build").get("includeDir"))
|
return os.path.abspath(self._manifest.get("build").get("includeDir"))
|
||||||
return LibBuilderBase.include_dir.fget(self) # pylint: disable=no-member
|
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
|
@property
|
||||||
def src_dir(self):
|
def src_dir(self):
|
||||||
if "srcDir" in self._manifest.get("build", {}):
|
if "srcDir" in self._manifest.get("build", {}):
|
||||||
@ -841,32 +857,23 @@ class PlatformIOLibBuilder(LibBuilderBase):
|
|||||||
def is_frameworks_compatible(self, frameworks):
|
def is_frameworks_compatible(self, frameworks):
|
||||||
return util.items_in_list(frameworks, self._manifest.get("frameworks") or ["*"])
|
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):
|
class ProjectAsLibBuilder(LibBuilderBase):
|
||||||
|
|
||||||
|
_INSTANCE = None
|
||||||
|
|
||||||
def __init__(self, env, *args, **kwargs):
|
def __init__(self, env, *args, **kwargs):
|
||||||
# backup original value, will be reset in base.__init__
|
# backup original value, will be reset in base.__init__
|
||||||
project_src_filter = env.get("SRC_FILTER")
|
project_src_filter = env.get("SRC_FILTER")
|
||||||
super().__init__(env, *args, **kwargs)
|
super().__init__(env, *args, **kwargs)
|
||||||
self.env["SRC_FILTER"] = project_src_filter
|
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
|
@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")
|
||||||
@ -1129,7 +1136,7 @@ def ConfigureProjectLibBuilder(env):
|
|||||||
if lb.depbuilders:
|
if lb.depbuilders:
|
||||||
_print_deps_tree(lb, level + 1)
|
_print_deps_tree(lb, level + 1)
|
||||||
|
|
||||||
project = ProjectAsLibBuilder(env, "$PROJECT_DIR")
|
project = ProjectAsLibBuilder.get_instance(env, "$PROJECT_DIR")
|
||||||
env.Export(dict(projenv=project.env))
|
env.Export(dict(projenv=project.env))
|
||||||
|
|
||||||
ldf_mode = LibBuilderBase.lib_ldf_mode.fget(project) # pylint: disable=no-member
|
ldf_mode = LibBuilderBase.lib_ldf_mode.fget(project) # pylint: disable=no-member
|
||||||
|
@ -141,23 +141,22 @@ def ProcessProgramDeps(env):
|
|||||||
|
|
||||||
|
|
||||||
def ProcessProjectDeps(env):
|
def ProcessProjectDeps(env):
|
||||||
project_lib_builder = env.ConfigureProjectLibBuilder()
|
plb = env.ConfigureProjectLibBuilder()
|
||||||
projenv = project_lib_builder.env
|
|
||||||
|
|
||||||
# prepend project libs to the beginning of list
|
# 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
|
# prepend extra linker related options from libs
|
||||||
env.PrependUnique(
|
env.PrependUnique(
|
||||||
**{
|
**{
|
||||||
key: project_lib_builder.env.get(key)
|
key: plb.env.get(key)
|
||||||
for key in ("LIBS", "LIBPATH", "LINKFLAGS")
|
for key in ("LIBS", "LIBPATH", "LINKFLAGS")
|
||||||
if project_lib_builder.env.get(key)
|
if plb.env.get(key)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if "test" in env.GetBuildType():
|
if "test" in env.GetBuildType():
|
||||||
build_files_before_nums = len(env.get("PIOBUILDFILES", []))
|
build_files_before_nums = len(env.get("PIOBUILDFILES", []))
|
||||||
projenv.BuildSources(
|
plb.env.BuildSources(
|
||||||
"$BUILD_TEST_DIR", "$PROJECT_TEST_DIR", "$PIOTEST_SRC_FILTER"
|
"$BUILD_TEST_DIR", "$PROJECT_TEST_DIR", "$PIOTEST_SRC_FILTER"
|
||||||
)
|
)
|
||||||
if len(env.get("PIOBUILDFILES", [])) - build_files_before_nums < 1:
|
if len(env.get("PIOBUILDFILES", [])) - build_files_before_nums < 1:
|
||||||
@ -168,7 +167,7 @@ def ProcessProjectDeps(env):
|
|||||||
env.Exit(1)
|
env.Exit(1)
|
||||||
|
|
||||||
if "test" not in env.GetBuildType() or env.GetProjectOption("test_build_src"):
|
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")
|
"$BUILD_SRC_DIR", "$PROJECT_SRC_DIR", env.get("SRC_FILTER")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user