Update tools help using a script.
Update docbook/wsug_src/*.txt using tools/update-tools-help.py. This removes a lot of unwanted behavior that came with updating via a CMake target. Change-Id: I0a24f425e9673ef7bd074210d7047654c6755e79 Reviewed-on: https://code.wireshark.org/review/29416 Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
parent
a1ae40f1a3
commit
c15ada34b1
|
@ -270,6 +270,13 @@ endif()
|
|||
# This option only has an effect on CMake >= 2.8.9
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
# Path to our generated executables (or wrapper scripts)
|
||||
if(WIN32)
|
||||
set(WS_PROGRAM_PATH ./run/$<CONFIG>)
|
||||
else()
|
||||
set(WS_PROGRAM_PATH ./run)
|
||||
endif()
|
||||
|
||||
if( CMAKE_C_COMPILER_ID MATCHES "MSVC")
|
||||
if ((MSVC_VERSION LESS "1900") OR (MSVC_VERSION GREATER_EQUAL "2000"))
|
||||
message(FATAL_ERROR "You are using an unsupported version of MSVC")
|
||||
|
@ -3018,11 +3025,6 @@ set(_test_group_list
|
|||
suite_unittests
|
||||
suite_wslua
|
||||
)
|
||||
if(WIN32)
|
||||
set(_test_group_program_path ./run/$<CONFIG>)
|
||||
else()
|
||||
set(_test_group_program_path ./run)
|
||||
endif()
|
||||
|
||||
# We don't currently handle spaces in arguments. On Windows this
|
||||
# means that you will probably have to pass in an interface index
|
||||
|
@ -3036,7 +3038,7 @@ foreach(_group_name ${_test_group_list})
|
|||
COMMAND ${CMAKE_COMMAND} -E env PYTHONIOENCODING=UTF-8
|
||||
${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/test/test.py
|
||||
--verbose
|
||||
--program-path ${_test_group_program_path}
|
||||
--program-path ${WS_PROGRAM_PATH}
|
||||
${TEST_EXTRA_ARGS}
|
||||
${_group_name}
|
||||
)
|
||||
|
|
|
@ -61,80 +61,15 @@ set(COMMON_GRAPHICS
|
|||
common_graphics/warning.svg
|
||||
)
|
||||
|
||||
set(WSUG_TOOLS_HELP_COMMANDS
|
||||
capinfos
|
||||
editcap
|
||||
mergecap
|
||||
reordercap
|
||||
text2pcap
|
||||
tshark
|
||||
)
|
||||
|
||||
if (PCAP_FOUND)
|
||||
list(APPEND WSUG_TOOLS_HELP_COMMANDS
|
||||
dumpcap
|
||||
rawshark
|
||||
)
|
||||
endif(PCAP_FOUND)
|
||||
|
||||
# We want the wsug_* targets to depend on our tools help files. However,
|
||||
# each WSUG_TOOLS_HELP_COMMANDS target depends on its corresponding
|
||||
# binary. Due to this and the following issues update_tools_help should
|
||||
# be as independent as possible:
|
||||
# - Aside from the first line (which contains the git commit ID) each
|
||||
# command's `-h` output might change every few months or years.
|
||||
# - It changes files in the source directory, which usually gives you
|
||||
# git changes that you probably don't want or at least don't care about.
|
||||
# - Having our documentation depend on our executables increases the
|
||||
# likelihood of unwanted rebuilds, particularly on the Buildbot.
|
||||
set(WSUG_TOOLS_HELP_FILES)
|
||||
set(GUIDE_INSTALL_DIRS)
|
||||
|
||||
# General help output
|
||||
|
||||
foreach(th_command ${WSUG_TOOLS_HELP_COMMANDS})
|
||||
if(NOT DEFINED BUILD_${th_command})
|
||||
# Catch typos, these commands must exist in CMakeOptions.txt
|
||||
message(WARNING "BUILD_${th_command} is an unknown option")
|
||||
endif()
|
||||
if(NOT BUILD_${th_command})
|
||||
message(STATUS "WSUG: will not update ${th_command} output")
|
||||
continue()
|
||||
endif()
|
||||
|
||||
set(th_file ${CMAKE_CURRENT_SOURCE_DIR}/wsug_src/${th_command}-h.txt)
|
||||
list(APPEND WSUG_TOOLS_HELP_FILES ${th_file})
|
||||
add_custom_command(
|
||||
OUTPUT ${th_file}
|
||||
COMMAND ${th_command} -h > ${th_file}
|
||||
DEPENDS ${th_command}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
# Extra command output
|
||||
# Note that these won't work on Windows unless we make -F and -T write
|
||||
# to stdout and return 0 or wrap the commands similar to hhc.exe.
|
||||
if(BUILD_editcap)
|
||||
set(th_file ${CMAKE_CURRENT_SOURCE_DIR}/wsug_src/editcap-F.txt)
|
||||
list(APPEND WSUG_TOOLS_HELP_FILES ${th_file})
|
||||
add_custom_command(
|
||||
OUTPUT ${th_file}
|
||||
COMMAND editcap -F > ${th_file}
|
||||
DEPENDS editcap
|
||||
)
|
||||
set(th_file ${CMAKE_CURRENT_SOURCE_DIR}/wsug_src/editcap-T.txt)
|
||||
list(APPEND WSUG_TOOLS_HELP_FILES ${th_file})
|
||||
add_custom_command(
|
||||
OUTPUT ${th_file}
|
||||
COMMAND editcap -T > ${th_file}
|
||||
DEPENDS editcap
|
||||
)
|
||||
else()
|
||||
message(STATUS "WSUG: will not update editcap output")
|
||||
endif()
|
||||
|
||||
# This is automatically updated each week. You probably don't need to run it
|
||||
# or depend on it.
|
||||
add_custom_target(update_tools_help
|
||||
DEPENDS ${WSUG_TOOLS_HELP_FILES}
|
||||
COMMAND ${CMAKE_COMMAND} -E env PYTHONIOENCODING=UTF-8
|
||||
${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/update-tools-help.py
|
||||
--program-path ${WS_PROGRAM_PATH}
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
)
|
||||
set_docbook_target_properties(update_tools_help)
|
||||
|
||||
|
@ -157,6 +92,16 @@ set(WSUG_FILES
|
|||
wsug_src/WSUG_chapter_use.asciidoc
|
||||
wsug_src/WSUG_chapter_work.asciidoc
|
||||
wsug_src/WSUG_preface.asciidoc
|
||||
wsug_src/capinfos-h.txt
|
||||
wsug_src/dumpcap-h.txt
|
||||
wsug_src/editcap-F.txt
|
||||
wsug_src/editcap-T.txt
|
||||
wsug_src/editcap-h.txt
|
||||
wsug_src/mergecap-h.txt
|
||||
wsug_src/rawshark-h.txt
|
||||
wsug_src/reordercap-h.txt
|
||||
wsug_src/text2pcap-h.txt
|
||||
wsug_src/tshark-h.txt
|
||||
${COMMON_FILES}
|
||||
)
|
||||
|
||||
|
@ -354,7 +299,7 @@ if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
|
|||
)
|
||||
endif()
|
||||
|
||||
set( WSUG_BUILT_DEPS ws.css update_tools_help)
|
||||
set( WSUG_BUILT_DEPS ws.css)
|
||||
|
||||
set(WSDG_SOURCE
|
||||
${WSDG_FILES}
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# update-tools-help.py - Update the command line help output in docbook/wsug_src.
|
||||
#
|
||||
# Wireshark - Network traffic analyzer
|
||||
# By Gerald Combs <gerald@wireshark.org>
|
||||
# Copyright 1998 Gerald Combs
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
'''Update tools help
|
||||
|
||||
For each file that matches docbook/wsug_src/<command>-<flag>.txt, run
|
||||
that command and flag. Update the file if the output differs.
|
||||
'''
|
||||
|
||||
import argparse
|
||||
import difflib
|
||||
import glob
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Update Wireshark tools help')
|
||||
parser.add_argument('-p', '--program-path', nargs=1, default=os.path.curdir, help='Path to Wireshark executables.')
|
||||
args = parser.parse_args()
|
||||
|
||||
this_dir = os.path.dirname(__file__)
|
||||
wsug_src_dir = os.path.join(this_dir, '..', 'docbook', 'wsug_src')
|
||||
|
||||
tools_help_files = glob.glob(os.path.join(wsug_src_dir, '*-*.txt'))
|
||||
tools_help_files.sort()
|
||||
tool_pat = re.compile('(\w+)(-\w).txt')
|
||||
|
||||
# If tshark is present, assume that our other executables are as well.
|
||||
program_path = args.program_path[0]
|
||||
if not os.path.isfile(os.path.join(program_path, 'tshark')):
|
||||
print('tshark not found at {}\n'.format(program_path))
|
||||
parser.print_usage()
|
||||
sys.exit(1)
|
||||
|
||||
null_fd = open(os.devnull, 'w')
|
||||
|
||||
for thf in tools_help_files:
|
||||
thf_base = os.path.basename(thf)
|
||||
m = tool_pat.match(thf_base)
|
||||
thf_command = os.path.join(program_path, m.group(1))
|
||||
thf_flag = m.group(2)
|
||||
|
||||
if not os.path.isfile(thf_command):
|
||||
print('{} not found. Skipping.'.format(thf_command))
|
||||
continue
|
||||
|
||||
with io.open(thf, 'r', encoding='UTF-8') as fd:
|
||||
cur_help = fd.read()
|
||||
|
||||
try:
|
||||
new_help_data = subprocess.check_output((thf_command, thf_flag), stderr=null_fd)
|
||||
except subprocess.CalledProcessError as e:
|
||||
if thf_flag == '-h':
|
||||
raise e
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
new_help = new_help_data.decode('UTF-8', 'replace')
|
||||
else:
|
||||
new_help = unicode(new_help_data, 'UTF-8', 'replace')
|
||||
|
||||
cur_lines = cur_help.splitlines()
|
||||
new_lines = new_help.splitlines()
|
||||
if ' (v' in cur_lines[0]:
|
||||
# Assume we have a version. Strip it.
|
||||
cur_lines[0] = ' '.join(cur_lines[0].split()[:-1])
|
||||
new_lines[0] = ' '.join(new_lines[0].split()[:-1])
|
||||
diff = list(difflib.unified_diff(cur_lines, new_lines))
|
||||
|
||||
if (len(diff) > 0):
|
||||
print('Updating {} {}'.format(thf_command, thf_flag))
|
||||
with io.open(thf, 'w', encoding='UTF-8') as fd:
|
||||
fd.write(new_help)
|
||||
else:
|
||||
print('{} {} output unchanged.'.format(thf_command, thf_flag))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue