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