Skip to content

Commit 29d67d3

Browse files
authored
Merge pull request diffblue#679 from diffblue/master
Update test-gen-support from master
2 parents e81a5e0 + 230c8c5 commit 29d67d3

File tree

4 files changed

+61
-33
lines changed

4 files changed

+61
-33
lines changed

scripts/cpplint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ def RepositoryName(self):
11451145
os.path.exists(os.path.join(current_dir, ".hg")) or
11461146
os.path.exists(os.path.join(current_dir, ".svn"))):
11471147
root_dir = current_dir
1148+
break;
11481149
current_dir = os.path.dirname(current_dir)
11491150

11501151
if (os.path.exists(os.path.join(root_dir, ".git")) or

scripts/filter_lint_by_diff.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
print >>sys.stderr, "Usage: filter_lint_by_diff.py diff.patch repository_root_directory < cpplint_warnings.txt"
99
sys.exit(1)
1010

11-
added_lines = set()
1211
repository_root = sys.argv[2]
1312

14-
diff = unidiff.PatchSet.from_filename(sys.argv[1])
15-
for diff_file in diff:
13+
# Create a set of all the files and the specific lines within that file that are in the diff
14+
added_lines = set()
15+
for diff_file in unidiff.PatchSet.from_filename(sys.argv[1]):
1616
filename = diff_file.target_file
1717
# Skip files deleted in the tip (b side of the diff):
1818
if filename == "/dev/null":
@@ -25,11 +25,12 @@
2525
if diff_line.line_type == "+":
2626
added_lines.add((filename, diff_line.target_line_no))
2727

28-
for l in sys.stdin:
29-
bits = l.split(":")
30-
if len(bits) < 3:
28+
# Print the lines that are in the set
29+
for line in sys.stdin:
30+
line_parts = line.split(":")
31+
if len(line_parts) < 3:
3132
continue
32-
filename = os.path.join(repository_root, bits[0])
33-
linenum = int(bits[1])
33+
filename = os.path.join(repository_root, line_parts[0])
34+
linenum = int(line_parts[1])
3435
if (filename, linenum) in added_lines:
35-
sys.stdout.write(l)
36+
sys.stdout.write(line)

scripts/run_lint.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
script_folder=`dirname $0`
6-
absolute_repository_root=`readlink -f $script_folder/..`
6+
absolute_repository_root=`git rev-parse --show-toplevel`
77

88
if [[ "$#" -gt 2 ]]
99
then
@@ -20,6 +20,13 @@ then
2020
exit 1
2121
fi
2222

23+
if ! [[ -e $script_folder/filter_lint_by_diff.py ]]
24+
then
25+
echo "Lint filter script could not be found in the $script_folder directory"
26+
echo "Ensure filter_lint_by_diff.py is inside the $script_folder directory then run again"
27+
exit 1
28+
fi
29+
2330
if [[ "$#" -gt 0 ]]
2431
then
2532
git_start=$1
@@ -62,7 +69,7 @@ for file in $diff_files; do
6269

6370
# Run the linting script and filter:
6471
# The errors from the linter go to STDERR so must be redirected to STDOUT
65-
result=`$script_folder/cpplint.py $file 2>&1 | $script_folder/filter_lint_by_diff.py $diff_file $absolute_repository_root`
72+
result=`$script_folder/cpplint.py $file 2>&1 >/dev/null | $script_folder/filter_lint_by_diff.py $diff_file $absolute_repository_root`
6673

6774
# Providing some errors were relevant we print them out
6875
if [ "$result" ]

src/util/file_util.cpp

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ Date: January 2012
2626
#include <io.h>
2727
#include <windows.h>
2828
#include <direct.h>
29+
#include <util/unicode.h>
2930
#define chdir _chdir
3031
#define popen _popen
3132
#define pclose _pclose
33+
#else
34+
#include <cstring>
3235
#endif
3336

3437
#include "file_util.h"
@@ -79,42 +82,58 @@ Function: delete_directory
7982
8083
\*******************************************************************/
8184

82-
void delete_directory(const std::string &path)
83-
{
84-
#ifdef _WIN32
85-
86-
std::string pattern=path+"\\*";
85+
#ifdef _WIN32
8786

87+
void delete_directory_utf16(const std::wstring &path)
88+
{
89+
std::wstring pattern=path + L"\\*";
8890
// NOLINTNEXTLINE(readability/identifiers)
89-
struct _finddata_t info;
90-
91-
intptr_t handle=_findfirst(pattern.c_str(), &info);
92-
93-
if(handle!=-1)
91+
struct _wfinddata_t info;
92+
intptr_t hFile=_wfindfirst(pattern.c_str(), &info);
93+
if(hFile!=-1)
9494
{
95-
unlink(info.name);
96-
97-
while(_findnext(handle, &info)!=-1)
98-
unlink(info.name);
95+
do
96+
{
97+
if(wcscmp(info.name, L".")==0 || wcscmp(info.name, L"..")==0)
98+
continue;
99+
std::wstring sub_path=path+L"\\"+info.name;
100+
if(info.attrib & _A_SUBDIR)
101+
delete_directory_utf16(sub_path);
102+
else
103+
DeleteFileW(sub_path.c_str());
104+
}
105+
while(_wfindnext(hFile, &info)==0);
106+
_findclose(hFile);
107+
RemoveDirectoryW(path.c_str());
99108
}
109+
}
100110

101-
#else
111+
#endif
102112

113+
void delete_directory(const std::string &path)
114+
{
115+
#ifdef _WIN32
116+
delete_directory_utf16(utf8_to_utf16_little_endian(path));
117+
#else
103118
DIR *dir=opendir(path.c_str());
104-
105119
if(dir!=NULL)
106120
{
107121
struct dirent *ent;
108-
109122
while((ent=readdir(dir))!=NULL)
110-
remove((path+"/"+ent->d_name).c_str());
111-
123+
{
124+
// Needed for Alpine Linux
125+
if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0)
126+
continue;
127+
std::string sub_path=path+"/"+ent->d_name;
128+
if(ent->d_type==DT_DIR)
129+
delete_directory(sub_path);
130+
else
131+
remove(sub_path.c_str());
132+
}
112133
closedir(dir);
113134
}
114-
115-
#endif
116-
117135
rmdir(path.c_str());
136+
#endif
118137
}
119138

120139
/*******************************************************************\

0 commit comments

Comments
 (0)