From 7c613080b44d29dd874ac719b24ae6642b1ab4e4 Mon Sep 17 00:00:00 2001 From: Roland Kaminski Date: Thu, 28 Sep 2023 15:19:21 +0200 Subject: [PATCH] setup linters and formatters --- .clang-format | 5 + .clang-tidy | 387 +-------------------------------- .envrc | 4 + .pre-commit-config.yaml | 11 + Makefile | 25 ++- cmake/FindGperftools.cmake | 81 ++++++- cmake/python-site.py | 74 +++++-- libclingo-lpx/CMakeLists.txt | 2 +- libpyclingo-lpx/CMakeLists.txt | 6 +- 9 files changed, 176 insertions(+), 419 deletions(-) create mode 100644 .clang-format create mode 100644 .envrc create mode 100644 .pre-commit-config.yaml diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..0aa04f6 --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +--- +IndentWidth: '4' +ColumnLimit: '120' +IndentCaseLabels: 'true' +... diff --git a/.clang-tidy b/.clang-tidy index eeac901..c9e209c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,389 +1,6 @@ --- -Checks: 'clang-diagnostic-*,clang-analyzer-*,clang-analyzer-*,readability-*,modernize-*,cppcoreguidelines-*,performance-*,bugprone-*,-modernize-use-trailing-return-type,-readability-magic-numbers,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-type-union-access,-cppcoreguidelines-pro-type-vararg,-readability-identifier-length,-readability-function-cognitive-complexity,-bugprone-easily-swappable-parameters,-readability-suspicious-call-argument' +Checks: 'clang-diagnostic-*,clang-analyzer-*,modernize-*,readability-*,-readability-identifier-length,-readability-function-cognitive-complexity' WarningsAsErrors: '' -HeaderFilterRegex: '.*hh' +HeaderFilterRegex: '' AnalyzeTemporaryDtors: false FormatStyle: none -CheckOptions: - - key: performance-unnecessary-copy-initialization.ExcludedContainerTypes - value: '' - - key: modernize-replace-auto-ptr.IncludeStyle - value: llvm - - key: cppcoreguidelines-no-malloc.Reallocations - value: '::realloc' - - key: cppcoreguidelines-owning-memory.LegacyResourceConsumers - value: '::free;::realloc;::freopen;::fclose' - - key: readability-static-accessed-through-instance.NameSpecifierNestingThreshold - value: '3' - - key: bugprone-reserved-identifier.Invert - value: 'false' - - key: modernize-use-auto.MinTypeNameLength - value: '5' - - key: bugprone-unused-return-value.CheckedFunctions - value: '::std::async;::std::launder;::std::remove;::std::remove_if;::std::unique;::std::unique_ptr::release;::std::basic_string::empty;::std::vector::empty;::std::back_inserter;::std::distance;::std::find;::std::find_if;::std::inserter;::std::lower_bound;::std::make_pair;::std::map::count;::std::map::find;::std::map::lower_bound;::std::multimap::equal_range;::std::multimap::upper_bound;::std::set::count;::std::set::find;::std::setfill;::std::setprecision;::std::setw;::std::upper_bound;::std::vector::at;::bsearch;::ferror;::feof;::isalnum;::isalpha;::isblank;::iscntrl;::isdigit;::isgraph;::islower;::isprint;::ispunct;::isspace;::isupper;::iswalnum;::iswprint;::iswspace;::isxdigit;::memchr;::memcmp;::strcmp;::strcoll;::strncmp;::strpbrk;::strrchr;::strspn;::strstr;::wcscmp;::access;::bind;::connect;::difftime;::dlsym;::fnmatch;::getaddrinfo;::getopt;::htonl;::htons;::iconv_open;::inet_addr;::isascii;::isatty;::mmap;::newlocale;::openat;::pathconf;::pthread_equal;::pthread_getspecific;::pthread_mutex_trylock;::readdir;::readlink;::recvmsg;::regexec;::scandir;::semget;::setjmp;::shm_open;::shmget;::sigismember;::strcasecmp;::strsignal;::ttyname' - - key: readability-function-size.VariableThreshold - value: '4294967295' - - key: cert-dcl16-c.NewSuffixes - value: 'L;LL;LU;LLU' - - key: bugprone-narrowing-conversions.WarnOnFloatingPointNarrowingConversion - value: 'true' - - key: cppcoreguidelines-macro-usage.CheckCapsOnly - value: 'false' - - key: bugprone-narrowing-conversions.PedanticMode - value: 'false' - - key: readability-inconsistent-declaration-parameter-name.Strict - value: 'false' - - key: readability-identifier-naming.GetConfigPerFile - value: 'true' - - key: performance-move-const-arg.CheckTriviallyCopyableMove - value: 'true' - - key: modernize-use-default-member-init.UseAssignment - value: 'false' - - key: readability-function-size.NestingThreshold - value: '4294967295' - - key: bugprone-assert-side-effect.IgnoredFunctions - value: __builtin_expect - - key: modernize-use-override.AllowOverrideAndFinal - value: 'false' - - key: cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes - value: '' - - key: readability-function-size.ParameterThreshold - value: '4294967295' - - key: modernize-pass-by-value.ValuesOnly - value: 'false' - - key: modernize-loop-convert.IncludeStyle - value: llvm - - key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons - value: 'false' - - key: bugprone-narrowing-conversions.WarnWithinTemplateInstantiation - value: 'false' - - key: cert-err33-c.CheckedFunctions - value: '::aligned_alloc;::asctime_s;::at_quick_exit;::atexit;::bsearch;::bsearch_s;::btowc;::c16rtomb;::c32rtomb;::calloc;::clock;::cnd_broadcast;::cnd_init;::cnd_signal;::cnd_timedwait;::cnd_wait;::ctime_s;::fclose;::fflush;::fgetc;::fgetpos;::fgets;::fgetwc;::fopen;::fopen_s;::fprintf;::fprintf_s;::fputc;::fputs;::fputwc;::fputws;::fread;::freopen;::freopen_s;::fscanf;::fscanf_s;::fseek;::fsetpos;::ftell;::fwprintf;::fwprintf_s;::fwrite;::fwscanf;::fwscanf_s;::getc;::getchar;::getenv;::getenv_s;::gets_s;::getwc;::getwchar;::gmtime;::gmtime_s;::localtime;::localtime_s;::malloc;::mbrtoc16;::mbrtoc32;::mbsrtowcs;::mbsrtowcs_s;::mbstowcs;::mbstowcs_s;::memchr;::mktime;::mtx_init;::mtx_lock;::mtx_timedlock;::mtx_trylock;::mtx_unlock;::printf_s;::putc;::putwc;::raise;::realloc;::remove;::rename;::scanf;::scanf_s;::setlocale;::setvbuf;::signal;::snprintf;::snprintf_s;::sprintf;::sprintf_s;::sscanf;::sscanf_s;::strchr;::strerror_s;::strftime;::strpbrk;::strrchr;::strstr;::strtod;::strtof;::strtoimax;::strtok;::strtok_s;::strtol;::strtold;::strtoll;::strtoul;::strtoull;::strtoumax;::strxfrm;::swprintf;::swprintf_s;::swscanf;::swscanf_s;::thrd_create;::thrd_detach;::thrd_join;::thrd_sleep;::time;::timespec_get;::tmpfile;::tmpfile_s;::tmpnam;::tmpnam_s;::tss_create;::tss_get;::tss_set;::ungetc;::ungetwc;::vfprintf;::vfprintf_s;::vfscanf;::vfscanf_s;::vfwprintf;::vfwprintf_s;::vfwscanf;::vfwscanf_s;::vprintf_s;::vscanf;::vscanf_s;::vsnprintf;::vsnprintf_s;::vsprintf;::vsprintf_s;::vsscanf;::vsscanf_s;::vswprintf;::vswprintf_s;::vswscanf;::vswscanf_s;::vwprintf_s;::vwscanf;::vwscanf_s;::wcrtomb;::wcschr;::wcsftime;::wcspbrk;::wcsrchr;::wcsrtombs;::wcsrtombs_s;::wcsstr;::wcstod;::wcstof;::wcstoimax;::wcstok;::wcstok_s;::wcstol;::wcstold;::wcstoll;::wcstombs;::wcstombs_s;::wcstoul;::wcstoull;::wcstoumax;::wcsxfrm;::wctob;::wctrans;::wctype;::wmemchr;::wprintf_s;::wscanf;::wscanf_s;' - - key: bugprone-suspicious-string-compare.WarnOnLogicalNotComparison - value: 'false' - - key: readability-redundant-smartptr-get.IgnoreMacros - value: 'true' - - key: cppcoreguidelines-explicit-virtual-functions.AllowOverrideAndFinal - value: 'false' - - key: readability-identifier-naming.AggressiveDependentMemberLookup - value: 'false' - - key: bugprone-suspicious-string-compare.WarnOnImplicitComparison - value: 'true' - - key: modernize-use-emplace.TupleTypes - value: '::std::pair;::std::tuple' - - key: modernize-use-emplace.TupleMakeFunctions - value: '::std::make_pair;::std::make_tuple' - - key: bugprone-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion - value: 'true' - - key: cppcoreguidelines-owning-memory.LegacyResourceProducers - value: '::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile' - - key: bugprone-argument-comment.CommentNullPtrs - value: '0' - - key: bugprone-argument-comment.StrictMode - value: '0' - - key: cppcoreguidelines-init-variables.IncludeStyle - value: llvm - - key: modernize-use-nodiscard.ReplacementString - value: '[[nodiscard]]' - - key: modernize-replace-random-shuffle.IncludeStyle - value: llvm - - key: modernize-loop-convert.MakeReverseRangeHeader - value: '' - - key: modernize-use-bool-literals.IgnoreMacros - value: 'true' - - key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField - value: 'true' - - key: google-readability-namespace-comments.ShortNamespaceLines - value: '10' - - key: bugprone-suspicious-string-compare.StringCompareLikeFunctions - value: '' - - key: modernize-avoid-bind.PermissiveParameterList - value: 'false' - - key: modernize-use-override.FinalSpelling - value: final - - key: cppcoreguidelines-narrowing-conversions.WarnOnFloatingPointNarrowingConversion - value: 'true' - - key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerNarrowingConversion - value: 'true' - - key: modernize-loop-convert.UseCxx20ReverseRanges - value: 'true' - - key: modernize-use-noexcept.ReplacementString - value: '' - - key: cppcoreguidelines-prefer-member-initializer.UseAssignment - value: 'false' - - key: modernize-use-using.IgnoreMacros - value: 'true' - - key: performance-type-promotion-in-math-fn.IncludeStyle - value: llvm - - key: cppcoreguidelines-explicit-virtual-functions.FinalSpelling - value: final - - key: bugprone-narrowing-conversions.WarnOnIntegerNarrowingConversion - value: 'true' - - key: modernize-loop-convert.NamingStyle - value: CamelCase - - key: bugprone-suspicious-include.ImplementationFileExtensions - value: 'c;cc;cpp;cxx' - - key: cppcoreguidelines-pro-type-member-init.UseAssignment - value: 'false' - - key: modernize-loop-convert.MakeReverseRangeFunction - value: '' - - key: bugprone-suspicious-include.HeaderFileExtensions - value: ';h;hh;hpp;hxx' - - key: performance-for-range-copy.WarnOnAllAutoCopies - value: 'false' - - key: readability-inconsistent-declaration-parameter-name.IgnoreMacros - value: 'true' - - key: bugprone-stringview-nullptr.IncludeStyle - value: llvm - - key: bugprone-suspicious-missing-comma.SizeThreshold - value: '5' - - key: readability-identifier-naming.IgnoreFailedSplit - value: 'false' - - key: performance-no-automatic-move.AllowedTypes - value: '' - - key: modernize-pass-by-value.IncludeStyle - value: llvm - - key: bugprone-sizeof-expression.WarnOnSizeOfThis - value: 'true' - - key: bugprone-string-constructor.WarnOnLargeLength - value: 'true' - - key: bugprone-too-small-loop-variable.MagnitudeBitsUpperLimit - value: '16' - - key: cppcoreguidelines-explicit-virtual-functions.OverrideSpelling - value: override - - key: readability-qualified-auto.AddConstToQualified - value: 'true' - - key: readability-simplify-boolean-expr.ChainedConditionalReturn - value: 'false' - - key: readability-else-after-return.WarnOnConditionVariables - value: 'true' - - key: bugprone-argument-comment.CommentIntegerLiterals - value: '0' - - key: readability-uppercase-literal-suffix.IgnoreMacros - value: 'true' - - key: modernize-use-nullptr.NullMacros - value: 'NULL' - - key: modernize-make-shared.IgnoreMacros - value: 'true' - - key: bugprone-dynamic-static-initializers.HeaderFileExtensions - value: ';h;hh;hpp;hxx' - - key: bugprone-suspicious-enum-usage.StrictMode - value: 'false' - - key: performance-unnecessary-copy-initialization.AllowedTypes - value: '' - - key: bugprone-suspicious-missing-comma.MaxConcatenatedTokens - value: '5' - - key: modernize-use-transparent-functors.SafeMode - value: 'false' - - key: cppcoreguidelines-macro-usage.AllowedRegexp - value: '^DEBUG_*' - - key: modernize-make-shared.IgnoreDefaultInitialization - value: 'true' - - key: bugprone-argument-comment.CommentCharacterLiterals - value: '0' - - key: bugprone-implicit-widening-of-multiplication-result.UseCXXHeadersInCppSources - value: 'true' - - key: bugprone-not-null-terminated-result.WantToUseSafeFunctions - value: 'true' - - key: modernize-make-shared.IncludeStyle - value: llvm - - key: cppcoreguidelines-narrowing-conversions.PedanticMode - value: 'false' - - key: bugprone-string-constructor.LargeLengthThreshold - value: '8388608' - - key: readability-simplify-boolean-expr.ChainedConditionalAssignment - value: 'false' - - key: cppcoreguidelines-avoid-magic-numbers.IgnoreAllFloatingPointValues - value: 'false' - - key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions - value: 'false' - - key: bugprone-implicit-widening-of-multiplication-result.UseCXXStaticCastsInCppSources - value: 'true' - - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField - value: 'false' - - key: bugprone-exception-escape.FunctionsThatShouldNotThrow - value: '' - - key: bugprone-argument-comment.CommentStringLiterals - value: '0' - - key: readability-function-size.LineThreshold - value: '4294967295' - - key: modernize-loop-convert.MaxCopySize - value: '16' - - key: performance-inefficient-vector-operation.EnableProto - value: 'false' - - key: modernize-make-shared.MakeSmartPtrFunction - value: 'std::make_shared' - - key: bugprone-signed-char-misuse.CharTypdefsToIgnore - value: '' - - key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader - value: '' - - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors - value: 'false' - - key: modernize-make-unique.IgnoreMacros - value: 'true' - - key: performance-for-range-copy.AllowedTypes - value: '' - - key: modernize-make-shared.MakeSmartPtrFunctionHeader - value: '' - - key: bugprone-argument-comment.CommentFloatLiterals - value: '0' - - key: modernize-use-override.IgnoreDestructors - value: 'false' - - key: bugprone-sizeof-expression.WarnOnSizeOfConstant - value: 'true' - - key: readability-redundant-string-init.StringNames - value: '::std::basic_string_view;::std::basic_string' - - key: modernize-make-unique.IgnoreDefaultInitialization - value: 'true' - - key: modernize-use-emplace.ContainersWithPushBack - value: '::std::vector;::std::list;::std::deque' - - key: modernize-make-unique.IncludeStyle - value: llvm - - key: readability-braces-around-statements.ShortStatementLines - value: '0' - - key: bugprone-argument-comment.CommentUserDefinedLiterals - value: '0' - - key: bugprone-argument-comment.CommentBoolLiterals - value: '0' - - key: modernize-use-override.OverrideSpelling - value: override - - key: readability-redundant-declaration.IgnoreMacros - value: 'true' - - key: performance-inefficient-string-concatenation.StrictMode - value: 'false' - - key: readability-implicit-bool-conversion.AllowPointerConditions - value: 'false' - - key: google-readability-braces-around-statements.ShortStatementLines - value: '1' - - key: modernize-make-unique.MakeSmartPtrFunction - value: 'std::make_unique' - - key: cppcoreguidelines-pro-type-member-init.IgnoreArrays - value: 'false' - - key: readability-else-after-return.WarnOnUnfixable - value: 'true' - - key: bugprone-reserved-identifier.AllowedIdentifiers - value: '' - - key: cppcoreguidelines-avoid-magic-numbers.IgnoredFloatingPointValues - value: '1.0;100.0;' - - key: modernize-use-emplace.IgnoreImplicitConstructors - value: 'false' - - key: modernize-make-unique.MakeSmartPtrFunctionHeader - value: '' - - key: bugprone-signal-handler.AsyncSafeFunctionSet - value: POSIX - - key: modernize-use-equals-delete.IgnoreMacros - value: 'true' - - key: cppcoreguidelines-pro-bounds-constant-array-index.IncludeStyle - value: llvm - - key: cppcoreguidelines-narrowing-conversions.WarnWithinTemplateInstantiation - value: 'false' - - key: cppcoreguidelines-macro-usage.IgnoreCommandLineMacros - value: 'true' - - key: cppcoreguidelines-narrowing-conversions.WarnOnEquivalentBitWidth - value: 'true' - - key: bugprone-misplaced-widening-cast.CheckImplicitCasts - value: 'false' - - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnorePublicMemberVariables - value: 'false' - - key: modernize-loop-convert.MinConfidence - value: reasonable - - key: performance-unnecessary-value-param.AllowedTypes - value: '' - - key: readability-uniqueptr-delete-release.PreferResetCall - value: 'false' - - key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted - value: 'false' - - key: cppcoreguidelines-avoid-magic-numbers.IgnorePowersOf2IntegerValues - value: 'false' - - key: google-readability-namespace-comments.SpacesBeforeComments - value: '2' - - key: cppcoreguidelines-avoid-magic-numbers.IgnoreBitFieldsWidths - value: 'true' - - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic - value: 'true' - - key: readability-uppercase-literal-suffix.NewSuffixes - value: '' - - key: cppcoreguidelines-no-malloc.Allocations - value: '::malloc;::calloc' - - key: bugprone-narrowing-conversions.WarnOnEquivalentBitWidth - value: 'true' - - key: bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression - value: 'false' - - key: performance-faster-string-find.StringLikeClasses - value: '::std::basic_string;::std::basic_string_view' - - key: cppcoreguidelines-avoid-magic-numbers.IgnoredIntegerValues - value: '1;2;3;4;' - - key: bugprone-narrowing-conversions.IgnoreConversionFromTypes - value: '' - - key: bugprone-assert-side-effect.CheckFunctionCalls - value: 'false' - - key: bugprone-string-constructor.StringNames - value: '::std::basic_string;::std::basic_string_view' - - key: bugprone-assert-side-effect.AssertMacros - value: assert,NSAssert,NSCAssert - - key: readability-function-size.BranchThreshold - value: '4294967295' - - key: bugprone-exception-escape.IgnoredExceptions - value: '' - - key: readability-function-size.StatementThreshold - value: '800' - - key: llvm-qualified-auto.AddConstToQualified - value: 'false' - - key: bugprone-signed-char-misuse.DiagnoseSignedUnsignedCharComparisons - value: 'true' - - key: modernize-use-default-member-init.IgnoreMacros - value: 'true' - - key: modernize-use-noexcept.UseNoexceptFalse - value: 'true' - - key: readability-identifier-naming.IgnoreMainLikeFunctions - value: 'false' - - key: readability-implicit-bool-conversion.AllowIntegerConditions - value: 'false' - - key: cppcoreguidelines-init-variables.MathHeader - value: '' - - key: google-readability-function-size.StatementThreshold - value: '800' - - key: llvm-else-after-return.WarnOnConditionVariables - value: 'false' - - key: bugprone-sizeof-expression.WarnOnSizeOfCompareToConstant - value: 'true' - - key: bugprone-argument-comment.IgnoreSingleArgument - value: '0' - - key: bugprone-reserved-identifier.AggressiveDependentMemberLookup - value: 'false' - - key: modernize-raw-string-literal.DelimiterStem - value: lit - - key: modernize-use-equals-default.IgnoreMacros - value: 'true' - - key: cppcoreguidelines-narrowing-conversions.WarnOnIntegerToFloatingPointNarrowingConversion - value: 'true' - - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor - value: 'false' - - key: bugprone-suspicious-missing-comma.RatioThreshold - value: '0.200000' - - key: modernize-raw-string-literal.ReplaceShorterLiterals - value: 'false' - - key: modernize-use-emplace.SmartPointers - value: '::std::shared_ptr;::std::unique_ptr;::std::auto_ptr;::std::weak_ptr' - - key: cppcoreguidelines-no-malloc.Deallocations - value: '::free' - - key: modernize-use-auto.RemoveStars - value: 'false' - - key: bugprone-dangling-handle.HandleClasses - value: 'std::basic_string_view;std::experimental::basic_string_view' - - key: bugprone-implicit-widening-of-multiplication-result.IncludeStyle - value: llvm - - key: performance-unnecessary-value-param.IncludeStyle - value: llvm - - key: performance-inefficient-vector-operation.VectorLikeClasses - value: '::std::vector' - - key: modernize-replace-disallow-copy-and-assign-macro.MacroName - value: DISALLOW_COPY_AND_ASSIGN - - key: readability-redundant-member-init.IgnoreBaseInCopyConstructors - value: 'false' - - key: llvm-else-after-return.WarnOnUnfixable - value: 'false' - - key: readability-simplify-subscript-expr.Types - value: '::std::basic_string;::std::basic_string_view;::std::vector;::std::array' -... - diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8aa087d --- /dev/null +++ b/.envrc @@ -0,0 +1,4 @@ +ACTIVATE=/mnt/scratch/kaminski/conda/bin/activate +if [[ -e "${ACTIVATE}" ]]; then + source /mnt/scratch/kaminski/conda/bin/activate clang +fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c0b9f64 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +fail_fast: false +repos: + - repo: https://github.com/pocc/pre-commit-hooks + rev: v1.3.5 + hooks: + - id: clang-format + exclude: _clingodl.c + args: ["-i"] + - id: clang-tidy + exclude: _clingodl.c + args: ["-fix"] diff --git a/Makefile b/Makefile index 7e3cf2e..58c03ee 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,23 @@ BUILD_TYPE:=debug CLINGO_DIR:=${HOME}/.local/opt/potassco/$(BUILD_TYPE)/lib/cmake/Clingo -CLANG_TIDY:=clang-tidy;--config-file;$(CURDIR)/.clang-tidy CXXFLAGS=-Wall -Wextra -Wpedantic -Werror +define cmake_options +-G Ninja \ +-S . \ +-B "build/$(BUILD_TYPE)" \ +-DCMAKE_INSTALL_PREFIX=${HOME}/.local/opt/potassco/$(BUILD_TYPE) \ +-DCMAKE_CXX_FLAGS="$(CXXFLAGS)" \ +-DClingo_DIR="$(CLINGO_DIR)" \ +-DCLINGOLPX_BUILD_TESTS=On \ +-DCMAKE_EXPORT_COMPILE_COMMANDS=On +endef + +ifeq ($(BUILD_TYPE),profile) + cmake_options += -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCLINGOLPX_PROFILE=On +else + cmake_options += -DCMAKE_BUILD_TYPE="$(BUILD_TYPE)" +endif + .PHONY: all configure compdb @@ -9,11 +25,10 @@ all: configure @TERM=dumb MAKEFLAGS= MFLAGS= cmake --build "build/$(BUILD_TYPE)" --target all test: all - @cmake --build "build/$(BUILD_TYPE)" --target "test" - + @TERM=dumb MAKEFLAGS= MFLAGS= cmake --build "build/$(BUILD_TYPE)" --target "test" %: configure - @cmake --build "build/$(BUILD_TYPE)" --target "$@" + @TERM=dumb MAKEFLAGS= MFLAGS= cmake --build "build/$(BUILD_TYPE)" --target "$@" # compdb can be installed with pip compdb: configure @@ -22,7 +37,7 @@ compdb: configure configure: build/$(BUILD_TYPE)/build.ninja build/$(BUILD_TYPE)/build.ninja: - cmake -G Ninja -H. -B"build/$(BUILD_TYPE)" -DCMAKE_INSTALL_PREFIX=${HOME}/.local/opt/potassco/$(BUILD_TYPE) -DCMAKE_CXX_FLAGS="$(CXXFLAGS)" -DCMAKE_BUILD_TYPE="$(BUILD_TYPE)" -DCMAKE_CXX_CLANG_TIDY:STRING="$(CLANG_TIDY)" -DClingo_DIR="$(CLINGO_DIR)" -DCLINGOLPX_BUILD_TESTS=On -DCMAKE_EXPORT_COMPILE_COMMANDS=On + cmake $(cmake_options) Makefile: : diff --git a/cmake/FindGperftools.cmake b/cmake/FindGperftools.cmake index 10c79cc..0a27135 100644 --- a/cmake/FindGperftools.cmake +++ b/cmake/FindGperftools.cmake @@ -1,15 +1,76 @@ -find_library(GPERFTOOLS_PROFILER NAMES profiler) +# Try to find gperftools +# Once done, this will define +# +# Gperftools_FOUND - system has Profiler +# GPERFTOOLS_INCLUDE_DIR - the Profiler include directories +# Tcmalloc_INCLUDE_DIR - where to find Tcmalloc.h +# GPERFTOOLS_TCMALLOC_LIBRARY - link it to use tcmalloc +# GPERFTOOLS_TCMALLOC_MINIMAL_LIBRARY - link it to use tcmalloc_minimal +# GPERFTOOLS_PROFILER_LIBRARY - link it to use Profiler +# TCMALLOC_VERSION_STRING +# TCMALLOC_VERSION_MAJOR +# TCMALLOC_VERSION_MINOR +# TCMALLOC_VERSION_PATCH -find_path(GPERFTOOLS_INCLUDE NAMES gperftools/profiler.h) +find_path(GPERFTOOLS_INCLUDE_DIR gperftools/profiler.h + HINTS $ENV{GPERF_ROOT}/include) +find_path(Tcmalloc_INCLUDE_DIR gperftools/tcmalloc.h + HINTS $ENV{GPERF_ROOT}/include) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Gperftools DEFAULT_MSG GPERFTOOLS_PROFILER GPERFTOOLS_INCLUDE) +if(Tcmalloc_INCLUDE_DIR AND EXISTS "${Tcmalloc_INCLUDE_DIR}/gperftools/tcmalloc.h") + foreach(ver "MAJOR" "MINOR" "PATCH") + file(STRINGS "${Tcmalloc_INCLUDE_DIR}/gperftools/tcmalloc.h" TC_VER_${ver}_LINE + REGEX "^#define[ \t]+TC_VERSION_${ver}[ \t]+[^ \t]+$") + string(REGEX REPLACE "^#define[ \t]+TC_VERSION_${ver}[ \t]+(\".)?([0-9]*)\"?$" + "\\2" TCMALLOC_VERSION_${ver} "${TC_VER_${ver}_LINE}") + unset(TC_VER_${ver}_LINE) + endforeach() + set(TCMALLOC_VERSION_STRING "${TCMALLOC_VERSION_MAJOR}.${TCMALLOC_VERSION_MINOR}") + if(NOT TCMALLOC_VERSION_PATCH STREQUAL "") + set(TCMALLOC_VERSION_STRING "${TCMALLOC_VERSION_STRING}.${TCMALLOC_VERSION_PATCH}") + endif() +endif() + +foreach(component tcmalloc tcmalloc_minimal profiler) + string(TOUPPER ${component} COMPONENT) + find_library(GPERFTOOLS_${COMPONENT}_LIBRARY ${component} + HINTS $ENV{GPERF_ROOT}/lib) + list(APPEND GPERFTOOLS_LIBRARIES GPERFTOOLS_${COMPONENT}_LIBRARY) +endforeach() -set(GPERFTOOLS_INCLUDE_DIRS ${GMPXX_INCLUDE}) -set(GPERFTOOLS_LIBRARIES ${GPERFTOOLS_PROFILER}) +set(_Gperftools_FIND_REQUIRED_VARS "GPERFTOOLS_INCLUDE_DIR") +if(Gperftools_FIND_COMPONENTS) + foreach(component ${Gperftools_FIND_COMPONENTS}) + string(TOUPPER ${component} COMPONENT) + list(APPEND _Gperftools_FIND_REQUIRED_VARS "GPERFTOOLS_${COMPONENT}_LIBRARY") + endforeach() +else() + list(APPEND _Gperftools_FIND_REQUIRED_VARS "GPERFTOOLS_LIBRARIES") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Gperftools + FOUND_VAR Gperftools_FOUND + REQUIRED_VARS ${_Gperftools_FIND_REQUIRED_VARS} + VERSION_VAR TCMALLOC_VERSION_STRING) -add_library(Gperftools::Gperftools INTERFACE IMPORTED) -set_property(TARGET Gperftools::Gperftools PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${GPERFTOOLS_INCLUDE_DIRS}") -set_property(TARGET Gperftools::Gperftools PROPERTY INTERFACE_LINK_LIBRARIES "${GPERFTOOLS_LIBRARIES}") +mark_as_advanced(${GPERFTOOLS_LIBRARIES} GPERFTOOLS_INCLUDE_DIR) -mark_as_advanced(GPERFTOOLS_PROFILER GPERFTOOLS_INCLUDE GPERFTOOLS_INCLUDE_DIRS GPERFTOOLS_LIBRARIES) +if(Gperftools_FOUND) + foreach(Component Tcmalloc Tcmalloc_minimal Profiler) + if(NOT (TARGET Gperftools::${Component})) + string(TOUPPER ${Component} COMPONENT) + add_library(Gperftools::${Component} UNKNOWN IMPORTED) + set_target_properties(Gperftools::${Component} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${GPERFTOOLS_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + IMPORTED_LOCATION "${GPERFTOOLS_${COMPONENT}_LIBRARY}") + endif() + endforeach() + foreach(Component Tcmalloc Tcmalloc_minimal) + if(NOT (TARGET Gperftools::${Component})) + set_target_properties(Gperftools::${Component} PROPERTIES + INTERFACE_COMPILE_OPTIONS "-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free") + endif() + endforeach() +endif() diff --git a/cmake/python-site.py b/cmake/python-site.py index 81b5534..f409dd4 100644 --- a/cmake/python-site.py +++ b/cmake/python-site.py @@ -1,17 +1,61 @@ -try: - from setuptools.sysconfig import get_python_lib, get_config_vars -except ImportError: - from distutils.sysconfig import get_python_lib, get_config_vars import sys +from argparse import ArgumentParser -if sys.argv[1] == "prefix": - print(get_python_lib(True, False, sys.argv[2] if len(sys.argv) > 2 else None)) -elif sys.argv[1] == "suffix": - SO, SOABI, EXT_SUFFIX = get_config_vars("SO", "SOABI", "EXT_SUFFIX") - if EXT_SUFFIX is not None: - ext = EXT_SUFFIX - elif SOABI is not None: - ext = ''.join('.', SOABI, SO) - else: - ext = SO - print(ext) +if sys.version_info >= (3, 11): + NEW_STYLE = True + from sysconfig import get_config_var, get_config_vars, get_preferred_scheme, get_path +else: + NEW_STYLE = False + from site import USER_SITE + try: + from setuptools.sysconfig import get_python_lib, get_config_vars + except ImportError: + from distutils.sysconfig import get_python_lib, get_config_vars + +parser = ArgumentParser() +if sys.version_info >= (3, 7): + subparser = parser.add_subparsers(required=True, dest="action") +else: + subparser = parser.add_subparsers(dest="action") + +prefix_parser = subparser.add_parser("target") +prefix_group = prefix_parser.add_mutually_exclusive_group() +prefix_group.add_argument("--user", action='store_true', help='get user prefix') +prefix_group.add_argument("--prefix", type=str, help='prepend prefix') + +prefix_parser = subparser.add_parser("suffix") + +result = parser.parse_args() + +if NEW_STYLE: + if result.action == "target": + if result.user: + scheme = get_preferred_scheme("user") + else: + scheme = get_preferred_scheme("prefix") + if result.prefix is not None: + cvars = get_config_vars() + cvars["base"] = result.prefix + cvars["platbase"] = result.prefix + platlib = get_path("platlib", scheme, cvars) + else: + platlib = get_path("platlib", scheme) + print(platlib) + elif result.action == "suffix": + print(get_config_var('EXT_SUFFIX')) +else: + # TODO: remove once python 3.10 is eol + if result.action == "target": + if result.user: + print(USER_SITE) + else: + print(get_python_lib(True, False, result.prefix)) + elif result.action == "suffix": + SO, SOABI, EXT_SUFFIX = get_config_vars("SO", "SOABI", "EXT_SUFFIX") + if EXT_SUFFIX is not None: + ext = EXT_SUFFIX + elif SOABI is not None: + ext = ''.join('.', SOABI, SO) + else: + ext = SO + print(ext) diff --git a/libclingo-lpx/CMakeLists.txt b/libclingo-lpx/CMakeLists.txt index 0c3c980..fa0c10f 100644 --- a/libclingo-lpx/CMakeLists.txt +++ b/libclingo-lpx/CMakeLists.txt @@ -54,7 +54,7 @@ endif() if (CLINGOLPX_PROFILE) target_compile_definitions(libclingo-lpx ${clingolpx_public_scope_} "CLINGOLPX_PROFILE") - target_link_libraries(libclingo-lpx ${clingolpx_public_scope_} Gperftools::Gperftools) + target_link_libraries(libclingo-lpx ${clingolpx_public_scope_} Gperftools::Profiler) endif() if (CLINGOLPX_CROSSCHECK) target_compile_definitions(libclingo-lpx ${clingolpx_public_scope_} "CLINGOLPX_CROSSCHECK") diff --git a/libpyclingo-lpx/CMakeLists.txt b/libpyclingo-lpx/CMakeLists.txt index 7c8014f..5f1688c 100644 --- a/libpyclingo-lpx/CMakeLists.txt +++ b/libpyclingo-lpx/CMakeLists.txt @@ -9,11 +9,11 @@ set(source if (NOT PYCLINGOLPX_INSTALL_DIR AND Python_EXECUTABLE) if (PYCLINGOLPX_INSTALL STREQUAL "user") - execute_process(COMMAND ${Python_EXECUTABLE} ${CLINGOLPX_SOURCE_DIR}/cmake/python-site.py site OUTPUT_VARIABLE PYCLINGOLPX_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${Python_EXECUTABLE} ${CLINGOLPX_SOURCE_DIR}/cmake/python-site.py target --user OUTPUT_VARIABLE PYCLINGOLPX_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) elseif(PYCLINGOLPX_INSTALL STREQUAL "prefix") - execute_process(COMMAND ${Python_EXECUTABLE} ${CLINGOLPX_SOURCE_DIR}/cmake/python-site.py prefix "${CMAKE_INSTALL_PREFIX}" OUTPUT_VARIABLE PYCLINGOLPX_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${Python_EXECUTABLE} ${CLINGOLPX_SOURCE_DIR}/cmake/python-site.py target --prefix "${CMAKE_INSTALL_PREFIX}" OUTPUT_VARIABLE PYCLINGOLPX_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) else() - execute_process(COMMAND ${Python_EXECUTABLE} ${CLINGOLPX_SOURCE_DIR}/cmake/python-site.py prefix OUTPUT_VARIABLE PYCLINGOLPX_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${Python_EXECUTABLE} ${CLINGOLPX_SOURCE_DIR}/cmake/python-site.py target OUTPUT_VARIABLE PYCLINGOLPX_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) endif() endif()