Skip to content

Commit

Permalink
[P4_Symbolic] Update pins_infra_deps.bzl with some best practices, an…
Browse files Browse the repository at this point in the history
…d apply them. (#616)



Co-authored-by: smolkaj <[email protected]>
Co-authored-by: kishanps <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2024
1 parent 598401a commit c37489f
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 85 deletions.
32 changes: 23 additions & 9 deletions install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
#!/bin/bash
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Please read carefully before adding new dependencies:
#
# System dependencies are disallowed by default, and the bar for exceptions is
# high.
#
# pins-infra strives for a hermetic build, i.e. one that is insensitive to the
# libraries and other software installed on your machine, other than Bazel and
# the compilers. This ensure the build is reproducible and portable.
#
# Before adding a new system dependency, consider the following:
#
# http://www.apache.org/licenses/LICENSE-2.0
# 1. Please read the note on dependencies in pins_infra_deps.bzl.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 2. Can the dependency be avoided altogether? Consider that there is a
# non-trival cost to maintaining dependencies over time.
#
# 3. Can the dependency be built with Bazel instead?
# - For many libraries, there are existing Bazel BUILD files. Try a quick
# Google search.
# - If there is no existing BUILD file, can you write your own BUILD file?
# See the bazel/ folder for examples. Ideally, we strive to upstream such
# BUILD files so everyone can benefit and share the maintenance burden.
# - If it's too hard to write a native BUILD file, try writing a BUILD file
# using rules_foreign_cc (https://github.com/bazelbuild/rules_foreign_cc).
#. See the bazel/ folder for examples.

# Please read carefully before adding new dependencies:
#
Expand Down
19 changes: 3 additions & 16 deletions p4_symbolic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

# This file contains build rules for the main binary of p4_symbolic.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test", "diff_test")
load("//p4_pdpi:pdgen.bzl", "p4_pd_proto")
load("@com_github_p4lang_p4c//:bazel/p4_library.bzl", "p4_library")

package(
default_visibility = ["//visibility:public"],
licenses = ["notice"],
Expand All @@ -29,8 +24,6 @@ cc_binary(
srcs = [
"main.cc",
],
# linkopts = ["-lz3"],
visibility = ["//p4_symbolic/symbolic:__pkg__"],
deps = [
":parser",
"//gutil:status",
Expand All @@ -49,15 +42,10 @@ cc_binary(

cc_library(
name = "parser",
srcs = [
"parser.cc",
],
hdrs = [
"parser.h",
],
visibility = ["//visibility:public"],
srcs = ["parser.cc"],
hdrs = ["parser.h"],
deps = [
"//gutil:proto",
"//gutil:proto",
"//gutil:status",
"//p4_pdpi:ir_cc_proto",
"//p4_symbolic/bmv2",
Expand All @@ -74,7 +62,6 @@ cc_library(
name = "z3_util",
srcs = ["z3_util.cc"],
hdrs = ["z3_util.h"],
visibility = ["//visibility:public"],
deps = [
"//gutil:status",
"//p4_pdpi/string_encodings:hex_string",
Expand Down
7 changes: 0 additions & 7 deletions p4_symbolic/bmv2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test", "diff_test")
load("//p4_pdpi:pdgen.bzl", "p4_pd_proto")
load("@com_github_p4lang_p4c//:bazel/p4_library.bzl", "p4_library")
load("//p4_symbolic/bmv2:test.bzl", "bmv2_protobuf_parsing_test")

package(
Expand All @@ -25,7 +21,6 @@ package(

cc_proto_library(
name = "bmv2_cc_proto",
visibility = ["//p4_symbolic:__subpackages__"],
deps = [":bmv2_proto"],
)

Expand All @@ -34,7 +29,6 @@ proto_library(
srcs = [
"bmv2.proto",
],
visibility = ["//p4_symbolic:__subpackages__"],
deps = [
"@com_google_protobuf//:struct_proto",
],
Expand All @@ -48,7 +42,6 @@ cc_library(
hdrs = [
"bmv2.h",
],
visibility = ["//p4_symbolic:__subpackages__"],
deps = [
":bmv2_cc_proto",
"//gutil:status",
Expand Down
36 changes: 14 additions & 22 deletions p4_symbolic/ir/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test", "diff_test")
load("//p4_pdpi:pdgen.bzl", "p4_pd_proto")
load("@com_github_p4lang_p4c//:bazel/p4_library.bzl", "p4_library")
load("//p4_symbolic/ir:test.bzl", "ir_parsing_test")

package(
default_visibility = ["//visibility:public"],
licenses = ["notice"],
)

cc_proto_library(
name = "ir_cc_proto",
deps = [":ir_proto"],
)

proto_library(
name = "ir_proto",
srcs = ["ir.proto"],
deps = [
"//p4_pdpi:ir_proto",
"//p4_symbolic/bmv2:bmv2_proto",
],
)

cc_library(
name = "pdpi_driver",
srcs = [
Expand All @@ -31,7 +41,6 @@ cc_library(
hdrs = [
"pdpi_driver.h",
],
visibility = ["//p4_symbolic:__subpackages__"],
deps = [
"//gutil:proto",
"//gutil:status",
Expand All @@ -40,21 +49,6 @@ cc_library(
],
)

cc_proto_library(
name = "ir_cc_proto",
visibility = ["//p4_symbolic:__subpackages__"],
deps = [":ir_proto"],
)

proto_library(
name = "ir_proto",
srcs = ["ir.proto"],
deps = [
"//p4_pdpi:ir_proto",
"//p4_symbolic/bmv2:bmv2_proto",
],
)

cc_library(
name = "table_entries",
srcs = [
Expand All @@ -63,7 +57,6 @@ cc_library(
hdrs = [
"table_entries.h",
],
visibility = ["//p4_symbolic:__subpackages__"],
deps = [
":ir_cc_proto",
"//gutil:status",
Expand All @@ -85,7 +78,6 @@ cc_library(
hdrs = [
"ir.h",
],
visibility = ["//p4_symbolic:__subpackages__"],
deps = [
":ir_cc_proto",
":table_entries",
Expand Down
11 changes: 4 additions & 7 deletions p4_symbolic/sai/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test", "diff_test")
load("//p4_pdpi:pdgen.bzl", "p4_pd_proto")
load("@com_github_p4lang_p4c//:bazel/p4_library.bzl", "p4_library")

package(licenses = ["notice"])
package(
default_visibility = ["//visibility:public"],
licenses = ["notice"],
)

cc_library(
name = "fields",
Expand All @@ -36,7 +34,6 @@ cc_library(
name = "parser",
srcs = ["parser.cc"],
hdrs = ["parser.h"],
visibility = ["//p4_symbolic:__subpackages__"],
deps = [
":fields",
"//gutil:status",
Expand Down
5 changes: 0 additions & 5 deletions p4_symbolic/symbolic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test", "diff_test")
load("//p4_pdpi:pdgen.bzl", "p4_pd_proto")
load("@com_github_p4lang_p4c//:bazel/p4_library.bzl", "p4_library")
load("//p4_symbolic/symbolic:test.bzl", "end_to_end_test")

package(
Expand Down Expand Up @@ -49,7 +45,6 @@ cc_library(
"util.h",
"values.h",
],
visibility = ["//p4_symbolic:__subpackages__"],
deps = [
"//gutil:status",
"//p4_pdpi:ir_cc_proto",
Expand Down
6 changes: 0 additions & 6 deletions p4_symbolic/testdata/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test", "diff_test")
load("//p4_pdpi:pdgen.bzl", "p4_pd_proto")
load("@com_github_p4lang_p4c//:bazel/p4_library.bzl", "p4_library")

package(default_visibility = ["//visibility:public"])

# Make sure programs under p4-samples are visible to other
Expand All @@ -27,5 +22,4 @@ exports_files(
"**/*.txt",
]),
licenses = ["notice"],
visibility = ["//p4_symbolic:__subpackages__"],
)
5 changes: 0 additions & 5 deletions p4_symbolic/tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test", "diff_test")
load("//p4_pdpi:pdgen.bzl", "p4_pd_proto")
load("@com_github_p4lang_p4c//:bazel/p4_library.bzl", "p4_library")

package(
default_visibility = ["//visibility:public"],
licenses = ["notice"],
Expand Down
4 changes: 2 additions & 2 deletions p4_symbolic/tests/sai_p4_component_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using ::p4::config::v1::P4Info;
using ::testing::Eq;
using ::testing::Not;

constexpr absl::string_view kTableEntries = R"PB(
constexpr absl::string_view kTableEntries = R"pb(
entries {
acl_pre_ingress_table_entry {
match {
Expand Down Expand Up @@ -73,7 +73,7 @@ constexpr absl::string_view kTableEntries = R"PB(
action { set_dst_mac { dst_mac: "cc:bb:aa:99:88:77" } }
}
}
)PB";
)pb";

class P4SymbolicComponentTest : public testing::Test {
public:
Expand Down
6 changes: 0 additions & 6 deletions p4_symbolic/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test", "diff_test")
load("//p4_pdpi:pdgen.bzl", "p4_pd_proto")
load("@com_github_p4lang_p4c//:bazel/p4_library.bzl", "p4_library")

package(
default_visibility = ["//visibility:public"],
licenses = ["notice"],
Expand All @@ -33,7 +28,6 @@ cc_library(
# TODO: clean up.
# "status.h",
],
visibility = ["//p4_symbolic:__subpackages__"],
deps = [
"//gutil:status",
"@com_google_absl//absl/status",
Expand Down

0 comments on commit c37489f

Please sign in to comment.