Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up formatting checks #146

Merged
merged 23 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 116 additions & 116 deletions .github/cloudbuild/android.yaml
Original file line number Diff line number Diff line change
@@ -1,116 +1,116 @@
steps:
# We need this step to correctly identify dockerfile tag
- id: fetch-repo-history
name: gcr.io/cloud-builders/git
timeout: 10s
args:
- fetch
- --unshallow
# Download DOCKERFILE_COMMIT-buildkit tag if it exists to skip docker image generation,
# or download the :latest tag and use it as a cache,
# or skip downloading if :latest doesn't exist yet.
# This being a separate step helps readability in Cloud Build console.
- id: cache-old-image
name: gcr.io/cloud-builders/docker
timeout: 600s # 10 minutes
entrypoint: bash
args:
- -xc
- |
DOCKERFILE_COMMIT=$$(git log -n 1 --pretty=format:%H -- android/docker/mlperf_mobile/Dockerfile)
docker pull gcr.io/$PROJECT_ID/mlperf-mobile-android:$$DOCKERFILE_COMMIT-buildkit \
|| docker pull gcr.io/$PROJECT_ID/mlperf-mobile-android:latest \
|| true
# This step overrides the :latest tag of the image, so that we can use it in later steps.
- id: build-new-image
name: gcr.io/cloud-builders/docker
timeout: 1800s # 30 minutes
entrypoint: bash
env:
- DOCKER_BUILDKIT=1
args:
- -xc
- |
DOCKERFILE_COMMIT=$$(git log -n 1 --pretty=format:%H -- android/docker/mlperf_mobile/Dockerfile)
docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
-t gcr.io/$PROJECT_ID/mlperf-mobile-android:$$DOCKERFILE_COMMIT-buildkit \
-t gcr.io/$PROJECT_ID/mlperf-mobile-android:latest \
--cache-from gcr.io/$PROJECT_ID/mlperf-mobile-android:$$DOCKERFILE_COMMIT-buildkit \
--cache-from gcr.io/$PROJECT_ID/mlperf-mobile-android:latest \
android/docker/mlperf_mobile
# If the build fails artifacts are not uploaded automatically, so we save them manually before build
- id: push-new-image
name: gcr.io/cloud-builders/docker
timeout: 1800s # 30 minutes
entrypoint: bash
args:
- -xc
- |
DOCKERFILE_COMMIT=$$(git log -n 1 --pretty=format:%H -- android/docker/mlperf_mobile/Dockerfile)
docker push gcr.io/$PROJECT_ID/mlperf-mobile-android:$$DOCKERFILE_COMMIT-buildkit
docker push gcr.io/$PROJECT_ID/mlperf-mobile-android:latest
- id: build-apks
name: gcr.io/$PROJECT_ID/mlperf-mobile-android:latest
# Image upload usually takes only few seconds.
# However, if we generated a new image and the build failed,
# it can fail before the build finishes, canceling the upload.
# Let's wait for the upload to finish before starting the actual build.
waitFor: []
timeout: 10800s # 3 hours
entrypoint: bash
args:
- -xc
- |
bazel-3.7.2 build \
--remote_cache=https://storage.googleapis.com/$_BAZEL_CACHE_BUCKET \
--google_default_credentials \
-c opt \
--config android_arm64 \
//android/java/org/mlperf/inference:mlperf_app //android/androidTest:mlperf_test_app
# artifacts can not be uploaded from a symlinked directory, like bazel-bin
mkdir -p output/artifacts
cp bazel-bin/android/java/org/mlperf/inference/mlperf_app.apk output/artifacts
cp bazel-bin/android/androidTest/mlperf_test_app.apk output/artifacts
- id: instrument-test-on-firebase
name: gcr.io/cloud-builders/gcloud
timeout: 3600s # 1 hour
entrypoint: bash
args:
- -xc
- |
# redfin is Pixel 5e
gcloud firebase test android run \
--type instrumentation \
--app output/artifacts/mlperf_app.apk \
--test output/artifacts/mlperf_test_app.apk \
--timeout 45m \
--device model=redfin,version=30,locale=en,orientation=portrait
- id: crawler-test-on-firebase
name: gcr.io/cloud-builders/gcloud
waitFor:
- build-apks # don't wait for the other test to finish, run as soon as APKs are ready
timeout: 3600s # 1 hour (we sometimes wait 30+ minutes until the device we need is free)
entrypoint: bash
args:
- -xc
- |
# x1q is SM-G981U1 (Samsung Galaxy S20 5G)
gcloud firebase test android run \
--type robo \
--app output/artifacts/mlperf_app.apk \
--device model=x1q,version=29,locale=en,orientation=portrait \
--timeout 90s
# We uploaded both tags earlier, but this option also adds them to the artifacts page of the build
images:
- gcr.io/$PROJECT_ID/mlperf-mobile-android
artifacts:
objects:
location: gs://$_ARTIFACT_BUCKET/$_ARTIFACT_FOLDER/$COMMIT_SHA
paths:
- output/artifacts/mlperf_app.apk
- output/artifacts/mlperf_test_app.apk
timeout: 18000s # 5 hours
steps:
# We need this step to correctly identify dockerfile tag
- id: fetch-repo-history
name: gcr.io/cloud-builders/git
timeout: 10s
args:
- fetch
- --unshallow
# Download DOCKERFILE_COMMIT-buildkit tag if it exists to skip docker image generation,
# or download the :latest tag and use it as a cache,
# or skip downloading if :latest doesn't exist yet.
# This being a separate step helps readability in Cloud Build console.
- id: cache-old-image
name: gcr.io/cloud-builders/docker
timeout: 600s # 10 minutes
entrypoint: bash
args:
- -xc
- |
DOCKERFILE_COMMIT=$$(git log -n 1 --pretty=format:%H -- android/docker/mlperf_mobile/Dockerfile)
docker pull gcr.io/$PROJECT_ID/mlperf-mobile-android:$$DOCKERFILE_COMMIT-buildkit \
|| docker pull gcr.io/$PROJECT_ID/mlperf-mobile-android:latest \
|| true
# This step overrides the :latest tag of the image, so that we can use it in later steps.
- id: build-new-image
name: gcr.io/cloud-builders/docker
timeout: 1800s # 30 minutes
entrypoint: bash
env:
- DOCKER_BUILDKIT=1
args:
- -xc
- |
DOCKERFILE_COMMIT=$$(git log -n 1 --pretty=format:%H -- android/docker/mlperf_mobile/Dockerfile)
docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
-t gcr.io/$PROJECT_ID/mlperf-mobile-android:$$DOCKERFILE_COMMIT-buildkit \
-t gcr.io/$PROJECT_ID/mlperf-mobile-android:latest \
--cache-from gcr.io/$PROJECT_ID/mlperf-mobile-android:$$DOCKERFILE_COMMIT-buildkit \
--cache-from gcr.io/$PROJECT_ID/mlperf-mobile-android:latest \
android/docker/mlperf_mobile
# If the build fails artifacts are not uploaded automatically, so we save them manually before build
- id: push-new-image
name: gcr.io/cloud-builders/docker
timeout: 1800s # 30 minutes
entrypoint: bash
args:
- -xc
- |
DOCKERFILE_COMMIT=$$(git log -n 1 --pretty=format:%H -- android/docker/mlperf_mobile/Dockerfile)
docker push gcr.io/$PROJECT_ID/mlperf-mobile-android:$$DOCKERFILE_COMMIT-buildkit
docker push gcr.io/$PROJECT_ID/mlperf-mobile-android:latest
- id: build-apks
name: gcr.io/$PROJECT_ID/mlperf-mobile-android:latest
# Image upload usually takes only few seconds.
# However, if we generated a new image and the build failed,
# it can fail before the build finishes, canceling the upload.
# Let's wait for the upload to finish before starting the actual build.
waitFor: []
timeout: 10800s # 3 hours
entrypoint: bash
args:
- -xc
- |
bazel-3.7.2 build \
--remote_cache=https://storage.googleapis.com/$_BAZEL_CACHE_BUCKET \
--google_default_credentials \
-c opt \
--config android_arm64 \
//android/java/org/mlperf/inference:mlperf_app //android/androidTest:mlperf_test_app
# artifacts can not be uploaded from a symlinked directory, like bazel-bin
mkdir -p output/artifacts
cp bazel-bin/android/java/org/mlperf/inference/mlperf_app.apk output/artifacts
cp bazel-bin/android/androidTest/mlperf_test_app.apk output/artifacts
- id: instrument-test-on-firebase
name: gcr.io/cloud-builders/gcloud
timeout: 3600s # 1 hour
entrypoint: bash
args:
- -xc
- |
# redfin is Pixel 5e
gcloud firebase test android run \
--type instrumentation \
--app output/artifacts/mlperf_app.apk \
--test output/artifacts/mlperf_test_app.apk \
--timeout 45m \
--device model=redfin,version=30,locale=en,orientation=portrait
- id: crawler-test-on-firebase
name: gcr.io/cloud-builders/gcloud
waitFor:
- build-apks # don't wait for the other test to finish, run as soon as APKs are ready
timeout: 3600s # 1 hour (we sometimes wait 30+ minutes until the device we need is free)
entrypoint: bash
args:
- -xc
- |
# x1q is SM-G981U1 (Samsung Galaxy S20 5G)
gcloud firebase test android run \
--type robo \
--app output/artifacts/mlperf_app.apk \
--device model=x1q,version=29,locale=en,orientation=portrait \
--timeout 90s

