| 1 | coccinelle_opt = get_option('coccinelle').require( |
| 2 | fs.exists(meson.project_source_root() / '.git'), |
| 3 | error_message: 'coccinelle can only be run from a git checkout', |
| 4 | ) |
| 5 | |
| 6 | spatch = find_program('spatch', required: coccinelle_opt) |
| 7 | if not spatch.found() |
| 8 | subdir_done() |
| 9 | endif |
| 10 | |
| 11 | rules = [ |
| 12 | 'array.cocci', |
| 13 | 'commit.cocci', |
| 14 | 'config_fn_ctx.pending.cocci', |
| 15 | 'equals-null.cocci', |
| 16 | 'flex_alloc.cocci', |
| 17 | 'free.cocci', |
| 18 | 'git_config_number.cocci', |
| 19 | 'hashmap.cocci', |
| 20 | 'index-compatibility.cocci', |
| 21 | 'object_id.cocci', |
| 22 | 'preincr.cocci', |
| 23 | 'qsort.cocci', |
| 24 | 'refs.cocci', |
| 25 | 'strbuf.cocci', |
| 26 | 'swap.cocci', |
| 27 | 'the_repository.cocci', |
| 28 | 'xcalloc.cocci', |
| 29 | 'xopen.cocci', |
| 30 | 'xstrdup_or_null.cocci', |
| 31 | 'xstrncmpz.cocci', |
| 32 | ] |
| 33 | |
| 34 | concatenated_rules = custom_target( |
| 35 | command: [ |
| 36 | 'cat', '@INPUT@', |
| 37 | ], |
| 38 | input: rules, |
| 39 | output: 'rules.cocci', |
| 40 | capture: true, |
| 41 | ) |
| 42 | |
| 43 | coccinelle_sources = [] |
| 44 | foreach source : run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.c', third_party_excludes, check: true).stdout().split() |
| 45 | coccinelle_sources += source |
| 46 | endforeach |
| 47 | |
| 48 | coccinelle_headers = [] |
| 49 | foreach header : headers_to_check |
| 50 | coccinelle_headers += meson.project_source_root() / header |
| 51 | endforeach |
| 52 | |
| 53 | coccinelle_includes = [] |
| 54 | foreach path : ['compat', 'ewah', 'refs', 'sha256', 'trace2', 'win32', 'xdiff'] |
| 55 | coccinelle_includes += ['-I', meson.project_source_root() / path] |
| 56 | endforeach |
| 57 | |
| 58 | patches = [ ] |
| 59 | foreach source : coccinelle_sources |
| 60 | patches += custom_target( |
| 61 | command: [ |
| 62 | spatch, |
| 63 | '--all-includes', |
| 64 | '--sp-file', concatenated_rules, |
| 65 | '--patch', meson.project_source_root(), |
| 66 | coccinelle_includes, |
| 67 | '@INPUT@', |
| 68 | ], |
| 69 | input: meson.project_source_root() / source, |
| 70 | output: source.underscorify() + '.patch', |
| 71 | capture: true, |
| 72 | depend_files: coccinelle_headers, |
| 73 | ) |
| 74 | endforeach |
| 75 | |
| 76 | concatenated_patch = custom_target( |
| 77 | command: [ |
| 78 | 'cat', '@INPUT@', |
| 79 | ], |
| 80 | input: patches, |
| 81 | output: 'cocci.patch', |
| 82 | capture: true, |
| 83 | ) |
| 84 | |
| 85 | alias_target('coccicheck', concatenated_patch) |