Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AFLplusplus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ulf Kargén
AFLplusplus
Commits
026404c4
Unverified
Commit
026404c4
authored
2 years ago
by
van Hauser
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #1608 from ahpaleus/custom-format-pip
Support for clang-format from pip in the .custom-format.py
parents
ffe89e8f
1bcc9bfa
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
.custom-format.py
+57
-24
57 additions, 24 deletions
.custom-format.py
with
57 additions
and
24 deletions
.custom-format.py
+
57
−
24
View file @
026404c4
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
# american fuzzy lop++ - custom code formatter
# american fuzzy lop++ - custom code formatter
# --------------------------------------------
# --------------------------------------------
#
#
# Written and maintaned by Andrea Fioraldi <andreafioraldi@gmail.com>
# Written and mainta
i
ned by Andrea Fioraldi <andreafioraldi@gmail.com>
#
#
# Copyright 2015, 2016, 2017 Google Inc. All rights reserved.
# Copyright 2015, 2016, 2017 Google Inc. All rights reserved.
# Copyright 2019-2022 AFLplusplus Project. All rights reserved.
# Copyright 2019-2022 AFLplusplus Project. All rights reserved.
...
@@ -18,24 +18,57 @@
...
@@ -18,24 +18,57 @@
import
subprocess
import
subprocess
import
sys
import
sys
import
os
import
os
import
re
#
import re
# TODO: for future use
import
shutil
import
shutil
import
importlib.metadata
# string_re = re.compile('(\\"(\\\\.|[^"\\\\])*\\")') # TODO: for future use
CURRENT_LLVM
=
os
.
getenv
(
'
LLVM_VERSION
'
,
14
)
CLANG_FORMAT_BIN
=
os
.
getenv
(
"
CLANG_FORMAT_BIN
"
,
""
)
def
check_clang_format_pip_version
():
"""
Check if the correct version of clang-format is installed via pip.
Returns:
bool: True if the correct version of clang-format is installed,
False otherwise.
"""
# Check if clang-format is installed
if
importlib
.
util
.
find_spec
(
'
clang_format
'
):
# Check if the installed version is the expected LLVM version
if
importlib
.
metadata
.
version
(
'
clang-format
'
)
\
.
startswith
(
CURRENT_LLVM
+
'
.
'
):
return
True
else
:
# Return False, because the clang-format version does not match
return
False
else
:
# If the 'clang_format' package isn't installed, return False
return
False
# string_re = re.compile('(\\"(\\\\.|[^"\\\\])*\\")') # future use
with
open
(
"
.clang-format
"
)
as
f
:
with
open
(
"
.clang-format
"
)
as
f
:
fmt
=
f
.
read
()
fmt
=
f
.
read
()
CURRENT_LLVM
=
os
.
getenv
(
'
LLVM_VERSION
'
,
14
)
CLANG_FORMAT_
BIN
=
os
.
getenv
(
"
CLANG_FORMAT_BIN
"
,
""
)
CLANG_FORMAT_
PIP
=
check_clang_format_pip_version
(
)
if
shutil
.
which
(
CLANG_FORMAT_BIN
)
is
None
:
if
shutil
.
which
(
CLANG_FORMAT_BIN
)
is
None
:
CLANG_FORMAT_BIN
=
f
"
clang-format-
{
CURRENT_LLVM
}
"
CLANG_FORMAT_BIN
=
f
"
clang-format-
{
CURRENT_LLVM
}
"
if
shutil
.
which
(
CLANG_FORMAT_BIN
)
is
None
:
if
shutil
.
which
(
CLANG_FORMAT_BIN
)
is
None
\
and
CLANG_FORMAT_PIP
is
False
:
print
(
f
"
[!] clang-format-
{
CURRENT_LLVM
}
is needed. Aborted.
"
)
print
(
f
"
[!] clang-format-
{
CURRENT_LLVM
}
is needed. Aborted.
"
)
print
(
f
"
Run `pip3 install
\"
clang-format==
{
CURRENT_LLVM
}
.*
\"
`
\
to install via pip.
"
)
exit
(
1
)
exit
(
1
)
if
CLANG_FORMAT_PIP
:
CLANG_FORMAT_BIN
=
shutil
.
which
(
"
clang-format
"
)
COLUMN_LIMIT
=
80
COLUMN_LIMIT
=
80
for
line
in
fmt
.
split
(
"
\n
"
):
for
line
in
fmt
.
split
(
"
\n
"
):
line
=
line
.
split
(
"
:
"
)
line
=
line
.
split
(
"
:
"
)
...
@@ -54,43 +87,43 @@ def custom_format(filename):
...
@@ -54,43 +87,43 @@ def custom_format(filename):
for
line
in
src
.
split
(
"
\n
"
):
for
line
in
src
.
split
(
"
\n
"
):
if
line
.
lstrip
().
startswith
(
"
#
"
):
if
line
.
lstrip
().
startswith
(
"
#
"
):
if
line
[
line
.
find
(
"
#
"
)
+
1
:].
lstrip
().
startswith
(
"
define
"
):
if
line
[
line
.
find
(
"
#
"
)
+
1
:].
lstrip
().
startswith
(
"
define
"
):
in_define
=
True
in_define
=
True
if
(
if
(
"
/*
"
in
line
"
/*
"
in
line
and
not
line
.
strip
().
startswith
(
"
/*
"
)
and
not
line
.
strip
().
startswith
(
"
/*
"
)
and
line
.
endswith
(
"
*/
"
)
and
line
.
endswith
(
"
*/
"
)
and
len
(
line
)
<
(
COLUMN_LIMIT
-
2
)
and
len
(
line
)
<
(
COLUMN_LIMIT
-
2
)
):
):
cmt_start
=
line
.
rfind
(
"
/*
"
)
cmt_start
=
line
.
rfind
(
"
/*
"
)
line
=
(
line
=
(
line
[:
cmt_start
]
line
[:
cmt_start
]
+
"
"
*
(
COLUMN_LIMIT
-
2
-
len
(
line
))
+
"
"
*
(
COLUMN_LIMIT
-
2
-
len
(
line
))
+
line
[
cmt_start
:]
+
line
[
cmt_start
:]
)
)
define_padding
=
0
define_padding
=
0
if
last_line
is
not
None
and
in_define
and
last_line
.
endswith
(
"
\\
"
):
if
last_line
is
not
None
and
in_define
and
last_line
.
endswith
(
"
\\
"
):
last_line
=
last_line
[:
-
1
]
last_line
=
last_line
[:
-
1
]
define_padding
=
max
(
0
,
len
(
last_line
[
last_line
.
rfind
(
"
\n
"
)
+
1
:]))
define_padding
=
max
(
0
,
len
(
last_line
[
last_line
.
rfind
(
"
\n
"
)
+
1
:]))
if
(
if
(
last_line
is
not
None
last_line
is
not
None
and
last_line
.
strip
().
endswith
(
"
{
"
)
and
last_line
.
strip
().
endswith
(
"
{
"
)
and
line
.
strip
()
!=
""
and
line
.
strip
()
!=
""
):
):
line
=
(
"
"
*
define_padding
+
"
\\
"
if
in_define
else
""
)
+
"
\n
"
+
line
line
=
(
"
"
*
define_padding
+
"
\\
"
if
in_define
else
""
)
+
"
\n
"
+
line
elif
(
elif
(
last_line
is
not
None
last_line
is
not
None
and
last_line
.
strip
().
startswith
(
"
}
"
)
and
last_line
.
strip
().
startswith
(
"
}
"
)
and
line
.
strip
()
!=
""
and
line
.
strip
()
!=
""
):
):
line
=
(
"
"
*
define_padding
+
"
\\
"
if
in_define
else
""
)
+
"
\n
"
+
line
line
=
(
"
"
*
define_padding
+
"
\\
"
if
in_define
else
""
)
+
"
\n
"
+
line
elif
(
elif
(
line
.
strip
().
startswith
(
"
}
"
)
line
.
strip
().
startswith
(
"
}
"
)
and
last_line
is
not
None
and
last_line
is
not
None
and
last_line
.
strip
()
!=
""
and
last_line
.
strip
()
!=
""
):
):
line
=
(
"
"
*
define_padding
+
"
\\
"
if
in_define
else
""
)
+
"
\n
"
+
line
line
=
(
"
"
*
define_padding
+
"
\\
"
if
in_define
else
""
)
+
"
\n
"
+
line
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment