From 11df0217501a7aaf9f78a32cf52b69dc14c1fcb1 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 1 Dec 2023 19:38:25 +0200 Subject: [PATCH] Resolve an issue where running `pio project metadata` resulted in duplicated include entries // Resolve #4723 --- HISTORY.rst | 1 + platformio/builder/tools/piointegration.py | 7 +- platformio/builder/tools/piolib.py | 4 +- tests/project/test_metadata.py | 82 ++++++++++++++++++++++ 4 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 tests/project/test_metadata.py diff --git a/HISTORY.rst b/HISTORY.rst index b35a8744..778042b0 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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 `_) * 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 `_) * Resolved an issue with incorrect handling of the ``check_src_filters`` option when used in multiple environments (`issue #4788 `_) +* Resolved an issue where running `pio project metadata `__ resulted in duplicated include entries (`issue #4723 `_) 6.1.11 (2023-08-31) ~~~~~~~~~~~~~~~~~~~ diff --git a/platformio/builder/tools/piointegration.py b/platformio/builder/tools/piointegration.py index 6f0a972e..00ecb88a 100644 --- a/platformio/builder/tools/piointegration.py +++ b/platformio/builder/tools/piointegration.py @@ -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", [])] ) diff --git a/platformio/builder/tools/piolib.py b/platformio/builder/tools/piolib.py index 70b0811c..aa18cd1a 100644 --- a/platformio/builder/tools/piolib.py +++ b/platformio/builder/tools/piolib.py @@ -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 diff --git a/tests/project/test_metadata.py b/tests/project/test_metadata.py new file mode 100644 index 00000000..a536dd72 --- /dev/null +++ b/tests/project/test_metadata.py @@ -0,0 +1,82 @@ +# Copyright (c) 2014-present PlatformIO +# +# 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 + +void dummy(void ) {}; + """ + ) + + tmpdir.mkdir("src").join("main.c").write( + """ +#include + +#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