Skip to content

Extend linter to check module dependencies #2196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 29, 2018

Conversation

peterschrammel
Copy link
Member

To use it just put a module_dependencies.txt into a directory,
which lists all modules that it is allowed to include header
files from.

It will emit messages such as

src/analyses/does_remove_const.cpp:19:  Module `analyses` must not use `ansi-c/c_qualifiers.h`  [build/include] [4]

If this is an acceptable solution, I'll populate the remaining module dependency definitions.

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of automatically checking policy rather than just having to tell people.

@peterschrammel
Copy link
Member Author

This contains full annotated module dependency information now.

@tautschnig
Copy link
Collaborator

  1. So how did you generate the dependency files? Is there a way of auto-generating them from Makefiles? Is that desirable or is it actually a bad idea to attempt to auto-generate them?
  2. add git shortened sha1sum to CBMC version for unique id #668 would solve the cbmc/version.h problem that we currently have.
  3. Should we first do some cleanup or merge this one and log all the cleanup to-be-done in some issue?

@peterschrammel
Copy link
Member Author

peterschrammel commented May 17, 2018

  1. I generated them from the error messages that the linter reported and annotated them manually. I don't think that the specification should be auto-adapted to the implementation.
  2. We might still want to have a place to define human readable version numbers. The cbmc directory is certainly not the right place for it.
  3. I prefer to merge this one and then do the cleanup separately.

@peterschrammel
Copy link
Member Author

Observed issues collected here: #571

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable - though I'm not sure the module_dependencies.txt is quite the right place for the commentary on the dependencies.

I also like the idea of it being driven by the Makefiles but not a blocker.

Is it worth having a warning for any folder that doesn't have a module_dependencies.txt (as people might wrongly assume that a subfolder will inherit the parents dependencies)

module_name = os.path.dirname(filename)
has_src = module_name.find('src/')
if has_src >= 0:
module_name = module_name[has_src+4:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a warning as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's worth a warning. It will only affect the module name printed in the error message.

@@ -6365,6 +6380,23 @@ def ProcessFileData(filename, file_extension, lines, error,

ResetNolintSuppressions()

# Load module dependencies
module_deps_file = os.path.join(os.path.dirname(filename), 'module_dependencies.txt')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For src/ansi-c/literals/convert_float_literal.cpp this will go looking in src/ansi-c/literalsl/module_dependencies.txt no? Which presumably isn't quite right? I guess we need to find the last src/ and then the folder immediately below that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake - I see sub folders get their own dependencies.

cpp
goto-programs
goto-instrument
java_bytecode # will go away
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between "will go away" and "should go away"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'will go away' has already a PR filed ;)

@peterschrammel
Copy link
Member Author

peterschrammel commented May 18, 2018

Is it worth having a warning for any folder that doesn't have a module_dependencies.txt (as people might wrongly assume that a subfolder will inherit the parents dependencies)

Good idea, @thk123, added this and caught two problems ;)

@peterschrammel peterschrammel force-pushed the check-module-includes branch from 0df597e to 63493cf Compare May 18, 2018 10:05
Copy link
Contributor

@chrisr-diffblue chrisr-diffblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this a lot, and I would definitely agree that these module_dependencies.txt files should not be autogenerated seeing as these are policy documents.

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some Python style tips otherwise lgtm

module_name = module_name[has_src+4:]
deps_name = os.path.dirname(include)
if deps_name and module_deps:
found = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found = any(deps_name.startswith(module) for module in module_deps)

has_comment = s.find('#')
if has_comment >= 0:
s = s[:has_comment]
s = s.lstrip().rstrip()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s = s.strip()

module_deps = f.read().splitlines()
# strip off comments and whitespace
def strip_off_comments(s):
has_comment = s.find('#')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/has_comment/comment_index/

s = s[:has_comment]
s = s.lstrip().rstrip()
return s
module_deps = [ strip_off_comments(module) for module in module_deps]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd spacing -- [ x ] or [x] not [ x]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also perhaps module_deps = map(strip_off_comments, module_deps)

return s
module_deps = [ strip_off_comments(module) for module in module_deps]
# remove empty lines
module_deps = [ module for module in module_deps if module]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend if len(module) != 0 to make clear you're expecting strings not booleans

Copy link
Contributor

@cesaro cesaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, in particular regarding the upcoming changes wrt Java threading.

@peterschrammel peterschrammel force-pushed the check-module-includes branch from 63493cf to 29cf186 Compare May 21, 2018 16:23
@peterschrammel peterschrammel force-pushed the check-module-includes branch 2 times, most recently from 41e6642 to 4fb755c Compare May 29, 2018 13:01
To use it just put a module_dependencies.txt into a directory,
which lists all modules that it is allowed to include header
files from.
@peterschrammel peterschrammel force-pushed the check-module-includes branch from 4fb755c to fada0af Compare May 29, 2018 13:05
@peterschrammel peterschrammel merged commit b51e2a8 into diffblue:develop May 29, 2018
@peterschrammel peterschrammel deleted the check-module-includes branch May 29, 2018 14:53
mgudemann pushed a commit to mgudemann/cbmc that referenced this pull request May 30, 2018
mgudemann pushed a commit to mgudemann/cbmc that referenced this pull request Jun 5, 2018
mgudemann pushed a commit to mgudemann/cbmc that referenced this pull request Jun 5, 2018
mgudemann pushed a commit to mgudemann/cbmc that referenced this pull request Jun 5, 2018
mgudemann pushed a commit to mgudemann/cbmc that referenced this pull request Jun 6, 2018
NathanJPhillips pushed a commit to NathanJPhillips/cbmc that referenced this pull request Aug 22, 2018
779fa71 Merge pull request diffblue#2253 from peterschrammel/documentation/override2
40ecff8 Merge pull request diffblue#2250 from tautschnig/expr-iterator-deque
050b344 Re-enable enforcement of override without virtual
b5dec9c Get legalistic about use of override without virtual
b51e2a8 Merge pull request diffblue#2196 from peterschrammel/check-module-includes
d5eabdf expr_iterator: use a std::deque to implement the stack
fada0af Add module dependency definition files
a90ea44 Add module dependency check to CPP-LINT
88f8cfc Remove unnecessary includes
d6986d8 Fix relative include paths
0f9c202 Merge pull request diffblue#2242 from diffblue/section-name-warning
b7f5886 Merge pull request diffblue#2241 from diffblue/ld_mode
5c11eb7 Merge pull request diffblue#2245 from mgudemann/fix/warning/clang_self_assign
f7e5fb5 Merge pull request diffblue#2229 from diffblue/ssize_t
1a504c9 Merge pull request diffblue#2244 from diffblue/solver-Makefile-fix
4bb1bf0 Fix clang++'s warning about self-assign
9a0aa9c Merge pull request diffblue#2235 from thomasspriggs/test-pl-colour
4c2cb3a remove linker mode from gcc_mode
303908f add separate path for ld
524091f factor out creation of hybrid binaries
b9127f3 linker_script_merget now takes exactly one ELF + goto binary
cd967db update year + add Michael
0d95cc5 missing const method qualifiers
6f04d98 fix ordering problem in solvers/Makefile
8f6bae0 remove a warning about section names
8befd02 Merge pull request diffblue#2238 from owen-jones-diffblue/owen-jones-diffblue/doc/irep_id
34b0ac6 Merge pull request diffblue#2236 from diffblue/show-class-hierarchy
8e8e450 Merge pull request diffblue#2232 from owen-jones-diffblue/owen-jones-diffblue/generic-bounded-types
01dc76b Add section on irep_idt and dstringt
2f4c6ad Add and unify --show-class-hierarchy command line option
56256f1 Minor typos in irept documentation
3cf4e3a Merge pull request diffblue#2178 from thomasspriggs/remove_java_bytecode_parse_treet_swap
1a7235d use __CPROVER_size_t and __CPROVER_ssize_t for __CPROVER_POINTER_OBJECT/OFFSET
a018e2f Add JSON output for class hierarchy
68c45ed Improve class hierarchy output
eeb732f Switch `push_back` to `emplace_back` when constructing `parse_trees`.
f154840 Delete copy constructor of `class java_bytecode_parse_treet`.
c5cbcec Fix instances where copying was being used instead of moving.
52a669f Remove `java_bytecode::swap` and return using `optionalt` instead.
fabbd04 Give up parsing generic method signature with bound
77f8162 Colour code tests passing vs failing.
e5e0897 Merge pull request diffblue#2126 from danpoe/refactor/sharing-map-small-nodes
f55bd96 Merge pull request diffblue#2231 from smowton/smowton/fix/jbmc-tests
af02973 Merge pull request diffblue#2202 from smowton/smowton/fix/java-lang-class-fields
42a78af JBMC tests: suffix logfiles when using symex-driven loading
af2defd Removed obsolete sharing map unit test
1d7fbd3 Refactor sharing map nodes to reduce memory consumption
5235938 Restore testing of jbmc
8a59f6f Object factory: permit null pointers within java.lang.Class
8412eb0 Merge pull request diffblue#2228 from peterschrammel/move-remaining-java-tests
369577a Move remaining java tests to jbmc/regression/
bfe3d3d Merge pull request diffblue#2226 from tautschnig/inline-get-str-cont
2b00973 Merge pull request diffblue#2227 from tautschnig/fptr-removal
3f7685f Merge pull request diffblue#2223 from diffblue/fp-builtins
3b3dc71 Distinct names of return-value symbols
4f7fade Cleanup: use symbolt::symbol_expr
8372862 function-pointer removal: Set the mode of a return symbol
272cde0 Inline get_string_container
72a0379 test __builtin_isinf, __builtin_isinf_sign, __builtin_isnormal
f156ef0 Merge pull request diffblue#2222 from tautschnig/attributes
a69c603 add __builtin_isnormal
83aeddd added __builtin_isinf_sign
87d467e fix return types of various __builtin_is* functions
61af061 added typecast_exprt::conditional_cast
e1b906a Support GCC's fallthrough attribute
d6d0a49 C front-end: support alias attributes on variables
376beab Merge pull request diffblue#2218 from diffblue/builtin_fpclassify
c3603e3 added a test for raw __builtin_fpclassify
52595bd add support for __builtin_fpclassify
50d1c79 Merge pull request diffblue#2214 from tautschnig/tg-only
3c59312 Remove unused substitute.{h,cpp}
d3e131c Revert "Set memory limit utility"
a4389fe Merge pull request diffblue#2210 from tautschnig/verbosity-cleanup
c250880 Merge pull request diffblue#2211 from tautschnig/travis-osx-cleanup
c8597a4 Merge pull request diffblue#2174 from romainbrenguier/bugfix/not_contains#TG-3150
b08ef94 Merge pull request diffblue#2216 from peterschrammel/update-codeowners
471ab0f Merge pull request diffblue#2207 from diffblue/remove-solvers-cvc
215cd69 Use enum entries instead of numeric values when comparing verbosity
6344b4f Warn if user-specified verbosity is out of range
bf04bcb Use a single implementation of eval_verbosity
b4731eb Do not redundantly set the message handler
42ec63a Clean up .gitignore
19200bf Update CODEOWNERS for /jbmc
0487376 Merge pull request diffblue#2173 from svorenova/gs_tg1121
6af2270 Update regression test that no longer throws an exception
bc17328 Enable previously failing regression tests
146bb29 Adding debug information to dereference type comparison
7b9a20a Allow pointers to be dereferenced to void types
108129c Merge pull request diffblue#2118 from diffblue/remove-jbmc
11411e4 Travis/OSX follow-up cleanup: remove unnecessary environment variables
386faa8 Test for String.contains and very large strings
9e73699 Refactor negation of not contains constraints
29a8818 Build jbmc on CI
f196e74 Update compilation instructions
1b7c84a Add JBMC README
03d6f5b Shorten goto-analyzer-taint-ansi-c tests to goto-analyzer-taint
8dc0d74 Remove obsolete jbmc-cover tests
f36da08 Move Java regression tests
b6742ca Move Java unit tests
e247458 Add JANALYZER tool
4588753 Add JDIFF tool
a20f2c1 Move java_bytecode, jbmc and miniz to jbmc/src
987106f Make unit test independent of java_bytecode
d945452 Adapt cpplint header guard check
28907b2 remove (pre-SMT-LIB) CVC interface

git-subtree-dir: cbmc
git-subtree-split: 779fa71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.