Let CppunitTest_odk_checkapi build against the SDK include directory

...which contains only the URE include files, rather than against the SRCDIR one
which contains many more.  This would have prevented
148536afc9 "Drop config_global.h from
osl/module.h", where an URE include file had accidentally started to include a
non-URE file.

(The way $(INCLUDE) is now set up in odk/CppunitTest_odk_checkapi.mk is a bit
hacky, and this change required teaching compilerplugins about SDKDIR to avoid
false warnings.  Another approach would be to make the test compile in the SDK
build environment, similarly to CustomTarget_odk/build-examples, but setting up
the SDK build environment from within gbuild is not supported at least on
Windows for now.  A smaller improvement would be to drop the need to include any
CppUnit include directories, by turning the test into some kind of compile-only
test similar to a gb_CompilerTest.)

Change-Id: If79761909c67c3162d01f847dfb5d4f538f91ca1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128591
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2022-01-19 08:14:12 +01:00
parent 2cfa04cbf0
commit d923625d89
7 changed files with 42 additions and 23 deletions

View File

@ -285,7 +285,8 @@ bool Plugin::isInUnoIncludeFile(SourceLocation spellingLocation) const
|| hasPathnamePrefix(name, SRCDIR "/include/sal/")
|| hasPathnamePrefix(name, SRCDIR "/include/salhelper/")
|| hasPathnamePrefix(name, SRCDIR "/include/typelib/")
|| hasPathnamePrefix(name, SRCDIR "/include/uno/"));
|| hasPathnamePrefix(name, SRCDIR "/include/uno/")
|| hasPathnamePrefix(name, SDKDIR "/include/"));
}
bool Plugin::isInUnoIncludeFile(const FunctionDecl* functionDecl) const
@ -722,6 +723,16 @@ bool isSamePathname(StringRef pathname, StringRef other)
pathname, other, [](StringRef p, StringRef a) { return p == a; });
}
bool isSameUnoIncludePathname(StringRef fullPathname, StringRef includePathname)
{
llvm::SmallVector<char, 256> buf;
if (isSamePathname(fullPathname, (SRCDIR "/include/" + includePathname).toStringRef(buf))) {
return true;
}
buf.clear();
return isSamePathname(fullPathname, (SDKDIR "/include/" + includePathname).toStringRef(buf));
}
bool hasCLanguageLinkageType(FunctionDecl const * decl) {
assert(decl != nullptr);
if (decl->isExternC()) {

View File

@ -282,6 +282,10 @@ bool hasPathnamePrefix(StringRef pathname, StringRef prefix);
// also contain backslashes:
bool isSamePathname(StringRef pathname, StringRef other);
// Check whether fullPathname is either SRCDIR/include/includePathname or
// SDKDIR/include/includePathname:
bool isSameUnoIncludePathname(StringRef fullPathname, StringRef includePathname);
// It appears that, given a function declaration, there is no way to determine
// the language linkage of the function's type, only of the function's name
// (via FunctionDecl::isExternC); however, in a case like

View File

@ -113,14 +113,12 @@ void ReservedId::postRun() {
auto loc = d->getLocation();
if (loc.isValid() && !ignoreLocation(loc)) {
auto file = getFilenameOfLocation(loc);
if (!loplugin::isSamePathname(
if (!loplugin::isSameUnoIncludePathname(
file,
SRCDIR
"/include/cppuhelper/implbase_ex_post.hxx")
&& !loplugin::isSamePathname(
"cppuhelper/implbase_ex_post.hxx")
&& !loplugin::isSameUnoIncludePathname(
file,
SRCDIR
"/include/cppuhelper/implbase_ex_pre.hxx"))
"cppuhelper/implbase_ex_pre.hxx"))
{
report(
DiagnosticsEngine::Warning,

View File

@ -8,6 +8,7 @@ Settings related to Clang compiler plugins.
#define CONFIG_CLANG_H
#undef BUILDDIR
#undef SDKDIR
#undef SRCDIR
#undef WORKDIR

View File

@ -5340,6 +5340,7 @@ AC_SUBST(P_SEP)
AC_SUBST(WORKDIR)
AC_SUBST(PLATFORMID)
AC_SUBST(WINDOWS_X64)
AC_DEFINE_UNQUOTED(SDKDIR, "$INSTDIR/$SDKDIRNAME")
AC_DEFINE_UNQUOTED(WORKDIR,"$WORKDIR")
if test "$OS" = WNT -a "$COM" = MSC; then

View File

@ -9,29 +9,33 @@
$(eval $(call gb_CppunitTest_CppunitTest,odk_checkapi))
$(eval $(call gb_CppunitTest_use_custom_headers,odk_checkapi,\
odk/allheaders \
))
$(eval $(call gb_CppunitTest_add_exception_objects,odk_checkapi,\
odk/qa/checkapi/checkapi \
))
$(eval $(call gb_CppunitTest_use_internal_comprehensive_api,odk_checkapi,\
udkapi \
))
$(eval $(call gb_CppunitTest_add_cxxflags,odk_checkapi,\
$(gb_CXX03FLAGS) \
))
$(eval $(call gb_CppunitTest_use_libraries,odk_checkapi,\
cppu \
cppuhelper \
sal \
salhelper \
))
$(eval $(call gb_CppunitTest_set_external_code,odk_checkapi))
# The remaining lines must be in the given order, to set up a set of include paths that only
# contains the instdir SDK include directory, plus SOLARINC as needed for platform-specific
# includes, plus the workdir sub-directory containing the generated allheaders.hxx and the workdir
# sub-directory containing the generated UNOIDL include files (which are not bundled in the SDK but
# would rather get created on demand by the SDK's makefiles), plus whatever is needed for CppUnit:
$(eval $(call gb_CppunitTest_set_include,odk_checkapi, \
-I$(INSTDIR)/$(SDKDIRNAME)/include $(SOLARINC)))
$(eval $(call gb_CppunitTest_use_custom_headers,odk_checkapi,\
odk/allheaders \
))
$(eval $(call gb_CppunitTest_use_internal_comprehensive_api,odk_checkapi,\
udkapi \
))
$(eval $(call gb_CppunitTest_use_external,odk_checkapi,cppunit))
# vim: set noet sw=4 ts=4:

View File

@ -1160,7 +1160,7 @@ endef
# call gb_LinkTarget_set_include,linktarget,includes
define gb_LinkTarget_set_include
$(call gb_LinkTarget__check_srcdir_paths,$(1),\
$(patsubst -I%,%,$(filter -I$(SRCDIR)/%,$(filter-out -I$(WORKDIR)/%,$(2)))))
$(patsubst -I%,%,$(filter -I$(SRCDIR)/%,$(filter-out -I$(INSTDIR)/% -I$(WORKDIR)/%,$(2)))))
$(call gb_LinkTarget_get_target,$(1)) : INCLUDE := $(2)
endef