fixed #11925 (build slowest files first) (#5419)

This will mainly help if you only build the `cppcheck` targets and the
more threads you utilize for compilation.
This commit is contained in:
Oliver Stöneberg 2023-09-11 20:22:07 +02:00 committed by GitHub
parent 1b5b74d1f3
commit b31860b72d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 28 deletions

View File

@ -189,7 +189,10 @@ MAN_SOURCE=man/cppcheck.1.xml
###### Object Files
LIBOBJ = $(libcppdir)/analyzerinfo.o \
LIBOBJ = $(libcppdir)/valueflow.o \
$(libcppdir)/tokenize.o \
$(libcppdir)/symboldatabase.o \
$(libcppdir)/analyzerinfo.o \
$(libcppdir)/astutils.o \
$(libcppdir)/check.o \
$(libcppdir)/check64bit.o \
@ -241,14 +244,11 @@ LIBOBJ = $(libcppdir)/analyzerinfo.o \
$(libcppdir)/settings.o \
$(libcppdir)/summaries.o \
$(libcppdir)/suppressions.o \
$(libcppdir)/symboldatabase.o \
$(libcppdir)/templatesimplifier.o \
$(libcppdir)/timer.o \
$(libcppdir)/token.o \
$(libcppdir)/tokenize.o \
$(libcppdir)/tokenlist.o \
$(libcppdir)/utils.o \
$(libcppdir)/valueflow.o \
$(libcppdir)/vfvalue.o
EXTOBJ = externals/simplecpp/simplecpp.o \
@ -342,12 +342,12 @@ TESTOBJ = test/fixture.o \
###### Targets
cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)
cppcheck: $(EXTOBJ) $(LIBOBJ) $(CLIOBJ)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
all: cppcheck testrunner
testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/executor.o cli/processexecutor.o cli/singleexecutor.o cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/cppcheckexecutorseh.o cli/cppcheckexecutorsig.o cli/stacktrace.o cli/filelister.o
testrunner: $(EXTOBJ) $(TESTOBJ) $(LIBOBJ) cli/executor.o cli/processexecutor.o cli/singleexecutor.o cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/cppcheckexecutorseh.o cli/cppcheckexecutorsig.o cli/stacktrace.o cli/filelister.o
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
test: all
@ -456,6 +456,15 @@ validateRules:
###### Build
$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/forwardanalyzer.h lib/importproject.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp
$(libcppdir)/tokenize.o: lib/tokenize.cpp externals/simplecpp/simplecpp.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/summaries.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/tokenize.cpp
$(libcppdir)/symboldatabase.o: lib/symboldatabase.cpp lib/astutils.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/keywords.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/symboldatabase.cpp
$(libcppdir)/analyzerinfo.o: lib/analyzerinfo.cpp externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/path.h lib/platform.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/analyzerinfo.cpp
@ -612,9 +621,6 @@ $(libcppdir)/summaries.o: lib/summaries.cpp lib/analyzerinfo.h lib/config.h lib/
$(libcppdir)/suppressions.o: lib/suppressions.cpp externals/tinyxml2/tinyxml2.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/mathlib.h lib/path.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/suppressions.cpp
$(libcppdir)/symboldatabase.o: lib/symboldatabase.cpp lib/astutils.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/keywords.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/symboldatabase.cpp
$(libcppdir)/templatesimplifier.o: lib/templatesimplifier.cpp lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/templatesimplifier.cpp
@ -624,18 +630,12 @@ $(libcppdir)/timer.o: lib/timer.cpp lib/config.h lib/timer.h lib/utils.h
$(libcppdir)/token.o: lib/token.cpp lib/astutils.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/tokenrange.h lib/utils.h lib/valueflow.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/token.cpp
$(libcppdir)/tokenize.o: lib/tokenize.cpp externals/simplecpp/simplecpp.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/summaries.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/tokenize.cpp
$(libcppdir)/tokenlist.o: lib/tokenlist.cpp externals/simplecpp/simplecpp.h lib/astutils.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/keywords.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/tokenlist.cpp
$(libcppdir)/utils.o: lib/utils.cpp lib/config.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/utils.cpp
$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/forwardanalyzer.h lib/importproject.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp
$(libcppdir)/vfvalue.o: lib/vfvalue.cpp lib/config.h lib/errortypes.h lib/mathlib.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vfvalue.cpp

