Dont require __main__ for an addon (#3363)
This commit is contained in:
parent
d86ff326e6
commit
2a3657154b
|
@ -33,6 +33,16 @@ if (BUILD_TESTS)
|
|||
enable_testing()
|
||||
endif()
|
||||
|
||||
add_custom_target(copy_cfg ALL
|
||||
${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/cfg"
|
||||
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/cfg"
|
||||
COMMENT "Copying cfg files to ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}")
|
||||
|
||||
add_custom_target(copy_addons ALL
|
||||
${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/addons"
|
||||
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/addons"
|
||||
COMMENT "Copying addons files to ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}")
|
||||
|
||||
if(USE_BUNDLED_TINYXML2)
|
||||
message(STATUS "Using bundled version of tinyxml2")
|
||||
add_subdirectory(externals/tinyxml2)
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
import cppcheckdata, sys, os
|
||||
|
||||
__checkers__ = []
|
||||
|
||||
def checker(f):
|
||||
__checkers__.append(f)
|
||||
return f
|
||||
|
||||
|
||||
__errorid__ = ''
|
||||
__addon_name__ = ''
|
||||
def reportError(location, severity, message, errorId=None):
|
||||
cppcheckdata.reportError(location, severity, message, __addon_name__, errorId or __errorid__)
|
||||
|
||||
def runcheckers():
|
||||
# If there are no checkers then dont run
|
||||
if len(__checkers__) == 0:
|
||||
return
|
||||
global __addon_name__
|
||||
global __errorid__
|
||||
addon = sys.argv[0]
|
||||
parser = cppcheckdata.ArgumentParser()
|
||||
args = parser.parse_args()
|
||||
|
||||
__addon_name__ = os.path.splitext(os.path.basename(addon))[0]
|
||||
|
||||
for dumpfile in args.dumpfile:
|
||||
if not args.quiet:
|
||||
print('Checking %s...' % dumpfile)
|
||||
|
||||
data = cppcheckdata.CppcheckData(dumpfile)
|
||||
|
||||
for cfg in data.iterconfigurations():
|
||||
if not args.quiet:
|
||||
print('Checking %s, config %s...' % (dumpfile, cfg.name))
|
||||
for c in __checkers__:
|
||||
__errorid__ = c.__name__
|
||||
c(cfg, data)
|
|
@ -3,40 +3,31 @@
|
|||
# Locate casts in the code
|
||||
#
|
||||
|
||||
import cppcheckdata
|
||||
import cppcheck
|
||||
import sys
|
||||
|
||||
for arg in sys.argv[1:]:
|
||||
if arg.startswith('-'):
|
||||
continue
|
||||
@cppcheck.checker
|
||||
def cast(cfg, data):
|
||||
for token in cfg.tokenlist:
|
||||
if token.str != '(' or not token.astOperand1 or token.astOperand2:
|
||||
continue
|
||||
|
||||
print('Checking %s...' % arg)
|
||||
data = cppcheckdata.CppcheckData(arg)
|
||||
# Is it a lambda?
|
||||
if token.astOperand1.str == '{':
|
||||
continue
|
||||
|
||||
for cfg in data.iterconfigurations():
|
||||
print('Checking %s, config %s...' % (arg, cfg.name))
|
||||
for token in cfg.tokenlist:
|
||||
if token.str != '(' or not token.astOperand1 or token.astOperand2:
|
||||
continue
|
||||
# we probably have a cast.. if there is something inside the parentheses
|
||||
# there is a cast. Otherwise this is a function call.
|
||||
typetok = token.next
|
||||
if not typetok.isName:
|
||||
continue
|
||||
|
||||
# Is it a lambda?
|
||||
if token.astOperand1.str == '{':
|
||||
continue
|
||||
# cast number => skip output
|
||||
if token.astOperand1.isNumber:
|
||||
continue
|
||||
|
||||
# we probably have a cast.. if there is something inside the parentheses
|
||||
# there is a cast. Otherwise this is a function call.
|
||||
typetok = token.next
|
||||
if not typetok.isName:
|
||||
continue
|
||||
# void cast => often used to suppress compiler warnings
|
||||
if typetok.str == 'void':
|
||||
continue
|
||||
|
||||
# cast number => skip output
|
||||
if token.astOperand1.isNumber:
|
||||
continue
|
||||
|
||||
# void cast => often used to suppress compiler warnings
|
||||
if typetok.str == 'void':
|
||||
continue
|
||||
|
||||
cppcheckdata.reportError(token, 'information', 'found a cast', 'findcasts', 'cast')
|
||||
|
||||
sys.exit(cppcheckdata.EXIT_CODE)
|
||||
cppcheck.reportError(token, 'information', 'found a cast')
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import cppcheckdata, cppcheck, runpy, sys, os
|
||||
|
||||
if __name__ == '__main__':
|
||||
addon = sys.argv[1]
|
||||
__addon_name__ = os.path.splitext(os.path.basename(addon))[0]
|
||||
sys.argv.pop(0)
|
||||
|
||||
runpy.run_path(addon, run_name='__main__')
|
||||
|
||||
# Run registered checkers
|
||||
cppcheck.runcheckers()
|
||||
sys.exit(cppcheckdata.EXIT_CODE)
|
|
@ -34,6 +34,9 @@ if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
|
|||
target_link_libraries(cppcheck tinyxml2)
|
||||
endif()
|
||||
|
||||
add_dependencies(cppcheck copy_cfg)
|
||||
add_dependencies(cppcheck copy_addons)
|
||||
|
||||
install(TARGETS cppcheck
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
|
||||
COMPONENT applications)
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "version.h"
|
||||
|
||||
#include "exprengine.h"
|
||||
#include <string>
|
||||
|
||||
#define PICOJSON_USE_INT64
|
||||
#include <picojson.h>
|
||||
|
@ -71,6 +72,7 @@ namespace {
|
|||
std::string args;
|
||||
std::string python;
|
||||
bool ctu = false;
|
||||
std::string runScript{};
|
||||
|
||||
static std::string getFullPath(const std::string &fileName, const std::string &exename) {
|
||||
if (Path::fileExists(fileName))
|
||||
|
@ -153,6 +155,8 @@ namespace {
|
|||
pos2 = std::string::npos;
|
||||
name = scriptFile.substr(pos1, pos2 - pos1);
|
||||
|
||||
runScript = getFullPath("runaddon.py", exename);
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -291,7 +295,8 @@ static std::string executeAddon(const AddonInfo &addonInfo,
|
|||
}
|
||||
|
||||
const std::string fileArg = (endsWith(file, FILELIST, sizeof(FILELIST)-1) ? " --file-list " : " ") + cmdFileName(file);
|
||||
const std::string args = cmdFileName(addonInfo.scriptFile) + " --cli" + addonInfo.args + fileArg;
|
||||
const std::string args =
|
||||
cmdFileName(addonInfo.runScript) + " " + cmdFileName(addonInfo.scriptFile) + " --cli" + addonInfo.args + fileArg;
|
||||
|
||||
std::string result;
|
||||
if (!executeCommand(pythonExe, split(args), redirect, &result))
|
||||
|
|
|
@ -34,11 +34,8 @@ if (BUILD_TESTS)
|
|||
target_precompile_headers(testrunner PRIVATE precompiled.h)
|
||||
endif()
|
||||
|
||||
add_custom_target(copy_cfg ALL
|
||||
${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/cfg"
|
||||
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/cfg"
|
||||
COMMENT "Copying cfg files to ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}")
|
||||
add_dependencies(testrunner copy_cfg)
|
||||
add_dependencies(testrunner copy_addons)
|
||||
|
||||
if (LIBXML2_XMLLINT_EXECUTABLE)
|
||||
# TODO: get rid of the copy
|
||||
|
|
Loading…
Reference in New Issue