Skip to content

Commit 99c25b4

Browse files
gcarranza-1copybara-github
authored andcommitted
Internal LiteRT change.
LiteRT-PiperOrigin-RevId: 826639488
1 parent 1b273b5 commit 99c25b4

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2025 Google LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
17+
source litert/integration_test/device_script_common.sh || exit 1
18+
19+
# TODO: Unify workdirs with other scripts.
20+
readonly work_dir="/tmp/litert_extras"
21+
rm -rf "${work_dir}"
22+
mkdir -p "${work_dir}"
23+
24+
readonly cns_path=@@cns_path@@
25+
26+
if [[ "$cns_path" == "@@"*"@@" ]]; then
27+
fatal "No cns_path templated into the script."
28+
elif [[ -z "${cns_path}" ]]; then
29+
fatal "cns_path is empty."
30+
fi
31+
32+
if fileutil test -d "${cns_path}"; then
33+
# Path is a directory. Copy all files in the directory.
34+
fileutil cp "${cns_path}/*.tflite" "${work_dir}/"
35+
36+
elif fileutil test -f "${cns_path}"; then
37+
# Path is a file. Copy the file.
38+
fileutil cp "${cns_path}" "${work_dir}/"
39+
40+
else
41+
fatal "The specified cns_path '${cns_path}' is not a valid file or directory, or it does not exist."
42+
fi
43+
44+
for model_file in ${work_dir}/*; do
45+
if [[ -f "${model_file}" ]]; then
46+
echo "${model_file}"
47+
fi
48+
done

litert/integration_test/litert_device_script.bzl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,33 @@ def make_download_model_provider(name, url, testonly = True):
319319
srcs = [":" + name + "_expanded"],
320320
testonly = testonly,
321321
)
322+
323+
# copybara:uncomment_begin(google-only)
324+
# def make_cns_pull_model_provider(name, cns_path, testonly = True):
325+
# """Generates a shell script and runfiles for downloading a model(s) from a CNS path.
326+
#
327+
# This can be depended on by litert_device_scripts to add more models to the data dependencies.
328+
# Args:
329+
# name: The name of the generated sh_binary target.
330+
# cns_path: The CNS path to download the model(s) from. Can be a file or a directory. If a
331+
# directory, all .tflite files in the directory will be downloaded.
332+
# testonly: If True, the generated targets are marked as testonly.
333+
# """
334+
#
335+
# _device_script_lib(
336+
# name = name + "_expanded",
337+
# template = "//litert/integration_test:cns_pull_model_provider.sh",
338+
# out = name + ".sh",
339+
# subs = {
340+
# "@@cns_path@@": cns_path,
341+
# },
342+
# executable = True,
343+
# )
344+
#
345+
# sh_binary(
346+
# name = name,
347+
# srcs = [":" + name + "_expanded"],
348+
# testonly = testonly,
349+
# )
350+
#
351+
# copybara:uncomment_end

0 commit comments

Comments
 (0)