Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
cb1408d4
Commit
cb1408d4
authored
Nov 12, 2012
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ccanlint: detect unused dependencies, too.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
453fdc02
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
21 deletions
+64
-21
tools/ccanlint/tests/depends_accurate.c
tools/ccanlint/tests/depends_accurate.c
+64
-21
No files found.
tools/ccanlint/tests/depends_accurate.c
View file @
cb1408d4
...
...
@@ -16,44 +16,42 @@
#include <string.h>
#include <ctype.h>
static
bool
has_dep
(
struct
manifest
*
m
,
bool
test_depend
,
const
char
*
depname
)
static
bool
has_dep
(
struct
manifest
*
m
,
char
**
deps
,
bool
*
used
,
const
char
*
depname
)
{
struct
manifest
*
i
;
unsigned
int
i
;
/* We can include ourselves, of course. */
if
(
streq
(
depname
,
m
->
basename
))
if
(
streq
(
depname
+
strlen
(
"ccan/"
)
,
m
->
basename
))
return
true
;
list_for_each
(
&
m
->
deps
,
i
,
list
)
{
if
(
streq
(
i
->
basename
,
depname
))
for
(
i
=
0
;
deps
[
i
];
i
++
)
{
if
(
streq
(
deps
[
i
],
depname
))
{
used
[
i
]
=
true
;
return
true
;
}
if
(
test_depend
)
{
list_for_each
(
&
m
->
test_deps
,
i
,
list
)
{
if
(
streq
(
i
->
basename
,
depname
))
return
true
;
}
}
return
false
;
}
static
void
check_dep_includes
(
struct
manifest
*
m
,
struct
score
*
score
,
struct
ccan_file
*
f
,
bool
test_depend
)
static
bool
check_dep_includes
(
struct
manifest
*
m
,
char
**
deps
,
bool
*
used
,
struct
score
*
score
,
struct
ccan_file
*
f
)
{
unsigned
int
i
;
char
**
lines
=
get_ccan_file_lines
(
f
);
struct
line_info
*
li
=
get_ccan_line_info
(
f
);
bool
ok
=
true
;
for
(
i
=
0
;
lines
[
i
];
i
++
)
{
char
*
mod
;
if
(
!
strreg
(
f
,
lines
[
i
],
"^[
\t
]*#[
\t
]*include[
\t
]*[<
\"
]"
"
ccan/+(
[^/]+)/"
,
&
mod
))
"
(ccan/+
[^/]+)/"
,
&
mod
))
continue
;
if
(
has_dep
(
m
,
test_depen
d
,
mod
))
if
(
has_dep
(
m
,
deps
,
use
d
,
mod
))
continue
;
/* FIXME: we can't be sure about
...
...
@@ -62,35 +60,80 @@ static void check_dep_includes(struct manifest *m, struct score *score,
if
(
!
li
[
i
].
cond
)
{
score_file_error
(
score
,
f
,
i
+
1
,
"%s not listed in _info"
,
mod
);
ok
=
false
;
}
}
return
ok
;
}
static
void
check_depends_accurate
(
struct
manifest
*
m
,
unsigned
int
*
timeleft
,
struct
score
*
score
)
{
struct
list_head
*
list
;
unsigned
int
i
,
core_deps
,
test_deps
;
char
**
deps
,
**
tdeps
;
bool
*
used
;
bool
ok
=
true
;
/* Get the *direct* dependencies. */
if
(
safe_mode
)
{
deps
=
get_safe_ccan_deps
(
m
,
m
->
dir
,
"depends"
,
false
);
tdeps
=
get_safe_ccan_deps
(
m
,
m
->
dir
,
"testdepends"
,
false
);
}
else
{
deps
=
get_deps
(
m
,
m
->
dir
,
"depends"
,
false
,
get_or_compile_info
);
tdeps
=
get_deps
(
m
,
m
->
dir
,
"testdepends"
,
false
,
get_or_compile_info
);
}
core_deps
=
talloc_array_length
(
deps
)
-
1
;
test_deps
=
talloc_array_length
(
tdeps
)
-
1
;
used
=
talloc_zero_array
(
m
,
bool
,
core_deps
+
test_deps
+
1
);
foreach_ptr
(
list
,
&
m
->
c_files
,
&
m
->
h_files
)
{
struct
ccan_file
*
f
;
list_for_each
(
list
,
f
,
list
)
check_dep_includes
(
m
,
score
,
f
,
false
);
ok
&=
check_dep_includes
(
m
,
deps
,
used
,
score
,
f
);
}
for
(
i
=
0
;
i
<
core_deps
;
i
++
)
{
if
(
!
used
[
i
])
score_file_error
(
score
,
m
->
info_file
,
0
,
"%s is an unused dependency"
,
deps
[
i
]);
}
/* Now append test dependencies to deps. */
deps
=
talloc_realloc
(
NULL
,
deps
,
char
*
,
(
core_deps
+
test_deps
+
1
)
*
sizeof
(
char
*
));
memcpy
(
&
deps
[
core_deps
],
tdeps
,
test_deps
*
sizeof
(
char
*
));
/* ccan/tap is given a free pass. */
deps
[
core_deps
+
test_deps
]
=
(
char
*
)
"ccan/tap"
;
deps
[
core_deps
+
test_deps
+
1
]
=
NULL
;
foreach_ptr
(
list
,
&
m
->
run_tests
,
&
m
->
api_tests
,
&
m
->
compile_ok_tests
,
&
m
->
compile_fail_tests
,
&
m
->
other_test_c_files
)
{
struct
ccan_file
*
f
;
list_for_each
(
list
,
f
,
list
)
check_dep_includes
(
m
,
score
,
f
,
true
);
ok
&=
check_dep_includes
(
m
,
deps
,
used
,
score
,
f
);
}
if
(
!
score
->
error
)
{
score
->
score
=
score
->
total
;
score
->
pass
=
true
;
for
(
i
=
core_deps
;
i
<
test_deps
;
i
++
)
{
if
(
!
used
[
i
])
score_file_error
(
score
,
m
->
info_file
,
0
,
"%s is an unused test dependency"
,
deps
[
i
]);
}
if
(
!
score
->
error
)
score
->
score
=
score
->
total
;
/* We don't count unused dependencies as an error (yet!) */
score
->
pass
=
ok
;
}
struct
ccanlint
depends_accurate
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment