diff --git a/platformio/check/cli.py b/platformio/check/cli.py index 3e0c1759..9adf7fb9 100644 --- a/platformio/check/cli.py +++ b/platformio/check/cli.py @@ -103,10 +103,21 @@ def cli( "%s: %s" % (k, ", ".join(v) if isinstance(v, list) else v) ) - default_src_filters = [ - "+<%s>" % os.path.basename(config.get("platformio", "src_dir")), - "+<%s>" % os.path.basename(config.get("platformio", "include_dir")), - ] + default_src_filters = [] + for d in ( + config.get("platformio", "src_dir"), + config.get("platformio", "include_dir"), + ): + try: + default_src_filters.append("+<%s>" % os.path.relpath(d)) + except ValueError as exc: + # On Windows if sources are located on a different logical drive + if not json_output and not silent: + click.echo( + "Error: Project cannot be analyzed! The project folder `%s`" + " is located on a different logical drive\n" % d + ) + raise exception.ReturnErrorCode(1) from exc env_src_filters = ( src_filters diff --git a/tests/commands/test_check.py b/tests/commands/test_check.py index a9a99d65..5f32e77d 100644 --- a/tests/commands/test_check.py +++ b/tests/commands/test_check.py @@ -803,3 +803,49 @@ check_src_filters = assert errors + warnings + style == EXPECTED_DEFECTS assert "test.cpp" in result.output assert "main.cpp" not in result.output + + +def test_check_sources_in_project_root(clirunner, validate_cliresult, tmpdir_factory): + tmpdir = tmpdir_factory.mktemp("project") + + config = ( + """ +[platformio] +src_dir = ./ + """ + + DEFAULT_CONFIG + ) + tmpdir.join("platformio.ini").write(config) + tmpdir.join("main.cpp").write(TEST_CODE) + tmpdir.mkdir("spi").join("uart.cpp").write(TEST_CODE) + + result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir)]) + validate_cliresult(result) + + errors, warnings, style = count_defects(result.output) + + assert result.exit_code == 0 + assert errors + warnings + style == EXPECTED_DEFECTS * 2 + + +def test_check_sources_in_external_dir(clirunner, validate_cliresult, tmpdir_factory): + tmpdir = tmpdir_factory.mktemp("project") + external_src_dir = tmpdir_factory.mktemp("external_src_dir") + + config = ( + f""" +[platformio] +src_dir = {external_src_dir} + """ + + DEFAULT_CONFIG + ) + tmpdir.join("platformio.ini").write(config) + external_src_dir.join("main.cpp").write(TEST_CODE) + + result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir)]) + validate_cliresult(result) + + errors, warnings, style = count_defects(result.output) + + assert result.exit_code == 0 + assert errors + warnings + style == EXPECTED_DEFECTS