Skip to content

Commit 156b6b0

Browse files
committed
[flang/flang-rt] Add -isysroot flag only to tests really requiring
-isysroot flag was added to all tests, but it makes Driver/darwin-version.f90 failed. In fact, only a few tests need -isysroot flag. So, -isysroot flag is now eliminated from the substitution `%flang`, and a new substitution `%isysroot` has been introduced. Moreover, Integration/iso-fortran-binding.cpp invokes clang++ via a shell script, which makes it hard to add -isysroot flag. So, it is refactored.
1 parent 7f0e407 commit 156b6b0

File tree

7 files changed

+27
-29
lines changed

7 files changed

+27
-29
lines changed

flang-rt/test/Driver/ctofortran.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
! UNSUPPORTED: offload-cuda
33

44
! RUN: split-file %s %t
5-
! RUN: %clang -I"%include/flang" -c %t/cfile.c -o %t/cfile.o
6-
! RUN: %flang -L"%libdir" %t/ffile.f90 %t/cfile.o -o %t/ctofortran
5+
! RUN: %clang %isysroot -I"%include/flang" -c %t/cfile.c -o %t/cfile.o
6+
! RUN: %flang %isysroot -L"%libdir" %t/ffile.f90 %t/cfile.o -o %t/ctofortran
77
! RUN: env LD_LIBRARY_PATH="$LD_LIBRARY_PATH:%libdir" %t/ctofortran | FileCheck %s
88

99
!--- ffile.f90

flang-rt/test/Runtime/no-cpp-dep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ UNSUPPORTED: system-windows
77
UNSUPPORTED: offload-cuda
88
99
RUN: %if system-aix %{ export OBJECT_MODE=64 %}
10-
RUN: %cc -std=c99 %s -I%include -L"%libdir" -lflang_rt.runtime -lm \
10+
RUN: %cc -std=c99 %s %isysroot -I%include -L"%libdir" -lflang_rt.runtime -lm \
1111
RUN: %if system-aix %{-lpthread %}
1212
RUN: rm a.out
1313
*/

flang-rt/test/lit.cfg.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,24 @@ def shjoin(args, sep=" "):
6262
# lit writes a '.lit_test_times.txt' file into this directory.
6363
config.test_exec_root = config.flang_rt_binary_test_dir
6464

65-
# On MacOS, -isysroot is needed to build binaries.
65+
# On MacOS, some tests need -isysroot to build binaries.
6666
isysroot_flag = []
6767
if config.osx_sysroot:
6868
isysroot_flag = ["-isysroot", config.osx_sysroot]
69+
config.substitutions.append(("%isysroot", " ".join(isysroot_flag)))
6970

7071
tools = [
7172
ToolSubst(
7273
"%flang",
7374
command=config.flang,
74-
extra_args=isysroot_flag,
7575
unresolved="fatal",
7676
),
7777
ToolSubst(
7878
"%clang",
7979
command=FindTool("clang"),
80-
extra_args=isysroot_flag,
8180
unresolved="fatal",
8281
),
83-
ToolSubst("%cc", command=config.cc, extra_args=isysroot_flag, unresolved="fatal"),
82+
ToolSubst("%cc", command=config.cc, unresolved="fatal"),
8483
]
8584
llvm_config.add_tool_substitutions(tools)
8685

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
// REQUIRES: clang
12
// UNSUPPORTED: system-windows
2-
// RUN: split-file %s %t
3-
// RUN: chmod +x %t/runtest.sh
4-
// RUN: %t/runtest.sh %t %t/cppfile.cpp %flang | FileCheck %s
3+
// RUN: rm -rf %t && mkdir %t
4+
// RUN: %clangxx %isysroot -I %include/flang %s -o %t/a.out
5+
// RUN: %t/a.out | FileCheck %s
56

6-
//--- cppfile.cpp
77
extern "C" {
88
#include "ISO_Fortran_binding.h"
99
}
@@ -15,19 +15,3 @@ int main() {
1515
}
1616

1717
// CHECK: PASS
18-
// clang-format off
19-
//--- runtest.sh
20-
#!/bin/bash
21-
TMPDIR=$1
22-
CPPFILE=$2
23-
FLANG=$3
24-
BINDIR=`dirname $FLANG`
25-
CPPCOMP=$BINDIR/clang++
26-
if [ -x $CPPCOMP ]
27-
then
28-
$CPPCOMP $CPPFILE -o $TMPDIR/a.out
29-
$TMPDIR/a.out # should print "PASS"
30-
else
31-
# No clang compiler, just pass by default
32-
echo "PASS"
33-
fi

flang/test/Integration/lit.local.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from lit.llvm import llvm_config
2+
3+
llvm_config.use_clang(required=False)
4+
if llvm_config.config.clang:
5+
config.available_features.add("clang")
6+
clangxx = next((subst for subst in llvm_config.config.substitutions
7+
if "clangxx" in subst[0]), None)
8+
config.substitutions.append(clangxx)
9+
10+
# Include path for C headers that define Flang's Fortran ABI.
11+
config.substitutions.append(
12+
("%include", os.path.join(config.flang_source_dir, "include"))
13+
)

flang/test/lit.cfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@
118118
"PATH", config.flang_llvm_tools_dir, append_path=True
119119
)
120120

121-
# On MacOS, -isysroot is needed to build binaries.
121+
# On MacOS, some tests need -isysroot to build binaries.
122122
isysroot_flag = []
123123
if config.osx_sysroot:
124124
isysroot_flag = ["-isysroot", config.osx_sysroot]
125+
config.substitutions.append(("%isysroot", " ".join(isysroot_flag)))
125126

126127
# Check for DEFAULT_SYSROOT, because when it is set -isysroot has no effect.
127128
if config.default_sysroot:
@@ -133,7 +134,6 @@
133134
ToolSubst(
134135
"%flang",
135136
command=FindTool("flang"),
136-
extra_args=isysroot_flag,
137137
unresolved="fatal",
138138
),
139139
ToolSubst(

flang/test/lit.site.cfg.py.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import lit.util
66
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
77
config.llvm_shlib_dir = lit_config.substitute(path(r"@SHLIBDIR@"))
88
config.llvm_plugin_ext = "@LLVM_PLUGIN_EXT@"
9+
config.host_triple = "@LLVM_HOST_TRIPLE@"
910
config.target_triple = "@LLVM_TARGET_TRIPLE@"
1011
config.llvm_target_triple_env = "@LLVM_TARGET_TRIPLE_ENV@"
1112
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
1213
config.errc_messages = "@LLVM_LIT_ERRC_MESSAGES@"
14+
config.flang_source_dir = "@FLANG_SOURCE_DIR@"
1315
config.flang_obj_root = "@FLANG_BINARY_DIR@"
1416
config.flang_tools_dir = lit_config.substitute("@FLANG_TOOLS_DIR@")
1517
config.flang_intrinsic_modules_dir = "@FLANG_INTRINSIC_MODULES_DIR@"

0 commit comments

Comments
 (0)