Skip to content

Commit dbe58b4

Browse files
paths fix for check tool (platformio#4874)
* paths fix for check tool * Minor changes - Handle an edge case on Windows when sources and the project are located on different drives - Cover edge cases with tests --------- Co-authored-by: Valerii Koval <valeros@users.noreply.github.com>
1 parent d36e394 commit dbe58b4

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

platformio/check/cli.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,21 @@ def cli(
103103
"%s: %s" % (k, ", ".join(v) if isinstance(v, list) else v)
104104
)
105105

106-
default_src_filters = [
107-
"+<%s>" % os.path.basename(config.get("platformio", "src_dir")),
108-
"+<%s>" % os.path.basename(config.get("platformio", "include_dir")),
109-
]
106+
default_src_filters = []
107+
for d in (
108+
config.get("platformio", "src_dir"),
109+
config.get("platformio", "include_dir"),
110+
):
111+
try:
112+
default_src_filters.append("+<%s>" % os.path.relpath(d))
113+
except ValueError as exc:
114+
# On Windows if sources are located on a different logical drive
115+
if not json_output and not silent:
116+
click.echo(
117+
"Error: Project cannot be analyzed! The project folder `%s`"
118+
" is located on a different logical drive\n" % d
119+
)
120+
raise exception.ReturnErrorCode(1) from exc
110121

111122
env_src_filters = (
112123
src_filters

tests/commands/test_check.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,49 @@ def test_check_src_filter_multiple_envs(clirunner, validate_cliresult, tmpdir_fa
803803
assert errors + warnings + style == EXPECTED_DEFECTS
804804
assert "test.cpp" in result.output
805805
assert "main.cpp" not in result.output
806+
807+
808+
def test_check_sources_in_project_root(clirunner, validate_cliresult, tmpdir_factory):
809+
tmpdir = tmpdir_factory.mktemp("project")
810+
811+
config = (
812+
"""
813+
[platformio]
814+
src_dir = ./
815+
"""
816+
+ DEFAULT_CONFIG
817+
)
818+
tmpdir.join("platformio.ini").write(config)
819+
tmpdir.join("main.cpp").write(TEST_CODE)
820+
tmpdir.mkdir("spi").join("uart.cpp").write(TEST_CODE)
821+
822+
result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir)])
823+
validate_cliresult(result)
824+
825+
errors, warnings, style = count_defects(result.output)
826+
827+
assert result.exit_code == 0
828+
assert errors + warnings + style == EXPECTED_DEFECTS * 2
829+
830+
831+
def test_check_sources_in_external_dir(clirunner, validate_cliresult, tmpdir_factory):
832+
tmpdir = tmpdir_factory.mktemp("project")
833+
external_src_dir = tmpdir_factory.mktemp("external_src_dir")
834+
835+
config = (
836+
f"""
837+
[platformio]
838+
src_dir = {external_src_dir}
839+
"""
840+
+ DEFAULT_CONFIG
841+
)
842+
tmpdir.join("platformio.ini").write(config)
843+
external_src_dir.join("main.cpp").write(TEST_CODE)
844+
845+
result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir)])
846+
validate_cliresult(result)
847+
848+
errors, warnings, style = count_defects(result.output)
849+
850+
assert result.exit_code == 0
851+
assert errors + warnings + style == EXPECTED_DEFECTS

0 commit comments

Comments
 (0)