TFLite: TfLiteCameraDemo bazel file

bazel file组成元素

workspace: 路径下包含文件WORKSPACE(可以是空文件,但必须有)
package:路径下包含文件BUILD
target:BUILD文件中的某个ruler

BUILD file

load("@build_bazel_rules_android//android:rules.bzl", "android_binary")

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

licenses(["notice"])  # Apache 2.0

android_binary(
    name = "TfLiteCameraDemo",
    srcs = glob(["java/**/*.java"]),
    aapt_version = "aapt",
    assets = [
        "//tensorflow/contrib/lite/java/demo/app/src/main/assets:labels_mobilenet_quant_v1_224.txt",
        "@tflite_mobilenet//:mobilenet_quant_v1_224.tflite",
    ],
    assets_dir = "",
    custom_package = "com.example.android.tflitecamerademo",
    manifest = "AndroidManifest.xml",
    nocompress_extensions = [
        ".tflite",
    ],
    resource_files = glob(["res/**"]),
    # In some platforms we don't have an Android SDK/NDK and this target
    # can't be built. We need to prevent the build system from trying to
    # use the target in that case.
    tags = ["manual"],
    deps = [
        "//tensorflow/contrib/lite/java:tensorflowlite",
        "//tensorflow/contrib/lite/java/src/testhelper/java/org/tensorflow/lite:testhelper",
        "@androidsdk//com.android.support:support-v13-25.2.0",
        "@androidsdk//com.android.support:support-v4-25.2.0",
    ],
)

分析第一句 load("@build_bazel_rules_android//android:rules.bzl", "android_binary")

load是一个扩展bazel功能的函数
build_bazel_rules_android是一个ruler的name,表示从某个 URL 下载到的文件,android是包含文件rules.bzl的文件夹
android_binary和该BULD文件的android_binary对应

build_bazel_rules_android定义在文件中tensorflow/tensorflow/workspace.bzl文件中
    tf_http_archive(     
        name   = "build_bazel_rules_android", 
                                                                                                                                                                       
        sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",     
        strip_prefix = "rules_android-0.1.1",     
        urls = [     
            "https://mirror.bazel.build/github.com/bazelbuild/rules_android/archive/v0.1.1.zip",     
            "https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip",     
        ],     
    )

    tf_http_archive(
        name = "tflite_mobilenet",
                                                                                                                                                                                 
        build_file = clean_dep("//third_party:tflite_mobilenet.BUILD"),
        sha256 = "23f814d1c076bdf03715dfb6cab3713aa4fbdf040fd5448c43196bd2e97a4c1b",
        urls = [
            "https://mirror.bazel.build/storage.googleapis.com/..models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip",
            "https://storage.googleapis.com/../models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip",
        ],
    )

另外androidsdk定义在文件:tensorflow/WORKSPACE
android_sdk_repository (     
    name = "androidsdk",     
    api_level = 23,     
    build_tools_version = "26.0.1",     
    path = "/home/mi/Android/Sdk/",     
)

glob函数


glob(include, exclude=[], exclude_directories=1)
Glob is a helper function that can be used anywhere a list of filenames is expected. 
    srcs = glob(["*.java"]) + [":gen_java_srcs"],

    data = glob(
        ["testdata/*.txt"],
        exclude = ["testdata/experimental.txt"],

    srcs = glob(
        ["**/*.java"],
        exclude = ["**/testing/**"],
    ),

android ruler


android_binary: Produces Android application package files (.apk).


    name:         required
    deps:         The list of other libraries to be linked in to the binary target.
    srcs:         The list of source files that are processed to create the target.
    aapt_version:     Select the version of aapt for this rule. aapt/aapt2/auto
    assets:     The list of assets to be packaged
    assets_dir:     The string giving the path to the files in assets.
    custom_package: Java package for which java sources will be generated.
    manifest:     The name of the Android manifest file, normally AndroidManifest.xml. 
    resource_files: The list of resources to be packaged.
    nocompress_extensions: A list of file extension to leave uncompressed in apk.

android_libray


This rule compiles and archives its sources into a .jar file. 
 

猜你喜欢

转载自blog.csdn.net/u011279649/article/details/83110549