Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/dictgen/src/rootcling_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3345,11 +3345,12 @@ class TRootClingCallbacks : public cling::InterpreterCallbacks {
if (!curLexer) return;
auto fileEntry = curLexer->getFileEntry();
if (!fileEntry) return;
auto thisFileName = fileEntry->getName();
auto thisFileName = llvm::sys::path::filename(fileEntry->getName()).str();
auto fileNameAsString = FileName.str();
auto isThisLinkdef = ROOT::TMetaUtils::IsLinkdefFile(thisFileName.data());
auto isThisLinkdef = ROOT::TMetaUtils::IsLinkdefFile(thisFileName.c_str());
if (isThisLinkdef) {
auto isTheIncludedLinkdef = ROOT::TMetaUtils::IsLinkdefFile(fileNameAsString.c_str());
auto includedFileName = llvm::sys::path::filename(FileName).str();
auto isTheIncludedLinkdef = ROOT::TMetaUtils::IsLinkdefFile(includedFileName.c_str());
if (isTheIncludedLinkdef) {
fFilesIncludedByLinkdef.clear();
isLocked = true;
Expand Down
30 changes: 30 additions & 0 deletions roottest/root/meta/rootcling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,36 @@ ROOTTEST_ADD_TEST(includeInLinkdef
COPY_TO_BUILDDIR headerForLdef.h
FIXTURES_REQUIRED root-meta-roocling-includeInLinkdefDict-fixture)

# Directory names must not make ordinary headers look like LinkDef files.
ROOTTEST_GENERATE_DICTIONARY(includeDirectoryDict
includeDirectory.h
LINKDEF includeDirectoryLinkDef.h
FIXTURES_SETUP root-meta-rootcling-includeDirectoryDict-fixture)

ROOTTEST_ADD_TEST(includeDirectory
MACRO assertIncludeDictionary.C
MACROARG "\"includeDirectoryDict\",\"RootclingDirectory::Payload\""
FIXTURES_REQUIRED root-meta-rootcling-includeDirectoryDict-fixture)

ROOTTEST_GENERATE_DICTIONARY(includeDirectoryFromSelectionDict
LINKDEF includeDirectoryFromSelectionLinkDef.h
FIXTURES_SETUP root-meta-rootcling-includeDirectoryFromSelectionDict-fixture)

ROOTTEST_ADD_TEST(includeDirectoryFromSelection
MACRO assertIncludeDictionary.C
MACROARG "\"includeDirectoryFromSelectionDict\",\"RootclingDirectory::DirectPayload\""
FIXTURES_REQUIRED root-meta-rootcling-includeDirectoryFromSelectionDict-fixture)

ROOTTEST_GENERATE_DICTIONARY(includeNestedDict
includeNested.h
LINKDEF NestedSelection/OuterLinkDef.h
FIXTURES_SETUP root-meta-rootcling-includeNestedDict-fixture)

ROOTTEST_ADD_TEST(includeNested
MACRO assertIncludeDictionary.C
MACROARG "\"includeNestedDict\",\"RootclingNested::Payload\""
FIXTURES_REQUIRED root-meta-rootcling-includeNestedDict-fixture)

Comment on lines +33 to +62

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is not yet verifying if the intended dictionary where actually generated.

@agourakis82 agourakis82 Oct 28, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an explicit check in 9694854, using assertIncludeDictionary.C. Each case starts a fresh ROOT process and loads the requested dictionary library. It then looks up the compiled class registration with TClassTable::GetDictNorm and checks HasDictionary() and the class name.

Starting a fresh process also prevents a dictionary loaded by another test from hiding a missing registration. This should check that the intended dictionary is present, rather than just that generation completed successfully.

# ROOT-8492
ROOTTEST_ADD_TEST(selectUnion
COMMAND ${ROOT_rootcling_CMD} -f NestedClassOff.Dict.cc ${CMAKE_CURRENT_SOURCE_DIR}/NestedClassOff.h ${CMAKE_CURRENT_SOURCE_DIR}/NestedClassOff.LinkDef.h
Expand Down
6 changes: 6 additions & 0 deletions roottest/root/meta/rootcling/LinkDefDirectory/Wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef ROOTTEST_ROOT_META_ROOTCLING_DIRECTORY_WRAPPER_H
#define ROOTTEST_ROOT_META_ROOTCLING_DIRECTORY_WRAPPER_H

#include "detail/Payload.h"

#endif
13 changes: 13 additions & 0 deletions roottest/root/meta/rootcling/LinkDefDirectory/detail/Payload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef ROOTTEST_ROOT_META_ROOTCLING_DIRECTORY_PAYLOAD_H
#define ROOTTEST_ROOT_META_ROOTCLING_DIRECTORY_PAYLOAD_H

namespace RootclingDirectory {
struct Payload {
int value = 0;
};
struct DirectPayload {
int value = 0;
};
} // namespace RootclingDirectory

#endif
5 changes: 5 additions & 0 deletions roottest/root/meta/rootcling/NestedSelection/After.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Parsing this selection-only header in rootcling is intentional. The guard
// detects an unwanted direct include during later dictionary C++ compilation.
#ifndef __ROOTCLING__
#error "Headers collected after a nested LinkDef must not be emitted directly."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This files seems explicitly included in the file passed to rootcling, why is it an error that it is parsed by rootcling?

#endif
5 changes: 5 additions & 0 deletions roottest/root/meta/rootcling/NestedSelection/Before.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Parsing this selection-only header in rootcling is intentional. The guard
// detects an unwanted direct include during later dictionary C++ compilation.
#ifndef __ROOTCLING__
#error "Headers collected before a nested LinkDef must not be emitted directly."
#endif
6 changes: 6 additions & 0 deletions roottest/root/meta/rootcling/NestedSelection/InnerLinkDef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifdef __ROOTCLING__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class RootclingNested::Payload + ;
#endif
3 changes: 3 additions & 0 deletions roottest/root/meta/rootcling/NestedSelection/OuterLinkDef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "Before.h"
#include "InnerLinkDef.h"
#include "After.h"
10 changes: 10 additions & 0 deletions roottest/root/meta/rootcling/NestedSelection/Payload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef ROOTTEST_ROOT_META_ROOTCLING_NESTED_PAYLOAD_H
#define ROOTTEST_ROOT_META_ROOTCLING_NESTED_PAYLOAD_H

namespace RootclingNested {
struct Payload {
int value = 0;
};
} // namespace RootclingNested

#endif
34 changes: 34 additions & 0 deletions roottest/root/meta/rootcling/assertIncludeDictionary.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "TClass.h"
#include "TClassTable.h"
#include "TError.h"
#include "TSystem.h"

#include <cstring>

int assertIncludeDictionary(const char *library, const char *className)
{
// Each CTest invocation starts a fresh ROOT process. Do not let a dictionary
// loaded by another case hide a missing selection in the requested library.
if (TClassTable::GetDictNorm(className)) {
Error("assertIncludeDictionary", "Dictionary for %s was already registered", className);
return 1;
}
if (gSystem->Load(library) < 0) {
Error("assertIncludeDictionary", "Could not load %s", library);
return 2;
}

// Look up the compiled registration directly, without interpreter fallback,
// header autoparsing or autoloading a different dictionary library.
auto dictionary = TClassTable::GetDictNorm(className);
if (!dictionary) {
Error("assertIncludeDictionary", "%s did not register a dictionary for %s", library, className);
return 3;
}
auto cl = dictionary();
if (!cl || !cl->HasDictionary() || std::strcmp(cl->GetName(), className) != 0) {
Error("assertIncludeDictionary", "Invalid compiled dictionary for %s from %s", className, library);
return 4;
}
return 0;
}
1 change: 1 addition & 0 deletions roottest/root/meta/rootcling/includeDirectory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "LinkDefDirectory/Wrapper.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "LinkDefDirectory/Wrapper.h"

#ifdef __ROOTCLING__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class RootclingDirectory::DirectPayload + ;
#endif
6 changes: 6 additions & 0 deletions roottest/root/meta/rootcling/includeDirectoryLinkDef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifdef __ROOTCLING__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class RootclingDirectory::Payload + ;
#endif
1 change: 1 addition & 0 deletions roottest/root/meta/rootcling/includeNested.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "NestedSelection/Payload.h"