2019-02-27 14:14:19 +01:00
|
|
|
import os
|
|
|
|
|
2019-02-28 11:09:10 +01:00
|
|
|
# We don't want to run metrics for unittests, automatically-generated C files,
|
|
|
|
# external libraries or git leftovers.
|
2019-07-17 14:30:12 +02:00
|
|
|
EXCLUDE_SOURCE_DIRS = {"src/test/", "src/trunnel/", "src/rust/",
|
|
|
|
"src/ext/", ".git/"}
|
|
|
|
|
2019-08-05 16:31:02 +02:00
|
|
|
EXCLUDE_FILES = {"orconfig.h"}
|
|
|
|
|
2019-07-17 14:30:12 +02:00
|
|
|
def _norm(p):
|
|
|
|
return os.path.normcase(os.path.normpath(p))
|
2019-02-28 11:09:10 +01:00
|
|
|
|
|
|
|
def get_tor_c_files(tor_topdir):
|
2019-02-27 14:14:19 +01:00
|
|
|
"""
|
2019-08-05 16:31:02 +02:00
|
|
|
Return a list with the .c and .h filenames we want to get metrics of.
|
2019-02-27 14:14:19 +01:00
|
|
|
"""
|
|
|
|
files_list = []
|
2019-07-17 14:30:12 +02:00
|
|
|
exclude_dirs = { _norm(os.path.join(tor_topdir, p)) for p in EXCLUDE_SOURCE_DIRS }
|
|
|
|
|
2019-02-27 14:14:19 +01:00
|
|
|
|
|
|
|
for root, directories, filenames in os.walk(tor_topdir):
|
2019-07-17 14:30:12 +02:00
|
|
|
# Remove all the directories that are excluded.
|
|
|
|
directories[:] = [ d for d in directories
|
|
|
|
if _norm(os.path.join(root,d)) not in exclude_dirs ]
|
2019-03-25 14:08:04 +01:00
|
|
|
directories.sort()
|
|
|
|
filenames.sort()
|
2019-02-27 14:14:19 +01:00
|
|
|
for filename in filenames:
|
2019-08-05 16:31:02 +02:00
|
|
|
# We only care about .c and .h files
|
|
|
|
if not (filename.endswith(".c") or filename.endswith(".h")):
|
|
|
|
continue
|
|
|
|
if filename in EXCLUDE_FILES:
|
2019-02-27 14:14:19 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
full_path = os.path.join(root,filename)
|
|
|
|
|
|
|
|
files_list.append(full_path)
|
|
|
|
|
|
|
|
return files_list
|