Skip to content

Commit 32eebe5

Browse files
committed
[Fortran/gfortran] Refactor build system
Remove some redundant code from the regression and torture directories and consolidate most of the build system logic into gfortran/CMakeLists.txt. This simplifies the build scripts in the directories containing the actual tests. There is also some cleanup including more consistent capitalization of variable names and more inline comments describing some of the peculiarities of the approach. Differential Revision: https://reviews.llvm.org/D154373
1 parent 89d9d31 commit 32eebe5

File tree

21 files changed

+489
-381
lines changed

21 files changed

+489
-381
lines changed

Fortran/gfortran/CMakeLists.txt

Lines changed: 410 additions & 95 deletions
Large diffs are not rendered by default.

Fortran/gfortran/compile-save-diags.cmake

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88

99
# Run the compiler and save the compiler diagnostics to file. The diagnostics
1010
# are simply the messages printed to stdout and stderr. This is intended to be
11-
# used for the "compile" tests in this test. The "compile" tests exercise the
12-
# compiler's parser and semantic analyzer as well as the diagnostics.
11+
# used for the "compile" tests in this suite.
1312

1413
# Required parameters
1514
#
16-
# COMPILER: STRING Path to the compiler.
17-
# COMPILER_FLAGS: STRING Compiler flags.
18-
# INPUT_FILES: STRING Space separated list of files to compile.
19-
# OUTPUT_FILE: STRING The output diagnostics file.
20-
# OBJECT_FILE: STRING The object file produced by the compiler. This
21-
# will be deleted before this script exits.
15+
# CMD: STRING Most of the compilation command. This excludes
16+
# the module directory flag (-J).
17+
#
18+
# OUTPUT_FILE: STRING The output file containing any compiler
19+
# diagnostics.
2220
#
2321
# Optional parameters
2422
#
@@ -28,18 +26,30 @@
2826
# failed for any reason.
2927
#
3028