# We uploaded both tags earlier, but this option also adds them to the artifacts page of the build
images:
- gcr.io/$PROJECT_ID/mlperf-mobile-android

artifacts:
objects:
location: gs://$_ARTIFACT_BUCKET/$_ARTIFACT_FOLDER/$COMMIT_SHA
paths:
- output/artifacts/mlperf_app.apk
- output/artifacts/mlperf_test_app.apk

timeout: 18000s # 5 hours
84 changes: 84 additions & 0 deletions .github/workflows/format-buildifier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Format & lint

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
bazel:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: ${{ github.workspace }}/src/github.com/${{ github.repository }}
- name: Setup Golang
uses: actions/setup-go@v1
with:
go-version: 1.16
- name: Set go env
run: echo GOPATH=$GITHUB_WORKSPACE >> $GITHUB_ENV
- name: Get buildifier
run: go get github.com/bazelbuild/buildtools/buildifier
- name: Run buildifier format check
run: $GOPATH/bin/buildifier -mode=check -r ${{ github.workspace }}/src/github.com/${{ github.repository }}
- name: Run buildifier linter
run: $GOPATH/bin/buildifier -lint=warn -r ${{ github.workspace }}/src/github.com/${{ github.repository }}
cpp:
name: C++
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check C++ format
uses: jidicula/[email protected]
with:
clang-format-version: 12
check-path: .
fallback-style: Google
dart:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Flutter
uses: subosito/flutter-action@v1
with:
channel: 'stable'
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: '3.x'
- name: Create ephemeral files
run: |
cd flutter &&
dart pub global activate protoc_plugin &&
export PATH="$PATH:$HOME/.pub-cache/bin" &&
make prepare-flutter &&
dart format lib/backend/backends_list.gen.dart lib/protos lib/localizations
- name: Run Dart format check
run: dart format --output=none --set-exit-if-changed flutter
- name: Run Dart linter
run: dart analyze --fatal-infos
java:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run Java format check
uses: axel-op/googlejavaformat-action@v3
with:
version: 1.9
args: --set-exit-if-changed --replace
misc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check prohibited extensions
run: make lint/prohibited-extensions
- name: Check large files
run: make lint/big-files
- name: Install dos2unix
run: sudo apt-get install dos2unix
- name: Check line endings
run: make lint/line-endings
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

