Browse Source

scripts: modules: Move blob processing to zephyr_module.py

In preparation for the handling of taint flags in zephyr_module.py, move
blob-processing code from the west command to it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
pull/49638/head
Carles Cufi 3 years ago committed by Carles Cufí
parent
commit
b662bc9093
  1. 23
      scripts/west_commands/blobs.py
  2. 32
      scripts/zephyr_module.py

23
scripts/west_commands/blobs.py

@ -3,7 +3,6 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import argparse import argparse
import hashlib
import os import os
from pathlib import Path from pathlib import Path
import sys import sys
@ -79,36 +78,16 @@ class Blobs(WestCommand):
return parser return parser
def get_status(self, path, sha256):
if not path.is_file():
return 'D'
with path.open('rb') as f:
m = hashlib.sha256()
m.update(f.read())
if sha256.lower() == m.hexdigest():
return 'A'
else:
return 'M'
def get_blobs(self, args): def get_blobs(self, args):
blobs = [] blobs = []
modules = args.modules modules = args.modules
for module in zephyr_module.parse_modules(ZEPHYR_BASE, self.manifest): for module in zephyr_module.parse_modules(ZEPHYR_BASE, self.manifest):
mblobs = module.meta.get('blobs', None)
if not mblobs:
continue
# Filter by module # Filter by module
module_name = module.meta.get('name', None) module_name = module.meta.get('name', None)
if len(modules) and module_name not in modules: if len(modules) and module_name not in modules:
continue continue
blobs_path = Path(module.project) / zephyr_module.MODULE_BLOBS_PATH blobs += zephyr_module.process_blobs(module.project, module.meta)
for blob in mblobs:
blob['module'] = module_name
blob['abspath'] = blobs_path / Path(blob['path'])
blob['status'] = self.get_status(blob['abspath'], blob['sha256'])
blobs.append(blob)
return blobs return blobs

32
scripts/zephyr_module.py

@ -18,6 +18,7 @@ maintained in modules in addition to what is available in the main Zephyr tree.
''' '''
import argparse import argparse
import hashlib
import os import os
import re import re
import subprocess import subprocess
@ -131,6 +132,9 @@ mapping:
MODULE_YML_PATH = PurePath('zephyr/module.yml') MODULE_YML_PATH = PurePath('zephyr/module.yml')
# Path to the blobs folder # Path to the blobs folder
MODULE_BLOBS_PATH = PurePath('zephyr/blobs') MODULE_BLOBS_PATH = PurePath('zephyr/blobs')
BLOB_PRESENT = 'A'
BLOB_NOT_PRESENT = 'D'
BLOB_OUTDATED = 'M'
schema = yaml.safe_load(METADATA_SCHEMA) schema = yaml.safe_load(METADATA_SCHEMA)
@ -225,6 +229,34 @@ def process_settings(module, meta):
return out_text return out_text
def get_blob_status(path, sha256):
if not path.is_file():
return BLOB_NOT_PRESENT
with path.open('rb') as f:
m = hashlib.sha256()
m.update(f.read())
if sha256.lower() == m.hexdigest():
return BLOB_PRESENT
else:
return BLOB_OUTDATED
def process_blobs(module, meta):
blobs = []
mblobs = meta.get('blobs', None)
if not mblobs:
return blobs
blobs_path = Path(module) / MODULE_BLOBS_PATH
for blob in mblobs:
blob['module'] = meta.get('name', None)
blob['abspath'] = blobs_path / Path(blob['path'])
blob['status'] = get_blob_status(blob['abspath'], blob['sha256'])
blobs.append(blob)
return blobs
def kconfig_snippet(meta, path, kconfig_file=None): def kconfig_snippet(meta, path, kconfig_file=None):
name = meta['name'] name = meta['name']
name_sanitized = meta['name-sanitized'] name_sanitized = meta['name-sanitized']

Loading…
Cancel
Save