forked from platformio/platformio-core
Refactor PIO Check from "check_filters" to "check_patterns"
This commit is contained in:
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from os.path import basename, dirname, isfile
|
from os.path import dirname, isfile
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
import click
|
import click
|
||||||
@ -48,7 +48,7 @@ from platformio.project.helpers import find_project_dir_above, get_project_dir
|
|||||||
exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True
|
exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@click.option("--filter", multiple=True, help="Pattern: +<include> -<exclude>")
|
@click.option("--pattern", multiple=True)
|
||||||
@click.option("--flags", multiple=True)
|
@click.option("--flags", multiple=True)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--severity", multiple=True, type=click.Choice(DefectItem.SEVERITY_LABELS.values())
|
"--severity", multiple=True, type=click.Choice(DefectItem.SEVERITY_LABELS.values())
|
||||||
@ -65,7 +65,7 @@ def cli(
|
|||||||
environment,
|
environment,
|
||||||
project_dir,
|
project_dir,
|
||||||
project_conf,
|
project_conf,
|
||||||
filter,
|
pattern,
|
||||||
flags,
|
flags,
|
||||||
severity,
|
severity,
|
||||||
silent,
|
silent,
|
||||||
@ -102,18 +102,14 @@ def cli(
|
|||||||
"%s: %s" % (k, ", ".join(v) if isinstance(v, list) else v)
|
"%s: %s" % (k, ", ".join(v) if isinstance(v, list) else v)
|
||||||
)
|
)
|
||||||
|
|
||||||
default_filter = [
|
default_patterns = [
|
||||||
"+<%s/>" % basename(d)
|
config.get_optional_dir("src"),
|
||||||
for d in (
|
config.get_optional_dir("include"),
|
||||||
config.get_optional_dir("src"),
|
|
||||||
config.get_optional_dir("include"),
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
tool_options = dict(
|
tool_options = dict(
|
||||||
verbose=verbose,
|
verbose=verbose,
|
||||||
silent=silent,
|
silent=silent,
|
||||||
filter=filter or env_options.get("check_filter", default_filter),
|
patterns=pattern or env_options.get("check_patterns", default_patterns),
|
||||||
flags=flags or env_options.get("check_flags"),
|
flags=flags or env_options.get("check_flags"),
|
||||||
severity=[DefectItem.SEVERITY_LABELS[DefectItem.SEVERITY_HIGH]]
|
severity=[DefectItem.SEVERITY_LABELS[DefectItem.SEVERITY_HIGH]]
|
||||||
if silent
|
if silent
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import glob
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import click
|
import click
|
||||||
@ -124,11 +125,24 @@ class CheckToolBase(object): # pylint: disable=too-many-instance-attributes
|
|||||||
def clean_up(self):
|
def clean_up(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_project_src_files(self):
|
def get_project_target_files(self):
|
||||||
file_extensions = ["h", "hpp", "c", "cc", "cpp", "ino"]
|
allowed_extensions = (".h", ".hpp", ".c", ".cc", ".cpp", ".ino")
|
||||||
return fs.match_src_files(
|
result = []
|
||||||
get_project_dir(), self.options.get("filter"), file_extensions
|
|
||||||
)
|
def _add_file(path):
|
||||||
|
if not path.endswith(allowed_extensions):
|
||||||
|
return
|
||||||
|
result.append(os.path.abspath(path))
|
||||||
|
|
||||||
|
for pattern in self.options["patterns"]:
|
||||||
|
for item in glob.glob(pattern):
|
||||||
|
if not os.path.isdir(item):
|
||||||
|
_add_file(item)
|
||||||
|
for root, _, files in os.walk(item, followlinks=True):
|
||||||
|
for f in files:
|
||||||
|
_add_file(os.path.join(root, f))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def get_source_language(self):
|
def get_source_language(self):
|
||||||
with fs.cd(get_project_dir()):
|
with fs.cd(get_project_dir()):
|
||||||
|
@ -58,7 +58,7 @@ class ClangtidyCheckTool(CheckToolBase):
|
|||||||
cmd.append("--checks=*")
|
cmd.append("--checks=*")
|
||||||
|
|
||||||
cmd.extend(flags)
|
cmd.extend(flags)
|
||||||
cmd.extend(self.get_project_src_files())
|
cmd.extend(self.get_project_target_files())
|
||||||
cmd.append("--")
|
cmd.append("--")
|
||||||
|
|
||||||
cmd.extend(["-D%s" % d for d in self.cpp_defines])
|
cmd.extend(["-D%s" % d for d in self.cpp_defines])
|
||||||
|
@ -137,7 +137,7 @@ class CppcheckCheckTool(CheckToolBase):
|
|||||||
|
|
||||||
def _generate_src_file(self):
|
def _generate_src_file(self):
|
||||||
src_files = [
|
src_files = [
|
||||||
f for f in self.get_project_src_files() if not f.endswith((".h", ".hpp"))
|
f for f in self.get_project_target_files() if not f.endswith((".h", ".hpp"))
|
||||||
]
|
]
|
||||||
return self._create_tmp_file("\n".join(src_files))
|
return self._create_tmp_file("\n".join(src_files))
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ class CppcheckCheckTool(CheckToolBase):
|
|||||||
# delete temporary dump files generated by addons
|
# delete temporary dump files generated by addons
|
||||||
if not self.is_flag_set("--addon", self.get_flags("cppcheck")):
|
if not self.is_flag_set("--addon", self.get_flags("cppcheck")):
|
||||||
return
|
return
|
||||||
for f in self.get_project_src_files():
|
for f in self.get_project_target_files():
|
||||||
dump_file = f + ".dump"
|
dump_file = f + ".dump"
|
||||||
if isfile(dump_file):
|
if isfile(dump_file):
|
||||||
remove(dump_file)
|
remove(dump_file)
|
||||||
|
@ -537,10 +537,10 @@ ProjectOptions = OrderedDict(
|
|||||||
),
|
),
|
||||||
ConfigEnvOption(
|
ConfigEnvOption(
|
||||||
group="check",
|
group="check",
|
||||||
name="check_filter",
|
name="check_patterns",
|
||||||
description=(
|
description=(
|
||||||
"Configure a list of source files which should be "
|
"Configure a list of target files or directories for checking "
|
||||||
"included/excluded from a check process"
|
"(Unix shell-style wildcards)"
|
||||||
),
|
),
|
||||||
multiple=True,
|
multiple=True,
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user