all: app

include format.mk

# TFLite is the default backend
include mobile_back_tflite/tflite_backend.mk

Expand Down
28 changes: 14 additions & 14 deletions android/cpp/c/dll_export.def
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
EXPORTS
mlperf_backend_matches_hardware
mlperf_backend_create
mlperf_backend_vendor_name
mlperf_backend_name
mlperf_backend_delete
mlperf_backend_issue_query
mlperf_backend_flush_queries
mlperf_backend_get_input_count
mlperf_backend_get_input_type
mlperf_backend_set_input
mlperf_backend_get_output_count
mlperf_backend_get_output_type
mlperf_backend_get_output
EXPORTS
mlperf_backend_matches_hardware
mlperf_backend_create
mlperf_backend_vendor_name
mlperf_backend_name
mlperf_backend_delete
mlperf_backend_issue_query
mlperf_backend_flush_queries
mlperf_backend_get_input_count
mlperf_backend_get_input_type
mlperf_backend_set_input
mlperf_backend_get_output_count
mlperf_backend_get_output_type
mlperf_backend_get_output
2 changes: 1 addition & 1 deletion android/cpp/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
load("@org_tensorflow//tensorflow/lite:build_def.bzl", "tflite_copts", "tflite_linkopts")
load("@org_tensorflow//tensorflow/lite:build_def.bzl", "tflite_linkopts")

package(
default_visibility = ["//visibility:public"],
Expand Down
9 changes: 8 additions & 1 deletion android/cpp/proto/gen_binary_proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ def text_to_bin(name, src, out, proto_message, proto_deps):
)

def basename(filepath):
"""Return base filename without directory and extension."""
"""Return base filename without directory and extension.

Args:
filepath: path to take basename from

Returns:
Base filename without directory and extension.
"""
left = filepath.rfind("/") + 1
filename = filepath[left:]
right = filename.find(".")
Expand Down
1 change: 0 additions & 1 deletion android/java/org/mlperf/inference/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# ==============================================================================
load("@build_bazel_rules_android//android:rules.bzl", "android_binary", "android_library")
load("@org_tensorflow//tensorflow/lite:build_def.bzl", "tflite_jni_binary")
load("//android/cpp/proto:gen_binary_proto.bzl", "basename", "text_to_bin")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")

package(
Expand Down
Loading