From 1072234c86d13d5d1f9a3eb59e1127fa93c65aab Mon Sep 17 00:00:00 2001
From: Jeff Tung <100387939+jtung-apple@users.noreply.github.com>
Date: Thu, 26 Jan 2023 05:56:05 -0800
Subject: [PATCH] SimpleSubscriptionResumptionStorage should be made
 conditionally compiled in GN (#24653)

* SimpleSubscriptionResumptionStorage should be made conditionally compiled in GN

* Restyled fix
---
 src/app/BUILD.gn                                   | 11 +++++++++--
 src/app/SimpleSubscriptionResumptionStorage.cpp    |  5 -----
 src/app/SimpleSubscriptionResumptionStorage.h      |  5 -----
 src/app/tests/BUILD.gn                             |  5 ++++-
 .../TestSimpleSubscriptionResumptionStorage.cpp    | 14 --------------
 src/lib/core/CHIPConfig.h                          | 11 -----------
 src/platform/Darwin/CHIPPlatformConfig.h           |  3 ---
 src/platform/Linux/CHIPPlatformConfig.h            |  3 ---
 src/platform/cc13x2_26x2/CHIPPlatformConfig.h      |  2 --
 src/platform/device.gni                            |  8 ++++++++
 10 files changed, 21 insertions(+), 46 deletions(-)

diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn
index cef97a1328f93e..2067fd1acbdc26 100644
--- a/src/app/BUILD.gn
+++ b/src/app/BUILD.gn
@@ -14,6 +14,7 @@
 
 import("//build_overrides/chip.gni")
 import("//build_overrides/nlio.gni")
+import("${chip_root}/src/platform/device.gni")
 
 import("${chip_root}/build/chip/buildconfig_header.gni")
 import("common_flags.gni")
@@ -50,6 +51,7 @@ buildconfig_header("app_buildconfig") {
     "CHIP_CONFIG_IM_FORCE_FABRIC_QUOTA_CHECK=${chip_im_force_fabric_quota_check}",
     "CHIP_CONFIG_ENABLE_SESSION_RESUMPTION=${chip_enable_session_resumption}",
     "CHIP_CONFIG_ACCESS_CONTROL_POLICY_LOGGING_VERBOSITY=${chip_access_control_policy_logging_verbosity}",
+    "CHIP_CONFIG_PERSIST_SUBSCRIPTIONS=${chip_persist_subscriptions}",
   ]
 }
 
@@ -173,8 +175,6 @@ static_library("app") {
     "ReadHandler.cpp",
     "RequiredPrivilege.cpp",
     "RequiredPrivilege.h",
-    "SimpleSubscriptionResumptionStorage.cpp",
-    "SimpleSubscriptionResumptionStorage.h",
     "StatusResponse.cpp",
     "StatusResponse.h",
     "SubscriptionResumptionStorage.h",
@@ -189,6 +189,13 @@ static_library("app") {
     "reporting/reporting.h",
   ]
 
+  if (chip_persist_subscriptions) {
+    sources += [
+      "SimpleSubscriptionResumptionStorage.cpp",
+      "SimpleSubscriptionResumptionStorage.h",
+    ]
+  }
+
   public_deps = [
     ":app_config",
     "${chip_root}/src/access",
diff --git a/src/app/SimpleSubscriptionResumptionStorage.cpp b/src/app/SimpleSubscriptionResumptionStorage.cpp
index 1f51f751639522..f6f96978d5ba9d 100644
--- a/src/app/SimpleSubscriptionResumptionStorage.cpp
+++ b/src/app/SimpleSubscriptionResumptionStorage.cpp
@@ -23,9 +23,6 @@
 
 #include <app/SimpleSubscriptionResumptionStorage.h>
 
-// TODO: move the conditional compilation into BUILD.gn config options
-#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
-
 #include <lib/support/Base64.h>
 #include <lib/support/CodeUtils.h>
 #include <lib/support/SafeInt.h>
@@ -469,5 +466,3 @@ CHIP_ERROR SimpleSubscriptionResumptionStorage::DeleteAll(FabricIndex fabricInde
 
 } // namespace app
 } // namespace chip
-
-#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
diff --git a/src/app/SimpleSubscriptionResumptionStorage.h b/src/app/SimpleSubscriptionResumptionStorage.h
index 95efa2d032aac8..7cd6a0a98b49d8 100644
--- a/src/app/SimpleSubscriptionResumptionStorage.h
+++ b/src/app/SimpleSubscriptionResumptionStorage.h
@@ -25,9 +25,6 @@
 
 #include <app/SubscriptionResumptionStorage.h>
 
-// TODO: move the conditional compilation into BUILD.gn config options
-#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
-
 #include <lib/core/TLV.h>
 #include <lib/support/DefaultStorageKeyAllocator.h>
 #include <lib/support/Pool.h>
@@ -141,5 +138,3 @@ class SimpleSubscriptionResumptionStorage : public SubscriptionResumptionStorage
 };
 } // namespace app
 } // namespace chip