31-
execute_process(COMMAND ${COMPILER} ${COMPILER_FLAGS} ${INPUT_FILES} -o ${OBJECT_FILE}
29+
separate_arguments(COMMAND NATIVE_COMMAND "${CMD} -J${WORKING_DIRECTORY}")
30+
31+
# There are race conditions on .mod (due to different tests compiling modules
32+
# having the same name). At the time of writing, there don't seem to be any
33+
# multi-file "compile" tests, let alone any pairs of tests which might generate
34+
# object files having the same name. In case any do show up, set the working
35+
# directory to be the module directory. This ensures that any object files are
36+
# written to the dedicated working directory for the test.
37+
execute_process(COMMAND ${COMMAND}
38+
WORKING_DIRECTORY ${WORKING_DIRECTORY}
3239
RESULT_VARIABLE RETVAR
3340
OUTPUT_VARIABLE OUTVAR
3441
ERROR_VARIABLE ERRVAR
3542
OUTPUT_STRIP_TRAILING_WHITESPACE
3643
ERROR_STRIP_TRAILING_WHITESPACE)
3744

45+
# An output file will always be written because one is expected to exists at
46+
# test-time.
3847
file(WRITE "${OUTPUT_FILE}" "")
48+
49+
# Only save diagnostics if the compilation return a non-zero (error) code unless
50+
# instructed to always save diagnostics.
3951
if (ALWAYS_SAVE_DIAGS OR NOT "${RETVAR}" EQUAL "0")
4052
file(APPEND "${OUTPUT_FILE}" "${ERRVAR}")
4153
file(APPEND "${OUTPUT_FILE}" "")
4254
file(APPEND "${OUTPUT_FILE}" "${OUTVAR}")
4355
endif()
44-
45-
file(REMOVE ${OBJECT_FILE})

Fortran/gfortran/regression/CMakeLists.txt

Lines changed: 7 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,89 +6,16 @@
66
#
77
#===------------------------------------------------------------------------===#
88

9-
# Creates a test from each valid test file in the current source directory. Each
10-
# argument to a function is a list. If a test file is in any of the lists, a
11-
# test will not be created from it.
12-
function(add_tests UnsupportedTests UnimplementedTests SkippedTests FailingTests)
13-
# This will just get all the Fortran source files in the directory. Since
14-
# the tests here are a mix of single-source and multi-source tests, this will
15-
# include files that are dependencies of some "main" test file as well. Those
16-
# will be filtered out later.
17-
file(GLOB AllFiles CONFIGURE_DEPENDS LIST_DIRECTORIES false
18-
*.f*
19-
*.F*
20-
)
21-
22-
set(TestsToSkip)
23-
24-
# There is still a chance that some of the unsupported tests may need to be
25-
# enabled, for instance if the non-standard extensions that they exercise are
26-
# supported due to user demand.
27-
if (NOT TEST_SUITE_FORTRAN_FORCE_ALL_TESTS AND
28-
NOT TEST_SUITE_FORTRAN_FORCE_UNSUPPORTED_TESTS)
29-
list(APPEND TestsToSkip ${UnsupportedTests})
30-
endif()
31-
32-
# For the remaining tests, there is cause to build and run the skipped, failing
33-
# and unimplemented tests since some could be enabled once some feature is
34-
# implemented. Eventually, all the TEST_SUITE_FORTRAN_FORCE_* options (perhaps
35-
# with the exception of TEST_SUITE_FORTRAN_FORCE_UNSUPPORTED_TESTS) should
36-
# become redundant and removed.
37-
if (NOT TEST_SUITE_FORTRAN_FORCE_ALL_TESTS AND
38-
NOT TEST_SUITE_FORTRAN_FORCE_UNIMPLEMENTED_TESTS)
39-
list(APPEND TestsToSkip ${UnimplementedTests})
40-
endif()
41-
42-
if (NOT TEST_SUITE_FORTRAN_FORCE_ALL_TESTS AND
43-
NOT TEST_SUITE_FORTRAN_FORCE_FAILING_TESTS)
44-
list(APPEND TestsToSkip ${FailingTests})
45-
endif()
46-
47-
if (NOT TEST_SUITE_FORTRAN_FORCE_ALL_TESTS AND
48-
NOT TEST_SUITE_FORTRAN_FORCE_SKIPPED_TESTS)
49-
list(APPEND TestsToSkip ${SkippedTests})
50-
endif()
51-
52-
foreach(TestToSkip ${TestsToSkip})
53-
list(REMOVE_ITEM AllFiles ${TestToSkip})
54-
endforeach()
55-
56-
# For now, only the execute tests are supported. Those have a "{ dg-do run }"
57-
# or a "{ dg-lto-do run }" directive.
58-
foreach(File ${AllFiles})
59-
set(MAIN)
60-
set(ADDITIONAL_SOURCES)
61-
set(ADDITIONAL_FFLAGS)
62-
set(ADDITIONAL_LDFLAGS)
63-
64-
file(STRINGS ${File} FileLines)
65-
foreach(FileLine ${FileLines})
66-
if(FileLine MATCHES "^.*[{][ ]*dg-(lto-)?do[ ]*([A-Za-z0-9]+).*[}].*$")
67-
# If this is not a main file for an execute test, just move on to the
68-
# next file.
69-
if (NOT ${CMAKE_MATCH_2} MATCHES "run")
70-
break()
71-
else()
72-
set(MAIN "${File}")
73-
endif()
74-
elseif(FileLine MATCHES "dg-additional-sources[ ]*[\"]?(.+)[\"]?[ ]*[}]")
75-
separate_arguments(ADDITIONAL_SOURCES UNIX_COMMAND ${CMAKE_MATCH_1})
76-
list(TRANSFORM ADDITIONAL_SOURCES STRIP)
77-
endif()
78-
endforeach()
79-
80-
if (MAIN)
81-
gfortran_execute_test(${MAIN}
82-
PREFIX "gfortran-regression-execute"
83-
FFLAGS ${ADDITIONAL_FFLAGS}
84-
LDFLAGS ${ADDITIONAL_LDFLAGS}
85-
DEPFILES ${ADDITIONAL_SOURCES})
86-
endif()
87-
endforeach()
88-
endfunction()
9+
# PREFIX_EXECUTE and PREFIX_COMPILE are used in gfortran_add_execute_test and
10+
# gfortran_add_compile_test respectively.
11+
set(PREFIX_EXECUTE "gfortran-regression-execute")
12+
set(PREFIX_COMPILE "gfortran-regression-compile")
8913

9014
set(TESTS)
9115
gfortran_populate_tests(TESTS)
16+
gfortran_add_execute_tests_from("${TESTS}")
17+
# TODO: Enable the "compile" tests
18+
# gfortran_add_compile_tests_from("${TESTS}")
9219

9320
add_subdirectory(analyzer)
9421
add_subdirectory(asan)

Fortran/gfortran/regression/analyzer/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
set(TESTS)
1010
gfortran_populate_tests(TESTS)
11+
gfortran_add_execute_tests_from("${TESTS}")
12+
# TODO: Enable the "compile" tests.
13+
# gfortran_add_compile_tests_from("${TESTS}")

Fortran/gfortran/regression/asan/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
set(TESTS)
1010
gfortran_populate_tests(TESTS)
11+
gfortran_add_execute_tests_from("${TESTS}")
12+
# TODO: Enable the "compile" tests.
13+
# gfortran_add_compile_tests_from("${TESTS}")

Fortran/gfortran/regression/c-interop/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
set(TESTS)
1010
gfortran_populate_tests(TESTS)
11+
gfortran_add_execute_tests_from("${TESTS}")
12+
# TODO: Enable the "compile" tests.
13+
# gfortran_add_compile_tests_from("${TESTS}")

Fortran/gfortran/regression/coarray/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
set(TESTS)
1010
gfortran_populate_tests(TESTS)
11+
gfortran_add_execute_tests_from("${TESTS}")
12+
# TODO: Enable the "compile" tests.
13+
# gfortran_add_compile_tests_from("${TESTS}")

Fortran/gfortran/regression/debug/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
set(TESTS)
1010
gfortran_populate_tests(TESTS)
11+
gfortran_add_execute_tests_from("${TESTS}")
12+
# TODO: Enable the "compile" tests.
13+
# gfortran_add_compile_tests_from("${TESTS}")

Fortran/gfortran/regression/g77/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
set(TESTS)
1010
gfortran_populate_tests(TESTS)
11+
gfortran_add_execute_tests_from("${TESTS}")
12+
# TODO: Enable the "compile" tests.
13+
# gfortran_add_compile_tests_from("${TESTS}")

Fortran/gfortran/regression/goacc-gomp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88

99
set(TESTS)
1010
gfortran_populate_tests(TESTS)
11+
gfortran_add_execute_tests_from("${TESTS}")
12+
# TODO: Enable the "compile" tests.
13+
# gfortran_add_compile_tests_from("${TESTS}")

0 commit comments

Comments
 (0)