From 1d043550c7601ca776b0318b9b913e5ecf325baf Mon Sep 17 00:00:00 2001
From: Tulio Magno Quites Machado Filho <tuliom@redhat.com>
Date: Tue, 5 Sep 2023 10:35:37 -0300
Subject: [PATCH] Reuse the library directory

Prefer to get the path to the shared libraries from config.llvm_shlib_dir.
Fallback to the previous path only if config.llvm_shlib_dir is not
defined.

This ensures the test will pass regardless of the build configuration
used downstream.
---
 mlir/test/lit.cfg.py                 |  1 +
 mlir/test/python/execution_engine.py | 12 +++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/mlir/test/lit.cfg.py b/mlir/test/lit.cfg.py
--- a/mlir/test/lit.cfg.py	2024-08-05 10:40:33.000000000 +0200
+++ b/mlir/test/lit.cfg.py	2024-08-14 19:17:55.160470316 +0200
@@ -164,6 +164,7 @@
         ToolSubst("transform-opt-ch2", unresolved="ignore"),
         ToolSubst("transform-opt-ch3", unresolved="ignore"),
         ToolSubst("transform-opt-ch4", unresolved="ignore"),
+        ToolSubst("%llvm_shlib_dir", config.llvm_shlib_dir, unresolved="ignore"),
         ToolSubst("mlir-transform-opt", unresolved="ignore"),
         ToolSubst("%mlir_lib_dir", config.mlir_lib_dir, unresolved="ignore"),
         ToolSubst("%mlir_src_dir", config.mlir_src_root, unresolved="ignore"),
diff -ruN mlir-19.1.0-rc2.src.orig/test/python/execution_engine.py mlir-19.1.0-rc2.src/test/python/execution_engine.py
--- a/mlir/test/python/execution_engine.py	2024-08-05 10:40:33.000000000 +0200
+++ b/mlir/test/python/execution_engine.py	2024-08-14 19:17:20.822219824 +0200
@@ -1,4 +1,4 @@
-# RUN: %PYTHON %s 2>&1 | FileCheck %s
+# RUN: env LLVM_SHLIB_DIR=%llvm_shlib_dir %PYTHON %s 2>&1 | FileCheck %s
 # REQUIRES: host-supports-jit
 import gc, sys, os, tempfile
 from mlir.ir import *
@@ -6,6 +6,9 @@
 from mlir.execution_engine import *
 from mlir.runtime import *
 
+_DEFAULT_LIB_DIR = "../../../../lib"
+LIB_DIR = os.getenv("LLVM_SHLIB_DIR", _DEFAULT_LIB_DIR)
+
 
 # Log everything to stderr and flush so that we have a unified stream to match
 # errors/info emitted by MLIR to stderr.
@@ -613,6 +616,7 @@
             shared_libs = [
                 "../../../../bin/mlir_runner_utils.dll",
                 "../../../../bin/mlir_c_runner_utils.dll",
+
             ]
         elif sys.platform == "darwin":
             shared_libs = [
@@ -621,8 +625,9 @@
             ]
         else:
             shared_libs = [
-                "../../../../lib/libmlir_runner_utils.so",
-                "../../../../lib/libmlir_c_runner_utils.so",
+                LIB_DIR + "/libmlir_runner_utils.so",
+                LIB_DIR + "/libmlir_c_runner_utils.so",
+
             ]
 
         execution_engine = ExecutionEngine(
@@ -664,8 +669,8 @@
             ]
         else:
             shared_libs = [
-                "../../../../lib/libmlir_runner_utils.so",
-                "../../../../lib/libmlir_c_runner_utils.so",
+                LIB_DIR + "/libmlir_runner_utils.so",
+                LIB_DIR + "/libmlir_c_runner_utils.so",
             ]
 
         execution_engine = ExecutionEngine(