-
-#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
diff --git a/src/app/tests/BUILD.gn b/src/app/tests/BUILD.gn
index b2f023b3eb2db0..cc509b5ba7c952 100644
--- a/src/app/tests/BUILD.gn
+++ b/src/app/tests/BUILD.gn
@@ -105,7 +105,6 @@ chip_test_suite("tests") {
     "TestPendingNotificationMap.cpp",
     "TestReadInteraction.cpp",
     "TestReportingEngine.cpp",
-    "TestSimpleSubscriptionResumptionStorage.cpp",
     "TestStatusIB.cpp",
     "TestStatusResponseMessage.cpp",
     "TestTimedHandler.cpp",
@@ -147,4 +146,8 @@ chip_test_suite("tests") {
     test_sources += [ "TestCommissionManager.cpp" ]
     public_deps += [ "${chip_root}/src/app/server" ]
   }
+
+  if (chip_persist_subscriptions) {
+    test_sources += [ "TestSimpleSubscriptionResumptionStorage.cpp" ]
+  }
 }
diff --git a/src/app/tests/TestSimpleSubscriptionResumptionStorage.cpp b/src/app/tests/TestSimpleSubscriptionResumptionStorage.cpp
index 67b1f0757d7b14..5497fff30e2dd2 100644
--- a/src/app/tests/TestSimpleSubscriptionResumptionStorage.cpp
+++ b/src/app/tests/TestSimpleSubscriptionResumptionStorage.cpp
@@ -18,8 +18,6 @@
 #include <lib/support/UnitTestRegistration.h>
 #include <nlunit-test.h>
 
-#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
-
 #include <app/SimpleSubscriptionResumptionStorage.h>
 #include <lib/support/TestPersistentStorageDelegate.h>
 
@@ -468,15 +466,3 @@ int TestSimpleSubscriptionResumptionStorage()
 }
 
 CHIP_REGISTER_TEST_SUITE(TestSimpleSubscriptionResumptionStorage)
-
-#else // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
-
-/**
- *  Main
- */
-int TestSimpleSubscriptionResumptionStorage()
-{
-    return 0;
-}
-
-#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
diff --git a/src/lib/core/CHIPConfig.h b/src/lib/core/CHIPConfig.h
index 1d2a7f9f3508a3..c66d7f2974d5a6 100644
--- a/src/lib/core/CHIPConfig.h
+++ b/src/lib/core/CHIPConfig.h
@@ -1358,17 +1358,6 @@ extern const char CHIP_NON_PRODUCTION_MARKER[];
  * @}
  */
 
-/**
- *  @def CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
- *
- *  @brief
- *    Enable persistence and resumption of subscriptions on servers.
- *
- */
-#ifndef CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
-#define CHIP_CONFIG_PERSIST_SUBSCRIPTIONS 0
-#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
-
 /**
  * @def CHIP_CONFIG_MAX_SUBSCRIPTION_RESUMPTION_STORAGE_CONCURRENT_ITERATORS
  *
diff --git a/src/platform/Darwin/CHIPPlatformConfig.h b/src/platform/Darwin/CHIPPlatformConfig.h
index 892812acd89fd6..e3e1a99aebe5a1 100644
--- a/src/platform/Darwin/CHIPPlatformConfig.h
+++ b/src/platform/Darwin/CHIPPlatformConfig.h
@@ -62,6 +62,3 @@
 #ifndef CHIP_CONFIG_KVS_PATH
 #define CHIP_CONFIG_KVS_PATH "/tmp/chip_kvs"
 #endif // CHIP_CONFIG_KVS_PATH
-
-// Enable subscription persistence and resumption for CI
-#define CHIP_CONFIG_PERSIST_SUBSCRIPTIONS 1
diff --git a/src/platform/Linux/CHIPPlatformConfig.h b/src/platform/Linux/CHIPPlatformConfig.h
index 0e36ed76144cd2..788fe9b80c75d9 100644
--- a/src/platform/Linux/CHIPPlatformConfig.h
+++ b/src/platform/Linux/CHIPPlatformConfig.h
@@ -64,9 +64,6 @@ using CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE = const char *;
 #define CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS 1
 #endif // CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS
 
-// Enable subscription persistence and resumption for CI
-#define CHIP_CONFIG_PERSIST_SUBSCRIPTIONS 1
-
 // ==================== Security Configuration Overrides ====================
 
 #ifndef CHIP_CONFIG_KVS_PATH
diff --git a/src/platform/cc13x2_26x2/CHIPPlatformConfig.h b/src/platform/cc13x2_26x2/CHIPPlatformConfig.h
index b60ebd2db042e9..2a5981d4bbdea6 100644
--- a/src/platform/cc13x2_26x2/CHIPPlatformConfig.h
+++ b/src/platform/cc13x2_26x2/CHIPPlatformConfig.h
@@ -68,5 +68,3 @@
 #ifndef CHIP_CONFIG_MAX_FABRICS
 #define CHIP_CONFIG_MAX_FABRICS 5
 #endif
-
-#define CHIP_CONFIG_PERSIST_SUBSCRIPTIONS 0
diff --git a/src/platform/device.gni b/src/platform/device.gni
index bddd80e6e8f973..a17bf0b9c706b2 100755
--- a/src/platform/device.gni
+++ b/src/platform/device.gni
@@ -97,6 +97,14 @@ declare_args() {
   } else {
     chip_mdns = "none"
   }
+
+  # Enable Subscription persistence / resumption for CI and supported platforms
+  if (chip_device_platform == "darwin" || chip_device_platform == "linux" ||
+      chip_device_platform == "fake") {
+    chip_persist_subscriptions = true
+  } else {
+    chip_persist_subscriptions = false
+  }
 }
 
 if (chip_device_platform == "bl702" && chip_enable_openthread) {