Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
common-superbuild
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ParaView
common-superbuild
Merge requests
!615
SuperbuildPackageMacros: add a function to test loadable modules
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
SuperbuildPackageMacros: add a function to test loadable modules
ben.boeckel/common-superbuild:test-loadable-modules
into
master
Overview
2
Commits
5
Pipelines
13
Changes
1
Merged
Ben Boeckel
requested to merge
ben.boeckel/common-superbuild:test-loadable-modules
into
master
1 year ago
Overview
2
Commits
5
Pipelines
13
Changes
1
Expand
0
0
Merge request reports
Viewing commit
902df526
Show latest version
1 file
+
167
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
902df526
SuperbuildTestingMacros: add a function to test loadable modules
· 902df526
Ben Boeckel
authored
1 year ago
cmake/SuperbuildTestingMacros.cmake
+
167
−
0
Options
@@ -54,3 +54,170 @@ function (superbuild_add_extract_test name glob_prefix generator output)
endfunction
()
# TODO: Add support for extracting a specific CPack's output.
#[==[.md
Create a test which loads all modules within a directory as being standalone
loadable.
```
superbuild_add_extra_package_test(<package> <generator> <directory>
[EXCLUDES <exclude>...])
```
For a package named `<package>`, find all loadable libraries under
`<directory>` and make sure they are loadable.
If `EXCLUDES` are given, paths matching the exclusion are not tested.
#]==]
function
(
superbuild_test_loadable_modules package generator dir
)
cmake_parse_arguments
(
PARSE_ARGV 3 _test_loadable
""
""
"EXCLUDES"
)
if
(
_test_loadable_UNPARSED_ARGUMENTS
)
message
(
FATAL_ERROR
"Unparsed arguments to `superbuild_test_loadable_modules`: "
"
${
_test_loadable_UNPARSED_ARGUMENTS
}
"
)
endif
()
if
(
WIN32
)
return
()
endif
()
find_program
(
FILE_COMMAND
NAMES file
REQUIRED
)
add_test
(
NAME
"test-package-
${
package
}
-
${
generator
}
-ldd-resolutions"
COMMAND
"
${
CMAKE_COMMAND
}
"
"-Ddirectory=
${
dir
}
"
"-Dexcludes=
${
_test_loadable_EXCLUDES
}
"
"-Dfile_command=
${
FILE_COMMAND
}
"
-D_run_superbuild_test_loadable_modules=ON
-P
"
${
CMAKE_CURRENT_FUNCTION_LIST_FILE
}
"
)
set_tests_properties
(
"test-package-
${
package
}
-
${
generator
}
-ldd-resolutions"
PROPERTIES
DEPENDS
"extract-
${
package
}
-
${
generator
}
"
)
endfunction
()
if
(
_run_superbuild_test_loadable_modules
)
# Keep the full output on CDash for future inspection.
message
(
"CTEST_FULL_OUTPUT"
)
if
(
NOT file_command
)
message
(
FATAL_ERROR
"Missing `file` command to detect filetypes."
)
endif
()
function
(
_superbuild_test_file_type module type
)
execute_process
(
COMMAND
"
${
file_command
}
"
"
${
module
}
"
RESULT_VARIABLE res
OUTPUT_VARIABLE out
ERROR_VARIABLE err
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if
(
res
)
message
(
SEND_ERROR
"Failed to run `file` to detect type of '
${
module
}
':
${
err
}
"
)
return
()
endif
()
set
(
filetype
""
)
if
(
out MATCHES
": ELF"
)
set
(
filetype
"ELF"
)
elseif
(
out MATCHES
": Mach-O"
)
set
(
filetype
"Mach-O"
)
endif
()
if
(
filetype
)
set
(
"
${
type
}
"
"
${
filetype
}
"
PARENT_SCOPE
)
else
()
set
(
"
${
type
}
"
""
PARENT_SCOPE
)
endif
()
endfunction
()
function
(
_superbuild_test_loadable_module module format
)
if
(
format STREQUAL
"ELF"
)
set
(
command
"ldd"
)
set
(
ignore_regex
"^$"
)
set
(
missing_regex
" => not found$"
)
set
(
libname_regex
"^
\t
(.*) => not found$"
)
else
()
message
(
FATAL_ERROR
"Unrecognized binary format:
${
format
}
"
)
endif
()
execute_process
(
COMMAND
${
command
}
"
${
module
}
"
RESULT_VARIABLE res
OUTPUT_VARIABLE out
ERROR_VARIABLE err
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if
(
res
)
message
(
SEND_ERROR
"Failed to run `
${
command
}
` on '
${
module
}
':
${
err
}
"
)
endif
()
string
(
REPLACE
"
\n
"
";"
lines
"
${
out
}
"
)
foreach
(
line IN LISTS lines
)
if
(
line MATCHES
"
${
ignore_regex
}
"
)
continue
()
endif
()
if
(
line MATCHES
"
${
missing_regex
}
"
)
string
(
REGEX REPLACE
"
${
libname_regex
}
"
"
\\
1"
libname
"
${
line
}
"
)
message
(
SEND_ERROR
"'
${
module
}
' cannot find library
${
libname
}
"
)
endif
()
endforeach
()
endfunction
()
file
(
GLOB binaries
"
${
directory
}
/bin/*"
)
file
(
GLOB macos_binaries
"
${
directory
}
/MacOS/*"
)
file
(
GLOB_RECURSE so_libraries
"
${
directory
}
/*.so*"
)
file
(
GLOB_RECURSE dylib_libraries
"
${
directory
}
/*.dylib*"
)
set
(
expected_format
)
if
(
APPLE
)
set
(
expected_format
"Mach-O"
)
elseif
(
UNIX
)
set
(
expected_format
"ELF"
)
endif
()
if
(
NOT expected_format
)
message
(
FATAL_ERROR
"No expected format; nothing to test."
)
endif
()
foreach
(
module IN LISTS binaries macos_binaries so_libraries dylib_libraries
)
# Skip symlinks.
if
(
IS_SYMLINK
"
${
module
}
"
)
continue
()
endif
()
set
(
exclude 0
)
foreach
(
exclude IN LISTS excludes
)
if
(
module MATCHES exclude
)
set
(
exclude 1
)
break
()
endif
()
endforeach
()
if
(
exclude
)
continue
()
endif
()
# Skip files not in the expected format.
_superbuild_test_file_type
(
"
${
module
}
"
module_format
)
if
(
NOT module_format STREQUAL expected_format
)
continue
()
endif
()
message
(
STATUS
"Testing
${
module
}
"
)
_superbuild_test_loadable_module
(
"
${
module
}
"
"
${
module_format
}
"
)
endforeach
()
endif
()
Loading