Resolve an issue where running pio project metadata resulted in duplicated include entries // Resolve #4723

This commit is contained in:
Ivan Kravets
2023-12-01 19:38:25 +02:00
parent ac6d94860b
commit 11df021750
4 changed files with 87 additions and 7 deletions

View File

@ -25,6 +25,7 @@ test-driven methodologies, and modern toolchains for unrivaled success.
* Resolved an issue where the ``COMPILATIONDB_INCLUDE_TOOLCHAIN`` setting was not correctly applying to private libraries (`issue #4762 <https://github.com/platformio/platformio-core/issues/4762>`_)
* Resolved an issue where ``get_systype()`` inaccurately returned the architecture when executed within a Docker container on a 64-bit kernel with a 32-bit userspace (`issue #4777 <https://github.com/platformio/platformio-core/issues/4777>`_)
* Resolved an issue with incorrect handling of the ``check_src_filters`` option when used in multiple environments (`issue #4788 <https://github.com/platformio/platformio-core/issues/4788>`_)
* Resolved an issue where running `pio project metadata <https://docs.platformio.org/en/latest/core/userguide/project/cmd_metadata.html>`__ resulted in duplicated include entries (`issue #4723 <https://github.com/platformio/platformio-core/issues/4723>`_)
6.1.11 (2023-08-31)
~~~~~~~~~~~~~~~~~~~

View File

@ -29,12 +29,7 @@ def IsIntegrationDump(_):
def DumpIntegrationIncludes(env):
result = dict(build=[], compatlib=[], toolchain=[])
result["build"].extend(
[
env.subst("$PROJECT_INCLUDE_DIR"),
env.subst("$PROJECT_SRC_DIR"),
]
)
# `env`(project) CPPPATH
result["build"].extend(
[os.path.abspath(env.subst(item)) for item in env.get("CPPPATH", [])]
)

View File

@ -792,7 +792,9 @@ class PlatformIOLibBuilder(LibBuilderBase):
include_dirs.append(os.path.join(self.path, "utility"))
for path in self.env.get("CPPPATH", []):
if path not in self.envorigin.get("CPPPATH", []):
if path not in include_dirs and path not in self.envorigin.get(
"CPPPATH", []
):
include_dirs.append(self.env.subst(path))
return include_dirs

View File

@ -0,0 +1,82 @@
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from platformio.project.commands.metadata import project_metadata_cmd
def test_metadata_dump(clirunner, validate_cliresult, tmpdir):
tmpdir.join("platformio.ini").write(
"""
[env:native]
platform = native
"""
)
component_dir = tmpdir.mkdir("lib").mkdir("component")
component_dir.join("library.json").write(
"""
{
"name": "component",
"version": "1.0.0"
}
"""
)
component_dir.mkdir("include").join("component.h").write(
"""
#define I_AM_COMPONENT
void dummy(void);
"""
)
component_dir.mkdir("src").join("component.cpp").write(
"""
#include <component.h>
void dummy(void ) {};
"""
)
tmpdir.mkdir("src").join("main.c").write(
"""
#include <component.h>
#ifndef I_AM_COMPONENT
#error "I_AM_COMPONENT"
#endif
int main() {
}
"""
)
metadata_path = tmpdir.join("metadata.json")
result = clirunner.invoke(
project_metadata_cmd,
[
"--project-dir",
str(tmpdir),
"-e",
"native",
"--json-output",
"--json-output-path",
str(metadata_path),
],
)
validate_cliresult(result)
with open(str(metadata_path), encoding="utf8") as fp:
metadata = json.load(fp)["native"]
assert len(metadata["includes"]["build"]) == 3
assert len(metadata["includes"]["compatlib"]) == 2