tf_fuzz: refactor includes to only include what is needed
* Refactor Makefile to automatically gather prerequisites.
* Change the includes (using include-what-you-need) so that files only
include the specific headers they need. Many includes are also now
inside the .hpp files instead of the .cpp files.
This improves editor support: previously, external symbols in .hpp
files would not be resolved by clangd due to .hpp files not having any
imports.
Change-Id: Iece03f81c35aa43ac026aaeb49b87d2c4acf07cd
Signed-off-by: Nik Dewally <Nik.Dewally@arm.com>
diff --git a/tf_fuzz/tfz-cpp/template/crypto_template_line.cpp b/tf_fuzz/tfz-cpp/template/crypto_template_line.cpp
index 3cf8a35..c0801c9 100644
--- a/tf_fuzz/tfz-cpp/template/crypto_template_line.cpp
+++ b/tf_fuzz/tfz-cpp/template/crypto_template_line.cpp
@@ -1,25 +1,16 @@
/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
-#include "class_forwards.hpp"
+#include <stdlib.h>
-#include "boilerplate.hpp"
#include "gibberish.hpp"
-#include "compute.hpp"
#include "data_blocks.hpp"
-#include "psa_asset.hpp"
-#include "find_or_create_asset.hpp"
#include "template_line.hpp"
#include "tf_fuzz.hpp"
-#include "crypto_asset.hpp"
-#include "psa_call.hpp"
-#include "crypto_call.hpp"
-#include "sst_asset.hpp"
-#include "crypto_asset.hpp"
#include "crypto_template_line.hpp"
diff --git a/tf_fuzz/tfz-cpp/template/crypto_template_line.hpp b/tf_fuzz/tfz-cpp/template/crypto_template_line.hpp
index 75be0fe..40218e5 100644
--- a/tf_fuzz/tfz-cpp/template/crypto_template_line.hpp
+++ b/tf_fuzz/tfz-cpp/template/crypto_template_line.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -9,17 +9,16 @@
#define CRYPTO_TEMPLATE_LINE_HPP
#include <cstdint>
+#include <string>
+#include <iosfwd>
-/* This project's header files #including other project headers quickly becomes
- unrealistically complicated. The only solution is for each .cpp to include
- the headers it needs.
-#include "psa_asset.hpp"
-//class psa_asset; // just need a forward reference
+#include "crypto_call.hpp"
+#include "data_blocks.hpp"
+#include "find_or_create_asset.hpp"
#include "template_line.hpp"
-#include "psa_call.hpp"
-*/
-using namespace std;
+#include "tf_fuzz.hpp"
+using namespace std;
class set_policy_template_line : public policy_template_line
{
diff --git a/tf_fuzz/tfz-cpp/template/secure_template_line.cpp b/tf_fuzz/tfz-cpp/template/secure_template_line.cpp
index 73fbde3..e8a255e 100644
--- a/tf_fuzz/tfz-cpp/template/secure_template_line.cpp
+++ b/tf_fuzz/tfz-cpp/template/secure_template_line.cpp
@@ -1,28 +1,18 @@
/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
-#include "class_forwards.hpp"
+#include <string>
+#include <vector>
-#include "boilerplate.hpp"
-#include "gibberish.hpp"
-#include "compute.hpp"
#include "data_blocks.hpp"
-#include "psa_asset.hpp"
#include "find_or_create_asset.hpp"
#include "template_line.hpp"
-#include "tf_fuzz.hpp"
-#include "crypto_asset.hpp"
#include "psa_call.hpp"
-#include "security_call.hpp"
#include "secure_template_line.hpp"
-#include "sst_call.hpp"
-#include "sst_template_line.hpp"
-#include "sst_asset.hpp"
-#include "crypto_asset.hpp"
@@ -70,4 +60,3 @@
/**********************************************************************************
End of methods of class security_hash_template_line.
**********************************************************************************/
-
diff --git a/tf_fuzz/tfz-cpp/template/secure_template_line.hpp b/tf_fuzz/tfz-cpp/template/secure_template_line.hpp
index 7f53c70..25afff3 100644
--- a/tf_fuzz/tfz-cpp/template/secure_template_line.hpp
+++ b/tf_fuzz/tfz-cpp/template/secure_template_line.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -13,18 +13,12 @@
#ifndef SECURE_TEMPLATE_LINE_HPP
#define SECURE_TEMPLATE_LINE_HPP
-#include <iostream>
-#include <string>
-#include <vector>
-#include <iterator>
-#include <algorithm>
-#include <new>
+#include "data_blocks.hpp"
+#include "security_call.hpp"
+#include "template_line.hpp"
+#include "tf_fuzz.hpp"
-/* This project's header files #including other project headers quickly becomes
- unrealistically complicated. The only solution is for each .cpp to include
- the headers it needs.
-*/
-
+class psa_call;
using namespace std;
@@ -57,4 +51,3 @@
};
#endif // #ifndef SECURE_TEMPLATE_LINE_HPP
-
diff --git a/tf_fuzz/tfz-cpp/template/sst_template_line.cpp b/tf_fuzz/tfz-cpp/template/sst_template_line.cpp
index 829071a..e50336d 100644
--- a/tf_fuzz/tfz-cpp/template/sst_template_line.cpp
+++ b/tf_fuzz/tfz-cpp/template/sst_template_line.cpp
@@ -1,25 +1,17 @@
/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
-#include "class_forwards.hpp"
+#include <cstdlib>
-#include "boilerplate.hpp"
#include "gibberish.hpp"
-#include "compute.hpp"
#include "data_blocks.hpp"
-#include "psa_asset.hpp"
-#include "find_or_create_asset.hpp"
#include "template_line.hpp"
#include "tf_fuzz.hpp"
-#include "crypto_asset.hpp"
-#include "psa_call.hpp"
-#include "sst_call.hpp"
#include "sst_template_line.hpp"
-#include "sst_asset.hpp"
/**********************************************************************************
@@ -107,4 +99,3 @@
/**********************************************************************************
End of methods of class remove_sst_template_line.
**********************************************************************************/
-
diff --git a/tf_fuzz/tfz-cpp/template/sst_template_line.hpp b/tf_fuzz/tfz-cpp/template/sst_template_line.hpp
index bec927c..19a4a96 100644
--- a/tf_fuzz/tfz-cpp/template/sst_template_line.hpp
+++ b/tf_fuzz/tfz-cpp/template/sst_template_line.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -9,15 +9,12 @@
#define SST_TEMPLATE_LINE_HPP
#include <cstdlib> // for rand()
+#include <string>
-/* This project's header files #including other project headers quickly becomes
- unrealistically complicated. The only solution is for each .cpp to include
- the headers it needs.
-#include "psa_asset.hpp"
+#include "data_blocks.hpp"
+#include "sst_call.hpp"
#include "template_line.hpp"
-#include "psa_call.hpp"
-*/
-
+#include "tf_fuzz.hpp"
using namespace std;
diff --git a/tf_fuzz/tfz-cpp/template/template_line.cpp b/tf_fuzz/tfz-cpp/template/template_line.cpp
index a8625b1..d5f3df3 100644
--- a/tf_fuzz/tfz-cpp/template/template_line.cpp
+++ b/tf_fuzz/tfz-cpp/template/template_line.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -12,24 +12,13 @@
commands are therefore tracked in separate objects, but referenced here. */
#include <vector>
-#include <algorithm> // for STL find()
-
-#include "class_forwards.hpp"
#include "data_blocks.hpp"
-#include "boilerplate.hpp"
-#include "randomization.hpp"
-#include "gibberish.hpp"
-#include "compute.hpp"
-#include "psa_asset.hpp"
#include "find_or_create_asset.hpp"
#include "template_line.hpp"
-#include "tf_fuzz.hpp"
-#include "crypto_asset.hpp"
#include "psa_call.hpp"
-#include "crypto_call.hpp"
-#include "sst_asset.hpp"
-#include "crypto_asset.hpp"
+
+class tf_fuzz_info;
@@ -275,4 +264,3 @@
/**********************************************************************************
End of methods of class security_template_line.
**********************************************************************************/
-
diff --git a/tf_fuzz/tfz-cpp/template/template_line.hpp b/tf_fuzz/tfz-cpp/template/template_line.hpp
index 143232d..dfdf111 100644
--- a/tf_fuzz/tfz-cpp/template/template_line.hpp
+++ b/tf_fuzz/tfz-cpp/template/template_line.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -14,18 +14,14 @@
#ifndef TEMPLATE_LINE_HPP
#define TEMPLATE_LINE_HPP
-#include <iostream>
+#include <stdint.h>
#include <string>
-#include <vector>
-#include <iterator>
-#include <algorithm>
-#include <new>
-/* This project's header files #including other project headers quickly becomes
- unrealistically complicated. The only solution is for each .cpp to include
- the headers it needs.
-*/
+#include "data_blocks.hpp"
+#include "find_or_create_asset.hpp"
+class psa_call;
+class tf_fuzz_info;
using namespace std;