[infra] Add auto-update of targets/README.md for generate command in helper.py.

This commit is contained in:
Max Moroz 2016-11-14 19:17:38 +01:00
parent c771c31753
commit e5346f4036
2 changed files with 55 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import os
import pipes
import re
import shutil
import string
import subprocess
import sys
import tempfile
@ -271,6 +272,9 @@ def generate(generate_args):
with open(build_sh_path, 'w') as f:
f.write(templates.BUILD_TEMPLATE % args.target_name)
targets_readme_path = os.path.join('targets', 'README.md')
update_targets_readme(targets_readme_path, args.target_name, dir)
os.chmod(build_sh_path, 0o755)
return 0
@ -295,5 +299,55 @@ def shell(shell_args):
pipe.communicate()
def update_targets_readme(readme_path, target_name, fuzzers_location):
"""Add new target name and fuzzers location to the given README.md file."""
readme_lines = []
with open(readme_path) as f:
readme_lines += f.readlines()
if not readme_lines:
print('ERROR: empty %s file' % readme_path)
return
TARGETS_LIST_START_TOKEN = '| Target |'
first_target_line_number = -1
for i, line in enumerate(readme_lines):
if line.startswith(TARGETS_LIST_START_TOKEN):
first_target_line_number = i + 2
break
if first_target_line_number < 0:
print('ERROR: list of targets is not found in %s file' % readme_path)
return
def sanitize_line(line):
while line and not line[0] in string.ascii_letters + string.digits:
line = line[1:]
return line
sanitized_lines = readme_lines[first_target_line_number : ]
sanitized_lines = [sanitize_line(line) for line in sanitized_lines]
position_to_insert = -1
for i in xrange(0, len(sanitized_lines)):
if target_name > sanitized_lines[i] and target_name < sanitized_lines[i+1]:
position_to_insert = i + 1
break
if position_to_insert < 0:
print('ERROR: please update %s file manually' % readme_path)
return
position_to_insert += first_target_line_number
updated_readme_lines = readme_lines[ : position_to_insert]
updated_readme_lines.append('| %s | [%s](%s) |\n' % (target_name,
fuzzers_location,
target_name))
updated_readme_lines += readme_lines[position_to_insert : ]
with open(readme_path, 'w') as f:
f.write(''.join(updated_readme_lines))
if __name__ == '__main__':
sys.exit(main())

View File

@ -5,6 +5,7 @@ Targets integrated with oss-fuzz.
| Target | Fuzzers Location | CC e-mail | Description
| ------------ | --------------- | ----------- | ------------ |
| [boringssl](https://boringssl.googlesource.com/boringssl/) | [/targets/boringssl](boringssl) |
| [c-ares](https://c-ares.haxx.se/) | [targets/c-ares](c-ares) |
| [curl](https://curl.haxx.se/) | [/targets/curl](curl) |
| [expat](http://expat.sourceforge.net/) | [/targets/expat](expat) |
| [file (aka libmagic)](http://www.darwinsys.com/file/) | [/targets/file](file) |