From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <tarantool-patches-bounces@dev.tarantool.org>
Received: from [87.239.111.99] (localhost [127.0.0.1])
	by dev.tarantool.org (Postfix) with ESMTP id 2AD49E32066;
	Tue, 24 Sep 2024 13:31:43 +0300 (MSK)
DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2AD49E32066
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev;
	t=1727173903; bh=MmCx3lVYagQXgY0bgAhjheGxsS0MrmvHgYC0hVQ9KKM=;
	h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
	 From;
	b=tiRfhy75zuJWTZjnfY3h0Z8fEqV719SxM9I8yP9zUrfU2eubxYTWFEjo0AE+VEm+D
	 Ci92t3tEnJpXxf3Dy1ewF+2wfebxrFrLAUwWfRxQ3nsPx7nvan7rd85gw6GoOy/xtU
	 emJbnjmi6CbLP4ugIJMJkYDBbCCO5tWIMiCet5cc=
Received: from smtp48.i.mail.ru (smtp48.i.mail.ru [95.163.41.86])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by dev.tarantool.org (Postfix) with ESMTPS id A038FE32052
 for <tarantool-patches@dev.tarantool.org>;
 Tue, 24 Sep 2024 13:30:13 +0300 (MSK)
DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A038FE32052
Received: by smtp48.i.mail.ru with esmtpa (envelope-from
 <skaplun@tarantool.org>)
 id 1st2o7-000000024Sz-3yEl; Tue, 24 Sep 2024 13:30:12 +0300
To: Maxim Kokryashkin <m.kokryashkin@tarantool.org>,
 Sergey Bronnikov <sergeyb@tarantool.org>
Date: Tue, 24 Sep 2024 13:29:48 +0300
Message-ID: <e4ec7aa1f1650237d492dc94a5f384ff59f8b4cc.1727172936.git.skaplun@tarantool.org>
X-Mailer: git-send-email 2.46.0
In-Reply-To: <cover.1727172936.git.skaplun@tarantool.org>
References: <cover.1727172936.git.skaplun@tarantool.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Mailru-Src: smtp
X-4EC0790: 10
X-7564579A: B8F34718100C35BD
X-77F55803: 4F1203BC0FB41BD968D81A599CAF0ABB6BA92BBABE0EB59B1196E825651383CB182A05F538085040DFAA80D3800F80A8F378A8CA21F699D64E25F607BB933F80136038D1A3840DCD87C9673BEE2CBA79
X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE753B96F70D0F8F35FEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063748789019239639CB8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D80FEBFDB6AA5B51C947D5332523126BA1E7EAAD6BB4E0E153CC7F00164DA146DAFE8445B8C89999728AA50765F7900637A679123E4CE3DB32389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC862B3BD3CC35DA588F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B53A69B3AC30C7B9475ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356
X-C1DE0DAB: 0D63561A33F958A53FBBA70D7C2FF3D15002B1117B3ED6960BD8B19BBA88F79ED57BAD45EC4C5DE1823CB91A9FED034534781492E4B8EEAD4ADCFBF7921B375DC79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41
X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF40031B29C4AA391637608582F30183BC5C344FA4EE83A5DFCFF4A36803BA5675698455FC0CD9C182A4322FFB9F042FEF8264A5050C275E51D27CCE5B6EF531728B5A3BD5144596BAC226CC413062362A913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203
X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojamSMdo1tbG/Zyl+qaQ2img==
X-DA7885C5: D5A9E0AAC6491051F255D290C0D534F969DDB3AF9D153BC49026BCB7CCAB62B578B41E58D69E9DB05B1A4C17EAA7BC4BEF2421ABFA55128DAF83EF9164C44C7E
X-Mailru-Sender: 689FA8AB762F7393C6D0B12EA33CAA9BAF653922D78CF07B598E7FB0904C86B37254EAB4B0581193E49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F
X-Mras: Ok
Subject: [Tarantool-patches] [PATCH v2 luajit 3/7] cmake: introduce
 AppendTestEnvVar macro
X-BeenThere: tarantool-patches@dev.tarantool.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: Tarantool development patches <tarantool-patches.dev.tarantool.org>
List-Unsubscribe: <https://lists.tarantool.org/mailman/options/tarantool-patches>, 
 <mailto:tarantool-patches-request@dev.tarantool.org?subject=unsubscribe>
List-Archive: <https://lists.tarantool.org/pipermail/tarantool-patches/>
List-Post: <mailto:tarantool-patches@dev.tarantool.org>
List-Help: <mailto:tarantool-patches-request@dev.tarantool.org?subject=help>
List-Subscribe: <https://lists.tarantool.org/mailman/listinfo/tarantool-patches>, 
 <mailto:tarantool-patches-request@dev.tarantool.org?subject=subscribe>
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
Reply-To: Sergey Kaplun <skaplun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Errors-To: tarantool-patches-bounces@dev.tarantool.org
Sender: "Tarantool-patches" <tarantool-patches-bounces@dev.tarantool.org>

It is useful to update the environment variable for some tests. For
CMake versions >= 3.22, we can use ENVIRONMENT_MODIFICATION [1] instead.
But unless we bump the CMake version, this macro is a workaround.

[1]: https://cmake.org/cmake/help/latest/prop_test/ENVIRONMENT_MODIFICATION.html

Part of tarantool/tarantool#9898
---
 test/tarantool-tests/CMakeLists.txt | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt
index 11a84496..ff402dc0 100644
--- a/test/tarantool-tests/CMakeLists.txt
+++ b/test/tarantool-tests/CMakeLists.txt
@@ -18,6 +18,34 @@ macro(BuildTestCLib lib sources)
   set(LD_LIBRARY_PATH "${CMAKE_CURRENT_BINARY_DIR}:${LD_LIBRARY_PATH}" PARENT_SCOPE)
 endmacro()
 
+# FIXME: This is used only due to ancient CMake requirements.
+# If we update to CMake >= 3.22, we can use
+# ENVIRONMENT_MODIFICATION [1] instead.
+# [1]: https://cmake.org/cmake/help/latest/prop_test/ENVIRONMENT_MODIFICATION.html
+# This macro appends to the given test's environment variable the
+# given value. If the variable doesn't exist, it is created equal
+# to the given argument.
+macro(AppendTestEnvVar testname var value)
+  get_test_property(${testname} ENVIRONMENT old_env)
+  foreach(loopvar ${old_env})
+    # XXX: `foreach()` unescapes ";" in string, escape them back.
+    string(REPLACE ";" "\;" loopvar "${loopvar}")
+    if("${loopvar}" MATCHES "^${var}=(.*)")
+      set(envvar_found TRUE)
+      set(loopvar "${var}=${value}${CMAKE_MATCH_1}")
+    endif()
+    list(APPEND new_env "${loopvar}")
+  endforeach()
+  if(NOT "${envvar_found}")
+    list(APPEND new_env "${var}=${value}")
+  endif()
+  set_tests_properties(${testname} PROPERTIES ENVIRONMENT "${new_env}")
+
+  unset(envvar_found)
+  unset(old_env)
+  unset(new_env)
+endmacro()
+
 add_subdirectory(ffi-ccall)
 add_subdirectory(fix-bit-shift-generation)
 add_subdirectory(gh-4427-ffi-sandwich)
-- 
2.46.0