View File

@ -1,6 +1,11 @@
file(GLOB_RECURSE hdrs "*.h")
file(GLOB_RECURSE srcs "*.cpp")
# move the slowest files to the top
set(srcs_slow "${CMAKE_CURRENT_SOURCE_DIR}/valueflow.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/tokenize.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/symboldatabase.cpp")
list(REMOVE_ITEM srcs ${srcs_slow})
list(INSERT srcs 0 ${srcs_slow})
function(build_src output filename)
get_filename_component(file ${filename} NAME)
set(outfile ${CMAKE_CURRENT_BINARY_DIR}/build/mc_${file})

View File

@ -20,6 +20,9 @@
<ItemGroup Label="SourceFiles">
<ClCompile Include="..\externals\simplecpp\simplecpp.cpp" />
<ClCompile Include="..\externals\tinyxml2\tinyxml2.cpp" />
<ClCompile Include="valueflow.cpp" />
<ClCompile Include="tokenize.cpp" />
<ClCompile Include="symboldatabase.cpp" />
<ClCompile Include="analyzerinfo.cpp" />
<ClCompile Include="astutils.cpp" />
<ClCompile Include="check.cpp">
@ -77,14 +80,11 @@
<ClCompile Include="settings.cpp" />
<ClCompile Include="summaries.cpp" />
<ClCompile Include="suppressions.cpp" />
<ClCompile Include="symboldatabase.cpp" />
<ClCompile Include="templatesimplifier.cpp" />
<ClCompile Include="timer.cpp" />
<ClCompile Include="token.cpp" />
<ClCompile Include="tokenize.cpp" />
<ClCompile Include="tokenlist.cpp" />
<ClCompile Include="utils.cpp" />
<ClCompile Include="valueflow.cpp" />
<ClCompile Include="vfvalue.cpp" />
</ItemGroup>
<ItemGroup Label="HeaderFiles">

View File

@ -75,7 +75,10 @@ HEADERS += $${PWD}/analyzer.h \
$${PWD}/version.h \
$${PWD}/vfvalue.h
SOURCES += $${PWD}/analyzerinfo.cpp \
SOURCES += $${PWD}/valueflow.cpp \
$${PWD}/tokenize.cpp \
$${PWD}/symboldatabase.cpp \
$${PWD}/analyzerinfo.cpp \
$${PWD}/astutils.cpp \
$${PWD}/check.cpp \
$${PWD}/check64bit.cpp \
@ -127,12 +130,9 @@ SOURCES += $${PWD}/analyzerinfo.cpp \
$${PWD}/settings.cpp \
$${PWD}/summaries.cpp \
$${PWD}/suppressions.cpp \
$${PWD}/symboldatabase.cpp \
$${PWD}/templatesimplifier.cpp \
$${PWD}/timer.cpp \
$${PWD}/token.cpp \
$${PWD}/tokenize.cpp \
$${PWD}/tokenlist.cpp \
$${PWD}/utils.cpp \
$${PWD}/valueflow.cpp \
$${PWD}/vfvalue.cpp

View File

