Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-dev-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-dev-tools
Commits
f1d98ce3
Commit
f1d98ce3
authored
5 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
header_clean: Add support for only removing headers matching an expression
parent
7b740545
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils_maintenance/header_clean.py
+30
-11
30 additions, 11 deletions
utils_maintenance/header_clean.py
with
30 additions
and
11 deletions
utils_maintenance/header_clean.py
+
30
−
11
View file @
f1d98ce3
...
@@ -116,8 +116,8 @@ def find_build_args_make(build_dir):
...
@@ -116,8 +116,8 @@ def find_build_args_make(build_dir):
return
process_commands
(
cmake_dir
,
data
)
return
process_commands
(
cmake_dir
,
data
)
def
wash_source_const
(
pair
):
def
wash_source_const
(
arg_group
):
(
source
,
build_args
)
=
pair
(
source
,
build_args
)
=
arg_group
# Here is where the fun happens, try make changes and see what happens
# Here is where the fun happens, try make changes and see what happens
# 'char *' -> 'const char *'
# 'char *' -> 'const char *'
lines
=
open
(
source
,
'
r
'
,
encoding
=
'
utf-8
'
).
read
().
split
(
"
\n
"
)
lines
=
open
(
source
,
'
r
'
,
encoding
=
'
utf-8
'
).
read
().
split
(
"
\n
"
)
...
@@ -190,8 +190,8 @@ def wash_source_const(pair):
...
@@ -190,8 +190,8 @@ def wash_source_const(pair):
# print("building:", c)
# print("building:", c)
def
wash_source_replace
(
pair
):
def
wash_source_replace
(
arg_group
):
(
source
,
build_args
)
=
pair
(
source
,
build_args
)
=
arg_group
# Here is where the fun happens, try make changes and see what happens
# Here is where the fun happens, try make changes and see what happens
# 'char *' -> 'const char *'
# 'char *' -> 'const char *'
lines
=
open
(
source
,
'
r
'
,
encoding
=
'
utf-8
'
).
read
().
split
(
"
\n
"
)
lines
=
open
(
source
,
'
r
'
,
encoding
=
'
utf-8
'
).
read
().
split
(
"
\n
"
)
...
@@ -249,8 +249,8 @@ HEADER_BLACKLIST = {
...
@@ -249,8 +249,8 @@ HEADER_BLACKLIST = {
}
}
def
wash_source_include
(
pair
):
def
wash_source_include
(
arg_group
):
(
source
,
build_args
)
=
pair
(
source
,
build_args
,
regex_list_header
)
=
arg_group
# Here is where the fun happens, try make changes and see what happens
# Here is where the fun happens, try make changes and see what happens
# 'char *' -> 'const char *'
# 'char *' -> 'const char *'
lines
=
open
(
source
,
'
r
'
,
encoding
=
'
utf-8
'
).
read
().
split
(
"
\n
"
)
lines
=
open
(
source
,
'
r
'
,
encoding
=
'
utf-8
'
).
read
().
split
(
"
\n
"
)
...
@@ -279,6 +279,11 @@ def wash_source_include(pair):
...
@@ -279,6 +279,11 @@ def wash_source_include(pair):
i
+=
1
i
+=
1
continue
continue
if
regex_list_header
:
if
not
any
(
regex
.
match
(
l_header
)
for
regex
in
regex_list_header
):
i
+=
1
continue
l_prev
=
l
l_prev
=
l
l_new
=
""
l_new
=
""
...
@@ -329,7 +334,7 @@ def wash_source_include(pair):
...
@@ -329,7 +334,7 @@ def wash_source_include(pair):
i
+=
1
i
+=
1
def
header_clean_all
(
build_dir
,
regex_list
):
def
header_clean_all
(
build_dir
,
regex_list
,
regex_list_header
):
# currently only supports ninja or makefiles
# currently only supports ninja or makefiles
build_file_ninja
=
os
.
path
.
join
(
build_dir
,
"
build.ninja
"
)
build_file_ninja
=
os
.
path
.
join
(
build_dir
,
"
build.ninja
"
)
build_file_make
=
os
.
path
.
join
(
build_dir
,
"
Makefile
"
)
build_file_make
=
os
.
path
.
join
(
build_dir
,
"
Makefile
"
)
...
@@ -363,9 +368,8 @@ def header_clean_all(build_dir, regex_list):
...
@@ -363,9 +368,8 @@ def header_clean_all(build_dir, regex_list):
if
regex
.
match
(
c_strip
)
is
not
None
:
if
regex
.
match
(
c_strip
)
is
not
None
:
return
True
return
True
return
False
return
False
if
1
:
if
1
:
args
=
[(
c
,
build_args
)
for
(
c
,
build_args
)
in
args
if
test_path
(
c
)]
args
=
[(
c
,
build_args
,
regex_list_header
)
for
(
c
,
build_args
)
in
args
if
test_path
(
c
)]
import
multiprocessing
import
multiprocessing
job_total
=
multiprocessing
.
cpu_count
()
job_total
=
multiprocessing
.
cpu_count
()
...
@@ -375,7 +379,7 @@ def header_clean_all(build_dir, regex_list):
...
@@ -375,7 +379,7 @@ def header_clean_all(build_dir, regex_list):
# now we have commands
# now we have commands
for
i
,
(
c
,
build_args
)
in
enumerate
(
args
):
for
i
,
(
c
,
build_args
)
in
enumerate
(
args
):
if
(
source_path
in
c
)
and
(
"
rna_
"
not
in
c
):
if
(
source_path
in
c
)
and
(
"
rna_
"
not
in
c
):
wash_source_include
((
c
,
build_args
))
wash_source_include
((
c
,
build_args
,
regex_list_header
))
def
create_parser
():
def
create_parser
():
...
@@ -395,6 +399,13 @@ def create_parser():
...
@@ -395,6 +399,13 @@ def create_parser():
metavar
=
"
REGEX
"
,
metavar
=
"
REGEX
"
,
help
=
"
Match file paths against this expression
"
,
help
=
"
Match file paths against this expression
"
,
)
)
parser
.
add_argument
(
"
--match-header
"
,
nargs
=
'
+
'
,
required
=
False
,
metavar
=
"
REGEX
"
,
help
=
"
Match file paths against this expression
"
,
)
return
parser
return
parser
...
@@ -404,6 +415,7 @@ def main():
...
@@ -404,6 +415,7 @@ def main():
build_dir
=
args
.
build_dir
build_dir
=
args
.
build_dir
regex_list
=
[]
regex_list
=
[]
regex_list_header
=
[]
for
i
,
expr
in
enumerate
(
args
.
match
):
for
i
,
expr
in
enumerate
(
args
.
match
):
try
:
try
:
...
@@ -412,7 +424,14 @@ def main():
...
@@ -412,7 +424,14 @@ def main():
print
(
f
"
Error in expression:
{
expr
}
\n
{
ex
}
"
)
print
(
f
"
Error in expression:
{
expr
}
\n
{
ex
}
"
)
return
1
return
1
return
header_clean_all
(
build_dir
,
regex_list
)
for
i
,
expr
in
enumerate
(
args
.
match_header
):
try
:
regex_list_header
.
append
(
re
.
compile
(
expr
))
except
Exception
as
ex
:
print
(
f
"
Error in expression:
{
expr
}
\n
{
ex
}
"
)
return
1
return
header_clean_all
(
build_dir
,
regex_list
,
regex_list_header
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
...
...
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