-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathvariables.bzl
52 lines (44 loc) · 2.22 KB
/
variables.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Copyright (c) 2020-2024 Qualcomm Innovation Center, Inc. All rights reserved.
# 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.
"""Find SNPE folder and pass it to bazel build config"""
def _impl(repository_ctx):
if "windows" in repository_ctx.os.name:
# print(repository_ctx.attr.workspace_dir + "/mobile_back_qti/")
found = repository_ctx.execute(["ls", repository_ctx.attr.workspace_dir + "/mobile_back_qti/qairt/"])
if found.return_code != 0 or found.stdout == "" or found.stdout == "\n":
fail("qairt folder is not found in the repo: " + found.stderr)
filelist = found.stdout.split("\n")
filepath = ""
for x in filelist:
if x.startswith("2"):
filepath = x
break
if filepath == "":
fail("qairt folder is not found in the repo")
else:
found = repository_ctx.execute(["find", repository_ctx.attr.workspace_dir + "/mobile_back_qti/qairt/", "-maxdepth", "1", "-name", "2.*", "-type", "d", "-print", "-quit"])
if found.return_code != 0 or found.stdout == "" or found.stdout == "\n":
fail("qairt folder is not found in the repo")
filepath = found.stdout[:-1]
sdk_version = filepath[found.stdout.rfind("/") + 1:]
print("Update SNPE version: " + sdk_version) # buildifier: disable=print
repository_ctx.read(Label("@//:mobile_back_qti/qairt/" + sdk_version + "/ReleaseNotes.txt"))
repository_ctx.file("BUILD", "")
repository_ctx.file(
"snpe_var_def.bzl",
"SNPE_VERSION = \"%s\"" % sdk_version,
)
snpe_version_loader = repository_rule(
implementation = _impl,
environ = ["SNPE_VERSION"],
local = True,
attrs = {"workspace_dir": attr.string(mandatory = True)},
)