@ -251,6 +251,25 @@ static std::string make_vcxproj_cl_entry(const std::string& file, ClType type)
return outstr;
}
static std::vector<std::string> prioritizelib(const std::vector<std::string>& libfiles)
{
std::map<std::string, std::size_t> priorities;
std::size_t prio = libfiles.size();
for (const auto &l : libfiles) {
priorities.emplace(l, prio--);
}
priorities["lib/valueflow.cpp"] = 1000;
priorities["lib/tokenize.cpp"] = 900;
priorities["lib/symboldatabase.cpp"] = 800;
std::vector<std::string> libfiles_prio = libfiles;
std::sort(libfiles_prio.begin(), libfiles_prio.end(), [&](const std::string &l1, const std::string &l2) {
const auto p1 = priorities.find(l1);
const auto p2 = priorities.find(l2);
return (p1 != priorities.end() ? p1->second : 0) > (p2 != priorities.end() ? p2->second : 0);
});
return libfiles_prio;
}
int main(int argc, char **argv)
{
const bool release(argc >= 2 && std::string(argv[1]) == "--release");
@ -262,6 +281,7 @@ int main(int argc, char **argv)
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
const std::vector<std::string> libfiles_prio = prioritizelib(libfiles);
std::vector<std::string> extfiles;
err = getCppFiles(extfiles, "externals/", true);
@ -349,7 +369,7 @@ int main(int argc, char **argv)
outstr += make_vcxproj_cl_entry(R"(..\externals\simplecpp\simplecpp.cpp)", Compile);
outstr += make_vcxproj_cl_entry(R"(..\externals\tinyxml2\tinyxml2.cpp)", Compile);
for (const std::string &libfile: libfiles) {
for (const std::string &libfile: libfiles_prio) {
const std::string l = libfile.substr(4);
outstr += make_vcxproj_cl_entry(l, l == "check.cpp" ? Precompile : Compile);
}
@ -400,7 +420,7 @@ int main(int argc, char **argv)
fout1 << " \\\n" << std::string(11, ' ');
}
fout1 << "\n\nSOURCES += ";
for (const std::string &libfile : libfiles) {
for (const std::string &libfile : libfiles_prio) {
fout1 << "$${PWD}/" << libfile.substr(4);
if (libfile != libfiles.back())
fout1 << " \\\n" << std::string(11, ' ');
@ -638,18 +658,18 @@ int main(int argc, char **argv)
fout << "MAN_SOURCE=man/cppcheck.1.xml\n\n";
fout << "\n###### Object Files\n\n";
fout << "LIBOBJ = " << objfiles(libfiles) << "\n\n";
fout << "LIBOBJ = " << objfiles(libfiles_prio) << "\n\n";
fout << "EXTOBJ = " << objfiles(extfiles) << "\n\n";
fout << "CLIOBJ = " << objfiles(clifiles) << "\n\n";
fout << "TESTOBJ = " << objfiles(testfiles) << "\n\n";
fout << ".PHONY: run-dmake tags\n\n";
fout << "\n###### Targets\n\n";
fout << "cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)\n";
fout << "cppcheck: $(EXTOBJ) $(LIBOBJ) $(CLIOBJ)\n";
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
fout << "all:\tcppcheck testrunner\n\n";
// TODO: generate from clifiles
fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/executor.o cli/processexecutor.o cli/singleexecutor.o cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/cppcheckexecutorseh.o cli/cppcheckexecutorsig.o cli/stacktrace.o cli/filelister.o\n";
fout << "testrunner: $(EXTOBJ) $(TESTOBJ) $(LIBOBJ) cli/executor.o cli/processexecutor.o cli/singleexecutor.o cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/cppcheckexecutorseh.o cli/cppcheckexecutorsig.o cli/stacktrace.o cli/filelister.o\n";
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
fout << "test:\tall\n";
fout << "\t./testrunner\n\n";
@ -745,7 +765,7 @@ int main(int argc, char **argv)
fout << "\n###### Build\n\n";
compilefiles(fout, libfiles, "${INCLUDE_FOR_LIB}");
compilefiles(fout, libfiles_prio, "${INCLUDE_FOR_LIB}");
compilefiles(fout, clifiles, "${INCLUDE_FOR_CLI}");
compilefiles(fout, testfiles, "${INCLUDE_FOR_TEST}");
compilefiles(fout, extfiles, emptyString);