Skip to content

Commit

Permalink
Use Abseil system includes (#4511)
Browse files Browse the repository at this point in the history
* Use system include style for Abseil includes.

* Add include directory.

* Use a patch.

* Clarifying comments.
  • Loading branch information
fruffy authored Mar 18, 2024
1 parent 0f002e6 commit ad7772e
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 17 deletions.
3 changes: 2 additions & 1 deletion backends/p4tools/modules/testgen/test/small-step/util.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "util.h"

#include <absl/strings/substitute.h>

#include <string>

#include "absl/strings/substitute.h"
#include "test/gtest/helpers.h"

#include "backends/p4tools/modules/testgen/test/gtest_utils.h"
Expand Down
15 changes: 15 additions & 0 deletions bazel/abseil.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel
index 0eb735da..5dd4aa67 100644
--- a/absl/base/BUILD.bazel
+++ b/absl/base/BUILD.bazel
@@ -137,6 +137,10 @@ cc_library(
"policy_checks.h",
],
copts = ABSL_DEFAULT_COPTS,
+ # This library is the root of the absl dependency tree.
+ # If we add this `includes` path here, then all absl headers
+ # can be included via angle brackets in external projects.
+ includes = ["../.."],
linkopts = ABSL_DEFAULT_LINKOPTS,
)

6 changes: 6 additions & 0 deletions bazel/p4c_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ filegroup(
name = "com_google_absl",
url = "https://github.com/abseil/abseil-cpp/releases/download/20240116.1/abseil-cpp-20240116.1.tar.gz",
strip_prefix = "abseil-cpp-20240116.1",
# We patch Abseil to support bracketed system includes.
# Patch is sourced from https://github.com/abseil/abseil-cpp/pull/1637.
# Discussion around Abseil's lack of support for bracketed system includes:
# https://github.com/abseil/abseil-cpp/issues/740
patches = ["@com_github_p4lang_p4c//:bazel/abseil.patch"],
patch_args = ["-p1"],
sha256 = "3c743204df78366ad2eaf236d6631d83f6bc928d1705dd0000b872e53b73dc6a",
)
if not native.existing_rule("com_google_protobuf"):
Expand Down
3 changes: 2 additions & 1 deletion control-plane/p4RuntimeSymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ limitations under the License.
*/
#include "p4RuntimeSymbolTable.h"

#include "absl/strings/str_split.h"
#include <absl/strings/str_split.h>

#include "lib/cstring.h"
#include "lib/iterator_range.h"
#include "p4RuntimeArchHandler.h"
Expand Down
5 changes: 3 additions & 2 deletions frontends/common/resolveReferences/referenceMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the License.
#ifndef COMMON_RESOLVEREFERENCES_REFERENCEMAP_H_
#define COMMON_RESOLVEREFERENCES_REFERENCEMAP_H_

#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include <absl/container/flat_hash_map.h>
#include <absl/container/flat_hash_set.h>

#include "frontends/common/programMap.h"
#include "ir/ir.h"
#include "ir/visitor.h"
Expand Down
3 changes: 2 additions & 1 deletion frontends/common/resolveReferences/resolveReferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ limitations under the License.
#ifndef COMMON_RESOLVEREFERENCES_RESOLVEREFERENCES_H_
#define COMMON_RESOLVEREFERENCES_RESOLVEREFERENCES_H_

#include "absl/container/flat_hash_map.h"
#include <absl/container/flat_hash_map.h>

#include "ir/ir.h"
#include "lib/cstring.h"
#include "lib/iterator_range.h"
Expand Down
5 changes: 3 additions & 2 deletions frontends/p4/def_use.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the License.
#ifndef FRONTENDS_P4_DEF_USE_H_
#define FRONTENDS_P4_DEF_USE_H_

#include "absl/container/flat_hash_set.h"
#include "absl/container/inlined_vector.h"
#include <absl/container/flat_hash_set.h>
#include <absl/container/inlined_vector.h>

#include "frontends/common/resolveReferences/referenceMap.h"
#include "ir/ir.h"
#include "lib/alloc_trace.h"
Expand Down
3 changes: 2 additions & 1 deletion frontends/p4/simplifyDefUse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ limitations under the License.

#include "simplifyDefUse.h"

#include "absl/container/flat_hash_set.h"
#include <absl/container/flat_hash_set.h>

#include "frontends/p4/def_use.h"
#include "frontends/p4/methodInstance.h"
#include "frontends/p4/parserCallGraph.h"
Expand Down
7 changes: 4 additions & 3 deletions frontends/p4/typeChecking/typeConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ limitations under the License.

#include "typeConstraints.h"

#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "absl/strings/str_split.h"
#include <absl/strings/str_cat.h>
#include <absl/strings/str_join.h>
#include <absl/strings/str_split.h>

#include "typeUnification.h"

namespace P4 {
Expand Down
5 changes: 3 additions & 2 deletions frontends/p4/typeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the License.
#ifndef FRONTENDS_P4_TYPEMAP_H_
#define FRONTENDS_P4_TYPEMAP_H_

#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include <absl/container/flat_hash_map.h>
#include <absl/container/flat_hash_set.h>

#include "frontends/common/programMap.h"
#include "frontends/p4/typeChecking/typeSubstitution.h"

Expand Down
3 changes: 2 additions & 1 deletion ir/visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ limitations under the License.
#include <stdlib.h>
#include <time.h>

#include "absl/container/flat_hash_map.h"
#include <absl/container/flat_hash_map.h>

#include "ir/ir-generated.h"
#include "lib/hash.h"

Expand Down
2 changes: 1 addition & 1 deletion test/gtest/complex_bitwise.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <absl/strings/substitute.h>
#include <gtest/gtest.h>

#include <optional>

#include "absl/strings/substitute.h"
#include "frontends/common/parseInput.h"
#include "frontends/common/resolveReferences/referenceMap.h"
#include "frontends/p4/toP4/toP4.h"
Expand Down
2 changes: 1 addition & 1 deletion test/gtest/diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include <absl/strings/substitute.h>
#include <gtest/gtest.h>

#include <optional>

#include "absl/strings/substitute.h"
#include "frontends/common/applyOptionsPragmas.h"
#include "test/gtest/helpers.h"

Expand Down
2 changes: 1 addition & 1 deletion test/gtest/p4runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <absl/strings/substitute.h>
#include <google/protobuf/util/message_differencer.h>
#include <gtest/gtest.h>

Expand All @@ -24,7 +25,6 @@ limitations under the License.
#include <string>
#include <vector>

#include "absl/strings/substitute.h"
#include "control-plane/p4/config/v1/p4types.pb.h"
#include "control-plane/p4/v1/p4runtime.pb.h"
#include "p4/config/v1/p4info.pb.h"
Expand Down

0 comments on commit ad7772e

Please sign in to comment.