From e8afb14046f8151d1b3e2fa1965ae9a5c58814b3 Mon Sep 17 00:00:00 2001 From: John Beard Date: Tue, 22 Jan 2019 16:38:09 +0000 Subject: [PATCH] QA: Move PCB parse util to combined tools exec This means all the current Pcbnew utilities are all in a single executable. The tool is now run by: $ qa/pcbnew_tools/qa_pcbnew_tools pcb_parser --- qa/CMakeLists.txt | 1 - qa/pcb_parse_input/CMakeLists.txt | 90 ------------------- qa/pcbnew_tools/CMakeLists.txt | 2 + qa/pcbnew_tools/pcbnew_tools.cpp | 2 + .../tools/pcb_parser/pcb_parser_tool.cpp} | 73 ++++++++------- .../tools/pcb_parser/pcb_parser_tool.h | 32 +++++++ 6 files changed, 79 insertions(+), 121 deletions(-) delete mode 100644 qa/pcb_parse_input/CMakeLists.txt rename qa/{pcb_parse_input/main.cpp => pcbnew_tools/tools/pcb_parser/pcb_parser_tool.cpp} (70%) create mode 100644 qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.h diff --git a/qa/CMakeLists.txt b/qa/CMakeLists.txt index d132ac030b..f178e775f6 100644 --- a/qa/CMakeLists.txt +++ b/qa/CMakeLists.txt @@ -26,7 +26,6 @@ add_subdirectory( shape_poly_set_refactor ) # Utility/debugging/profiling programs add_subdirectory( common_tools ) add_subdirectory( pcbnew_tools ) -add_subdirectory( pcb_parse_input ) # add_subdirectory( pcb_test_window ) # add_subdirectory( polygon_triangulation ) diff --git a/qa/pcb_parse_input/CMakeLists.txt b/qa/pcb_parse_input/CMakeLists.txt deleted file mode 100644 index 75ce4baff3..0000000000 --- a/qa/pcb_parse_input/CMakeLists.txt +++ /dev/null @@ -1,90 +0,0 @@ -# This program source code file is part of KiCad, a free EDA CAD application. -# -# Copyright (C) 2018 KiCad Developers, see CHANGELOG.TXT for contributors. -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, you may find one here: -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# or you may search the http://www.gnu.org website for the version 2 license, -# or you may write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - - -if( BUILD_GITHUB_PLUGIN ) - set( GITHUB_PLUGIN_LIBRARIES github_plugin ) -endif() - -add_dependencies( pnsrouter pcbcommon pcad2kicadpcb ${GITHUB_PLUGIN_LIBRARIES} ) - -add_executable( qa_pcb_parse_input - # This is needed for the global mock objects - ../qa_utils/mocks.cpp - - main.cpp - - ../../common/base_units.cpp - ../../common/xnode.cpp - ../../common/base_screen.cpp -) - -include_directories( BEFORE ${INC_BEFORE} ) -include_directories( - ${CMAKE_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/include - ${CMAKE_SOURCE_DIR}/polygon - ${CMAKE_SOURCE_DIR}/pcbnew - ${CMAKE_SOURCE_DIR}/common - ${CMAKE_SOURCE_DIR}/pcbnew/router - ${CMAKE_SOURCE_DIR}/pcbnew/tools - ${CMAKE_SOURCE_DIR}/pcbnew/dialogs - ${Boost_INCLUDE_DIR} - ${INC_AFTER} -) - -target_link_libraries( qa_pcb_parse_input - pcbcommon - legacy_wx - polygon - pnsrouter - common - pcbcommon - bitmaps - polygon - pnsrouter - common - pcbcommon - bitmaps - polygon - pnsrouter - common - pcbcommon - bitmaps - polygon - pnsrouter - common - pcbcommon - 3d-viewer - bitmaps - gal - pcad2kicadpcb - common - pcbcommon - ${GITHUB_PLUGIN_LIBRARIES} - qa_utils - ${wxWidgets_LIBRARIES} -) - -# we need to pretend to be something to appease the units code -target_compile_definitions( qa_pcb_parse_input - PRIVATE PCBNEW -) \ No newline at end of file diff --git a/qa/pcbnew_tools/CMakeLists.txt b/qa/pcbnew_tools/CMakeLists.txt index 04a2c563e7..1e0e09739d 100644 --- a/qa/pcbnew_tools/CMakeLists.txt +++ b/qa/pcbnew_tools/CMakeLists.txt @@ -31,6 +31,8 @@ add_executable( qa_pcbnew_tools tools/drc_tool/drc_tool.cpp + tools/pcb_parser/pcb_parser_tool.cpp + # Older CMakes cannot link OBJECT libraries # https://cmake.org/pipermail/cmake/2013-November/056263.html $ diff --git a/qa/pcbnew_tools/pcbnew_tools.cpp b/qa/pcbnew_tools/pcbnew_tools.cpp index dbad93da76..7c4c4824a6 100644 --- a/qa/pcbnew_tools/pcbnew_tools.cpp +++ b/qa/pcbnew_tools/pcbnew_tools.cpp @@ -24,6 +24,7 @@ #include #include "tools/drc_tool/drc_tool.h" +#include "tools/pcb_parser/pcb_parser_tool.h" /** * List of registered tools. @@ -33,6 +34,7 @@ */ const static std::vector known_tools = { &drc_tool, + &pcb_parser_tool, }; diff --git a/qa/pcb_parse_input/main.cpp b/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.cpp similarity index 70% rename from qa/pcb_parse_input/main.cpp rename to qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.cpp index 9855b177d0..3e763a5073 100644 --- a/qa/pcb_parse_input/main.cpp +++ b/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2018 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -21,26 +21,35 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include "pcb_parser_tool.h" -#include -#include -#include -#include +#include +#include + +#include + +#include + +#include +#include +#include +#include #include -#include #include +#include using PARSE_DURATION = std::chrono::microseconds; + /** * Parse a PCB or footprint file from the given input stream * * @param aStream the input stream to read from * @return success, duration (in us) */ -bool parse(std::istream& aStream, bool aVerbose ) +bool parse( std::istream& aStream, bool aVerbose ) { // Take input from stdin STDISTREAM_LINE_READER reader; @@ -52,7 +61,7 @@ bool parse(std::istream& aStream, bool aVerbose ) BOARD_ITEM* board = nullptr; - PARSE_DURATION duration {}; + PARSE_DURATION duration{}; try { @@ -74,40 +83,35 @@ bool parse(std::istream& aStream, bool aVerbose ) } -static const wxCmdLineEntryDesc g_cmdLineDesc [] = -{ - { wxCMD_LINE_SWITCH, "h", "help", - _( "displays help on the command line parameters" ).mb_str(), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, - { wxCMD_LINE_SWITCH, "v", "verbose", - _( "print parsing information").mb_str() }, - { wxCMD_LINE_PARAM, nullptr, nullptr, - _( "input file" ).mb_str(), - wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE }, +static const wxCmdLineEntryDesc g_cmdLineDesc[] = { + { wxCMD_LINE_SWITCH, "h", "help", _( "displays help on the command line parameters" ).mb_str(), + wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, + { wxCMD_LINE_SWITCH, "v", "verbose", _( "print parsing information" ).mb_str() }, + { wxCMD_LINE_PARAM, nullptr, nullptr, _( "input file" ).mb_str(), wxCMD_LINE_VAL_STRING, + wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE }, { wxCMD_LINE_NONE } }; -enum RET_CODES +enum PARSER_RET_CODES { - OK = 0, - BAD_CMDLINE = 1, - PARSE_FAILED = 2, + PARSE_FAILED = RET_CODES::TOOL_SPECIFIC, }; -int main(int argc, char** argv) +int pcb_parser_main_func( int argc, char** argv ) { #ifdef __AFL_COMPILER __AFL_INIT(); #endif - wxMessageOutput::Set(new wxMessageOutputStderr); + wxMessageOutput::Set( new wxMessageOutputStderr ); wxCmdLineParser cl_parser( argc, argv ); cl_parser.SetDesc( g_cmdLineDesc ); - cl_parser.AddUsageText( _("This program parses PCB files, either from the " - "stdin stream or from the given filenames. This can be used either for " - "standalone testing of the parser or for fuzz testing." ) ); + cl_parser.AddUsageText( + _( "This program parses PCB files, either from the " + "stdin stream or from the given filenames. This can be used either for " + "standalone testing of the parser or for fuzz testing." ) ); int cmd_parsed_ok = cl_parser.Parse(); if( cmd_parsed_ok != 0 ) @@ -119,11 +123,10 @@ int main(int argc, char** argv) const bool verbose = cl_parser.Found( "verbose" ); bool ok = true; - PARSE_DURATION duration; const auto file_count = cl_parser.GetParamCount(); - if ( file_count == 0 ) + if( file_count == 0 ) { // Parse the file provided on stdin - used by AFL to drive the // program @@ -152,7 +155,17 @@ int main(int argc, char** argv) } if( !ok ) - return RET_CODES::PARSE_FAILED; + return PARSER_RET_CODES::PARSE_FAILED; return RET_CODES::OK; } + + +/* + * Define the tool interface + */ +UTILITY_PROGRAM pcb_parser_tool = { + "pcb_parser", + "Parse a KiCad PCB file", + pcb_parser_main_func, +}; \ No newline at end of file diff --git a/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.h b/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.h new file mode 100644 index 0000000000..ddab182d7e --- /dev/null +++ b/qa/pcbnew_tools/tools/pcb_parser/pcb_parser_tool.h @@ -0,0 +1,32 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 KiCad Developers, see CHANGELOG.TXT for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef PCBNEW_TOOLS_PCB_PARSER_UTILITY_H +#define PCBNEW_TOOLS_PCB_PARSER_UTILITY_H + +#include + +/// A tool to parse kicad PCBs from the command line +extern UTILITY_PROGRAM pcb_parser_tool; + +#endif //PCBNEW_TOOLS_PCB_PARSER_UTILITY_H \ No newline at end of file