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 <same arguments as before>
This commit is contained in:
John Beard 2019-01-22 16:38:09 +00:00 committed by Wayne Stambaugh
parent d7563c55c4
commit e8afb14046
6 changed files with 79 additions and 121 deletions

View File

@ -26,7 +26,6 @@ add_subdirectory( shape_poly_set_refactor )
# Utility/debugging/profiling programs # Utility/debugging/profiling programs
add_subdirectory( common_tools ) add_subdirectory( common_tools )
add_subdirectory( pcbnew_tools ) add_subdirectory( pcbnew_tools )
add_subdirectory( pcb_parse_input )
# add_subdirectory( pcb_test_window ) # add_subdirectory( pcb_test_window )
# add_subdirectory( polygon_triangulation ) # add_subdirectory( polygon_triangulation )

View File

@ -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
)

View File

@ -31,6 +31,8 @@ add_executable( qa_pcbnew_tools
tools/drc_tool/drc_tool.cpp tools/drc_tool/drc_tool.cpp
tools/pcb_parser/pcb_parser_tool.cpp
# Older CMakes cannot link OBJECT libraries # Older CMakes cannot link OBJECT libraries
# https://cmake.org/pipermail/cmake/2013-November/056263.html # https://cmake.org/pipermail/cmake/2013-November/056263.html
$<TARGET_OBJECTS:pcbnew_kiface_objects> $<TARGET_OBJECTS:pcbnew_kiface_objects>

View File

@ -24,6 +24,7 @@
#include <utility_program.h> #include <utility_program.h>
#include "tools/drc_tool/drc_tool.h" #include "tools/drc_tool/drc_tool.h"
#include "tools/pcb_parser/pcb_parser_tool.h"
/** /**
* List of registered tools. * List of registered tools.
@ -33,6 +34,7 @@
*/ */
const static std::vector<UTILITY_PROGRAM*> known_tools = { const static std::vector<UTILITY_PROGRAM*> known_tools = {
&drc_tool, &drc_tool,
&pcb_parser_tool,
}; };

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * 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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include "pcb_parser_tool.h"
#include <kicad_plugin.h> #include <cstdio>
#include <pcb_parser.h> #include <string>
#include <richio.h>
#include <class_board_item.h> #include <common.h>
#include <wx/cmdline.h>
#include <class_board_item.h>
#include <kicad_plugin.h>
#include <pcb_parser.h>
#include <richio.h>
#include <wx/cmdline.h> #include <wx/cmdline.h>
#include <stdstream_line_reader.h>
#include <scoped_timer.h> #include <scoped_timer.h>
#include <stdstream_line_reader.h>
using PARSE_DURATION = std::chrono::microseconds; using PARSE_DURATION = std::chrono::microseconds;
/** /**
* Parse a PCB or footprint file from the given input stream * Parse a PCB or footprint file from the given input stream
* *
* @param aStream the input stream to read from * @param aStream the input stream to read from
* @return success, duration (in us) * @return success, duration (in us)
*/ */
bool parse(std::istream& aStream, bool aVerbose ) bool parse( std::istream& aStream, bool aVerbose )
{ {
// Take input from stdin // Take input from stdin
STDISTREAM_LINE_READER reader; STDISTREAM_LINE_READER reader;
@ -52,7 +61,7 @@ bool parse(std::istream& aStream, bool aVerbose )
BOARD_ITEM* board = nullptr; BOARD_ITEM* board = nullptr;
PARSE_DURATION duration {}; PARSE_DURATION duration{};
try try
{ {
@ -74,38 +83,33 @@ bool parse(std::istream& aStream, bool aVerbose )
} }
static const wxCmdLineEntryDesc g_cmdLineDesc [] = static const wxCmdLineEntryDesc g_cmdLineDesc[] = {
{ { wxCMD_LINE_SWITCH, "h", "help", _( "displays help on the command line parameters" ).mb_str(),
{ wxCMD_LINE_SWITCH, "h", "help",
_( "displays help on the command line parameters" ).mb_str(),
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
{ wxCMD_LINE_SWITCH, "v", "verbose", { wxCMD_LINE_SWITCH, "v", "verbose", _( "print parsing information" ).mb_str() },
_( "print parsing information").mb_str() }, { wxCMD_LINE_PARAM, nullptr, nullptr, _( "input file" ).mb_str(), wxCMD_LINE_VAL_STRING,
{ wxCMD_LINE_PARAM, nullptr, nullptr, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
_( "input file" ).mb_str(),
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
{ wxCMD_LINE_NONE } { wxCMD_LINE_NONE }
}; };
enum RET_CODES enum PARSER_RET_CODES
{ {
OK = 0, PARSE_FAILED = RET_CODES::TOOL_SPECIFIC,
BAD_CMDLINE = 1,
PARSE_FAILED = 2,
}; };
int main(int argc, char** argv) int pcb_parser_main_func( int argc, char** argv )
{ {
#ifdef __AFL_COMPILER #ifdef __AFL_COMPILER
__AFL_INIT(); __AFL_INIT();
#endif #endif
wxMessageOutput::Set(new wxMessageOutputStderr); wxMessageOutput::Set( new wxMessageOutputStderr );
wxCmdLineParser cl_parser( argc, argv ); wxCmdLineParser cl_parser( argc, argv );
cl_parser.SetDesc( g_cmdLineDesc ); cl_parser.SetDesc( g_cmdLineDesc );
cl_parser.AddUsageText( _("This program parses PCB files, either from the " cl_parser.AddUsageText(
_( "This program parses PCB files, either from the "
"stdin stream or from the given filenames. This can be used either for " "stdin stream or from the given filenames. This can be used either for "
"standalone testing of the parser or for fuzz testing." ) ); "standalone testing of the parser or for fuzz testing." ) );
@ -119,11 +123,10 @@ int main(int argc, char** argv)
const bool verbose = cl_parser.Found( "verbose" ); const bool verbose = cl_parser.Found( "verbose" );
bool ok = true; bool ok = true;
PARSE_DURATION duration;
const auto file_count = cl_parser.GetParamCount(); 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 // Parse the file provided on stdin - used by AFL to drive the
// program // program
@ -152,7 +155,17 @@ int main(int argc, char** argv)
} }
if( !ok ) if( !ok )
return RET_CODES::PARSE_FAILED; return PARSER_RET_CODES::PARSE_FAILED;
return RET_CODES::OK; return RET_CODES::OK;
} }
/*
* Define the tool interface
*/
UTILITY_PROGRAM pcb_parser_tool = {
"pcb_parser",
"Parse a KiCad PCB file",
pcb_parser_main_func,
};

View File

@ -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 <utility_program.h>
/// A tool to parse kicad PCBs from the command line
extern UTILITY_PROGRAM pcb_parser_tool;
#endif //PCBNEW_TOOLS_PCB_PARSER_UTILITY_H