Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce69e9c8 authored by Spandan Das's avatar Spandan Das
Browse files

Convert check_radio_versions to python3

Additionaly,
1. Run it as a python_binary_host so that it uses the hermetic python
toolchain
2. Fix an existing bug where if `board_info_txt` was empty, $^ would
   evaluate to its own path, and it would try to parse the relevant
   configuration from the wrong file

Bug: 196300985
Test: m out/target/product/vsoc_arm64/android-info.txt
Change-Id: Ie1e51a93041591829da4351dd57f37106e15d764
parent e9d0a7f5
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -19,8 +19,11 @@ board_info_txt := $(TARGET_BOARD_INFO_FILE)
ifndef board_info_txt
board_info_txt := $(wildcard $(TARGET_DEVICE_DIR)/board-info.txt)
endif
$(INSTALLED_ANDROID_INFO_TXT_TARGET): $(board_info_txt) build/make/tools/check_radio_versions.py
	$(hide) build/make/tools/check_radio_versions.py $< $(BOARD_INFO_CHECK)
CHECK_RADIO_VERSIONS := $(HOST_OUT_EXECUTABLES)/check_radio_versions$(HOST_EXECUTABLE_SUFFIX)
$(INSTALLED_ANDROID_INFO_TXT_TARGET): $(board_info_txt) $(CHECK_RADIO_VERSIONS)
	$(hide) $(CHECK_RADIO_VERSIONS) \
		--board_info_txt $(board_info_txt) \
		--board_info_check $(BOARD_INFO_CHECK)
	$(call pretty,"Generated: ($@)")
ifdef board_info_txt
	$(hide) grep -v '#' $< > $@
+5 −0
Original line number Diff line number Diff line
@@ -54,3 +54,8 @@ cc_binary_host {
  name: "build-runfiles",
  srcs: ["build-runfiles.cc"],
}

python_binary_host {
  name: "check_radio_versions",
  srcs: ["check_radio_versions.py"],
}
+18 −11
Original line number Diff line number Diff line
@@ -22,11 +22,18 @@ try:
except ImportError:
  from sha import sha as sha1

if len(sys.argv) < 2:
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--board_info_txt", nargs="?", required=True)
parser.add_argument("--board_info_check", nargs="*", required=True)
args = parser.parse_args()

if not args.board_info_txt:
  sys.exit(0)

build_info = {}
f = open(sys.argv[1])
f = open(args.board_info_txt)
for line in f:
  line = line.strip()
  if line.startswith("require"):
@@ -36,7 +43,7 @@ f.close()

bad = False

for item in sys.argv[2:]:
for item in args.board_info_check:
  key, fn = item.split(":", 1)

  values = build_info.get(key, None)
@@ -52,8 +59,8 @@ for item in sys.argv[2:]:
  try:
    f = open(fn + ".sha1")
  except IOError:
    if not bad: print
    print "*** Error opening \"%s.sha1\"; can't verify %s" % (fn, key)
    if not bad: print()
    print("*** Error opening \"%s.sha1\"; can't verify %s" % (fn, key))
    bad = True
    continue
  for line in f:
@@ -63,17 +70,17 @@ for item in sys.argv[2:]:
    versions[h] = v

  if digest not in versions:
    if not bad: print
    print "*** SHA-1 hash of \"%s\" doesn't appear in \"%s.sha1\"" % (fn, fn)
    if not bad: print()
    print("*** SHA-1 hash of \"%s\" doesn't appear in \"%s.sha1\"" % (fn, fn))
    bad = True
    continue

  if versions[digest] not in values:
    if not bad: print
    print "*** \"%s\" is version %s; not any %s allowed by \"%s\"." % (
        fn, versions[digest], key, sys.argv[1])
    if not bad: print()
    print("*** \"%s\" is version %s; not any %s allowed by \"%s\"." % (
        fn, versions[digest], key, args.board_info_txt))
    bad = True

if bad:
  print
  print()
  sys.exit(1)