From 524a5a10ae5ff1035e55ab2c9b3dc9e7d781167b Mon Sep 17 00:00:00 2001 From: "Aalyria Technologies, Inc" Date: Wed, 28 Jun 2023 16:54:00 -0700 Subject: [PATCH] Project import generated by Copybara. GitOrigin-RevId: 62a9a674282768931281feeca93be1c5346158d3 --- .github/workflows/main.yml | 10 +- .../v1alpha/resources/antenna_pattern.proto | 10 +- api/nbi/v1alpha/resources/network_link.proto | 6 + bazel/java_format_rules/BUILD | 18 +++ bazel/java_format_rules/def.bzl | 107 ++++++++++++++++++ bazel/java_format_rules/runner.bash.template | 79 +++++++++++++ .../aalyria/spacetime/authentication/BUILD | 7 ++ .../spacetime/codesamples/nbi/client/BUILD | 7 ++ .../aalyria/spacetime/authentication/BUILD | 7 ++ patches/BUILD | 14 +++ tools/gopackagesdriver.sh | 17 +++ 11 files changed, 279 insertions(+), 3 deletions(-) create mode 100644 bazel/java_format_rules/BUILD create mode 100644 bazel/java_format_rules/def.bzl create mode 100644 bazel/java_format_rules/runner.bash.template create mode 100755 tools/gopackagesdriver.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1773491..7958aac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +name: Bazel + on: [pull_request] jobs: @@ -19,9 +21,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Mount bazel cache - uses: actions/cache@v3 + - uses: actions/cache@v3 with: path: "~/.cache/bazel" key: bazel + path: | + ~/.cache/bazelisk + ~/.cache/bazel + key: bazel-${{ hashFiles('.bazelrc', '.bazelversion', 'WORKSPACE', 'requirements.txt') }} + restore-keys: bazel- - run: bazelisk build //... diff --git a/api/nbi/v1alpha/resources/antenna_pattern.proto b/api/nbi/v1alpha/resources/antenna_pattern.proto index dba153a..3c3fc76 100644 --- a/api/nbi/v1alpha/resources/antenna_pattern.proto +++ b/api/nbi/v1alpha/resources/antenna_pattern.proto @@ -24,7 +24,7 @@ option go_package = "aalyria.com/spacetime/api/nbi/v1alpha/resources"; // Models an antenna radiation pattern. Multiple platform definitions can // reference the same antenna pattern. message AntennaPattern { - reserved 8, 11 to max; + reserved 8, 12 to max; // A custom / user-defined antenna radiation pattern. message CustomAntennaPattern { @@ -117,6 +117,13 @@ message AntennaPattern { optional double near_field_range_m = 3; } + // Applies a different antenna radiation pattern for the transmitter + // and receiver. + message TransmitterAndReceiverAntennaPattern { + optional AntennaPattern transmitter_pattern = 1; + optional AntennaPattern receiver_pattern = 2; + } + oneof pattern_type { CustomAntennaPattern custom_pattern = 1; GaussianAntennaPattern gaussian_pattern = 2; @@ -127,5 +134,6 @@ message AntennaPattern { GaussianOpticalAntennaPattern gaussian_optical_pattern = 7; PhasedArrayAntennaPattern phased_array_pattern = 10; NearAndFarFieldAntennaPattern near_and_far_field_pattern = 9; + TransmitterAndReceiverAntennaPattern transmitter_and_receiver_pattern = 11; } } diff --git a/api/nbi/v1alpha/resources/network_link.proto b/api/nbi/v1alpha/resources/network_link.proto index 1087a6f..9b279ff 100644 --- a/api/nbi/v1alpha/resources/network_link.proto +++ b/api/nbi/v1alpha/resources/network_link.proto @@ -207,6 +207,12 @@ message WirelessLinkReport { // The modeled data rate capacity, in layer 2 bits per second. optional double data_rate_bps = 6; + + // The transmitter antenna's gain in the link direction, in dB. + optional double transmitter_antenna_gain_in_link_direction_db = 7; + + // The receiver antenna's gain in the link direction, in dB. + optional double receiver_antenna_gain_in_link_direction_db = 8; } repeated WirelessLinkMetrics sampled_metrics = 4; } diff --git a/bazel/java_format_rules/BUILD b/bazel/java_format_rules/BUILD new file mode 100644 index 0000000..69e1381 --- /dev/null +++ b/bazel/java_format_rules/BUILD @@ -0,0 +1,18 @@ +# Copyright 2023 Aalyria Technologies, Inc., and its affiliates. +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. + +exports_files([ + "def.bzl", + "runner.bash.template", +]) diff --git a/bazel/java_format_rules/def.bzl b/bazel/java_format_rules/def.bzl new file mode 100644 index 0000000..000e3c2 --- /dev/null +++ b/bazel/java_format_rules/def.bzl @@ -0,0 +1,107 @@ +# Copyright 2023 Aalyria Technologies, Inc., and its affiliates. +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. +"""Bazel rules for testing compliance with google-java-format.""" + +load("@bazel_skylib//lib:shell.bzl", "shell") + +def _java_format_test_impl(ctx): + out_file = ctx.actions.declare_file(ctx.label.name + ".bash") + runfiles = [ctx.executable.google_java_format] + substitutions = { + "@@GOOGLE_JAVA_FORMAT@@": shell.quote(ctx.executable.google_java_format.short_path), + "@@SRCS@@": "", + } + if ctx.file.workspace != None: + runfiles.append(ctx.file.workspace) + substitutions["@@WORKSPACE@@"] = ctx.file.workspace.path + else: + for f in ctx.files.srcs: + runfiles.append(f) + substitutions["@@SRCS@@"] = " ".join([shell.quote(f.short_path) for f in ctx.files.srcs]) + + ctx.actions.expand_template( + template = ctx.file._runner, + output = out_file, + substitutions = substitutions, + is_executable = True, + ) + + shell_runfiles = ctx.runfiles(files = runfiles) + merged_runfiles = shell_runfiles.merge(ctx.attr.google_java_format[DefaultInfo].default_runfiles) + + return DefaultInfo( + files = depset([out_file]), + runfiles = merged_runfiles, + executable = out_file, + ) + +java_format_test = rule( + implementation = _java_format_test_impl, + test = True, + attrs = { + "srcs": attr.label_list( + allow_files = [".java"], + doc = "A list of Java files to check for formatting", + ), + "google_java_format": attr.label( + default = "//third_party/java/google_java_format", + cfg = "exec", + executable = True, + ), + "workspace": attr.label( + allow_single_file = True, + doc = "Label of the WORKSPACE file", + ), + "_runner": attr.label( + default = ":runner.bash.template", + allow_single_file = True, + ), + }, +) + +# def _validation_aspect_impl(target, ctx): +# validation_output = ctx.actions.declare_file(ctx.rule.attr.name + ".validation") +# args = ctx.actions.args() +# args.add(validation_output) +# inputs = [] +# if hasattr(ctx.rule.attr, "srcs"): +# for s in ctx.rule.attr.srcs: +# for f in s.files.to_list(): +# if f.extension == "java" and not f.path.startswith("external"): +# inputs.append(f) +# args.add(f.path) + +# if +# if not inputs: +# ctx.actions.write(output = validation_output, content="") +# else: +# ctx.actions.run_shell( +# inputs = inputs, +# outputs = [validation_output], +# arguments = [args], +# tools = [ctx.executable._google_java_format], +# progress_message = "Checking %d files for formatting" % len(inputs), +# command = 'set -x; outfile="$1"; shift; "%s" -n --set-exit-if-changed "$@" > "$outfile"' % ctx.executable._google_java_format.path, +# ) + +# validation_outputs_in_deps = [] +# for d in ctx.rule.attr.deps: +# validation_outputs_in_deps.append(d[OutputGroupInfo]._validation) + +# return [ +# OutputGroupInfo( +# _validation = depset( +# [validation_output], +# transitive = validation_outputs_in_deps)), +# ] diff --git a/bazel/java_format_rules/runner.bash.template b/bazel/java_format_rules/runner.bash.template new file mode 100644 index 0000000..4c469be --- /dev/null +++ b/bazel/java_format_rules/runner.bash.template @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +# Copyright 2023 Aalyria Technologies, Inc., and its affiliates. +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. + +set -euo pipefail + +WORKSPACE="@@WORKSPACE@@" +SRCS=(@@SRCS@@) +GOOGLE_JAVA_FORMAT=@@GOOGLE_JAVA_FORMAT@@ +GOOGLE_JAVA_FORMAT="$(readlink "$GOOGLE_JAVA_FORMAT")" + +main() { + if [[ ${#SRCS[@]} -gt 0 ]] + then + check_srcs + else + check_repo + fi +} + +check_srcs() { + # the bulk of the time spent checking formatting is in the jvm startup time, + # but the full batch output is difficult to read and generate diffs off. To + # get a mix of speed and helpful error messages, we run the tool once against + # all the files with --dry-run set (which prints the list of files that are + # incorrectly formatted) then we loop over those if necessary to generate the + # human-friendly diffs + local unformatted_files=() + mapfile -t unformatted_files < <("$GOOGLE_JAVA_FORMAT" --dry-run "${SRCS[@]}") + + for src in "${unformatted_files[@]}"; + do + "$GOOGLE_JAVA_FORMAT" "$src" | diff -u3 "$src" - || true + done + + [[ "${#unformatted_files[@]}" -eq 0 ]] +} + +check_repo() { + # Use TEST_WORKSPACE to determine if the script is being ran under a test + if [[ ! -z "${TEST_WORKSPACE+x}" && -z "${BUILD_WORKSPACE_DIRECTORY+x}" ]]; then + FIND_FILE_TYPE="l" + # If WORKSPACE was provided, then the script is being run under a test in no_sandbox mode + # cd to the directory containing the WORKSPACE file + if [[ ! -z "${WORKSPACE+x}" ]]; then + FIND_FILE_TYPE="f" + WORKSPACE_PATH="$(dirname "$(realpath ${WORKSPACE})")" + if ! cd "$WORKSPACE_PATH" ; then + echo "Unable to change to workspace (WORKSPACE_PATH: ${WORKSPACE_PATH})" + fi + fi + else + # Change into the workspace directory if this is _not_ a test + if ! cd "$BUILD_WORKSPACE_DIRECTORY"; then + echo "Unable to change to workspace (BUILD_WORKSPACE_DIRECTORY: ${BUILD_WORKSPACE_DIRECTORY})" + exit 1 + fi + fi + + find . \ + -type "${FIND_FILE_TYPE:-f}" \ + \( -name '*.java' \ + \) -print0 | xargs -0 "$GOOGLE_JAVA_FORMAT" --set-exit-if-changed --dry-run + +} + +main "$@" diff --git a/java/com/aalyria/spacetime/authentication/BUILD b/java/com/aalyria/spacetime/authentication/BUILD index 26e75f4..654e268 100644 --- a/java/com/aalyria/spacetime/authentication/BUILD +++ b/java/com/aalyria/spacetime/authentication/BUILD @@ -12,8 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("//bazel/java_format_rules:def.bzl", "java_format_test") + package(default_visibility = ["//visibility:public"]) +java_format_test( + name = "java_format_test", + srcs = glob(["*.java"]), +) + java_library( name = "Authentication", srcs = [ diff --git a/java/com/aalyria/spacetime/codesamples/nbi/client/BUILD b/java/com/aalyria/spacetime/codesamples/nbi/client/BUILD index 6f3f426..23f4fcf 100644 --- a/java/com/aalyria/spacetime/codesamples/nbi/client/BUILD +++ b/java/com/aalyria/spacetime/codesamples/nbi/client/BUILD @@ -12,6 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("//bazel/java_format_rules:def.bzl", "java_format_test") + +java_format_test( + name = "java_format_test", + srcs = glob(["*.java"]), +) + java_binary( name = "ListEntities", srcs = [ diff --git a/javatests/com/aalyria/spacetime/authentication/BUILD b/javatests/com/aalyria/spacetime/authentication/BUILD index 4465f85..77edfda 100644 --- a/javatests/com/aalyria/spacetime/authentication/BUILD +++ b/javatests/com/aalyria/spacetime/authentication/BUILD @@ -12,6 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("//bazel/java_format_rules:def.bzl", "java_format_test") + +java_format_test( + name = "java_format_test", + srcs = glob(["*.java"]), +) + java_test( name = "SpacetimeCallCredentialsTest", srcs = [ diff --git a/patches/BUILD b/patches/BUILD index bb4827b..17ccb7c 100644 --- a/patches/BUILD +++ b/patches/BUILD @@ -1 +1,15 @@ +# Copyright 2023 Aalyria Technologies, Inc., and its affiliates. +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. + exports_files(["grpc.patch"]) diff --git a/tools/gopackagesdriver.sh b/tools/gopackagesdriver.sh new file mode 100755 index 0000000..d4d5d4b --- /dev/null +++ b/tools/gopackagesdriver.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# +# Copyright 2023 Aalyria Technologies, Inc., and its affiliates. +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. + +exec bazel run -- @io_bazel_rules_go//go/tools/gopackagesdriver "${@}"