summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorIsabella Gottardi <isabella.gottardi@arm.com>2022-02-16 14:24:03 +0000
committerIsabella Gottardi <isabella.gottardi@arm.com>2022-02-25 17:29:30 +0000
commitef2b9ddd7771589e049c4103859ecef67fe87855 (patch)
tree9856299c572d32cd049816a04dbef7930dc3c7fb /scripts
parent177c69d40dddd4db9da7875b9979b82c67609cd1 (diff)
downloadml-embedded-evaluation-kit-ef2b9ddd7771589e049c4103859ecef67fe87855.tar.gz
MLECO-2881: Revise resources_downloaded based on optimised models' metadata
Change-Id: I12777c3818463c11d6351db0b4961a2bc0b00b18 Signed-off-by: Isabella Gottardi <isabella.gottardi@arm.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/cmake/util_functions.cmake27
-rw-r--r--scripts/py/check_update_resources_downloaded.py84
2 files changed, 108 insertions, 3 deletions
diff --git a/scripts/cmake/util_functions.cmake b/scripts/cmake/util_functions.cmake
index 447265c..ee9eceb 100644
--- a/scripts/cmake/util_functions.cmake
+++ b/scripts/cmake/util_functions.cmake
@@ -1,5 +1,5 @@
#----------------------------------------------------------------------------
-# Copyright (c) 2021 Arm Limited. All rights reserved.
+# Copyright (c) 2021-2022 Arm Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -152,7 +152,7 @@ endfunction()
# Function to download a files from the Arm Model Zoo
# Arguments:
# model_zoo_version: hash of the Arm Model Zoo commit to use
-# file_sub_path: subpath within the model zoo respository
+# file_sub_path: subpath within the model zoo repository
# download_path: location where this file is to be downloaded (path including filename)
function(download_file_from_modelzoo model_zoo_version file_sub_path download_path)
@@ -190,4 +190,25 @@ function(add_platform_build_configuration)
message(STATUS "Found build configuration: ${PLATFORM_BUILD_CONFIG}")
include(${PLATFORM_BUILD_CONFIG}/build_configuration.cmake)
-endfunction() \ No newline at end of file
+endfunction()
+
+function(check_update_public_resources resource_downloaded_dir)
+
+ string(JOIN "/" FILE_URL ${resource_downloaded_dir})
+ execute_process(
+ COMMAND python3 ${CMAKE_SOURCE_DIR}/scripts/py/check_update_resources_downloaded.py
+ --resource_downloaded_dir ${resource_downloaded_dir}
+ --setup_script_path ${CMAKE_SOURCE_DIR}/set_up_default_resources.py
+ RESULT_VARIABLE return_code
+ )
+ if (NOT return_code EQUAL "0")
+ if (NOT return_code EQUAL "1")
+ # Return code equal to 2 or else means an error in the resources_downloaded folder
+ message(FATAL_ERROR "Resources downloaded error, please run: set_up_default_resources.py")
+ else()
+ # Return code equal to 1 means that resources_downloaded need to be updated
+ message(FATAL_ERROR "Resources downloaded need to be updated, please run: set_up_default_resources.py --clean")
+ endif()
+ endif ()
+
+endfunction()
diff --git a/scripts/py/check_update_resources_downloaded.py b/scripts/py/check_update_resources_downloaded.py
new file mode 100644
index 0000000..6408f14
--- /dev/null
+++ b/scripts/py/check_update_resources_downloaded.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+# Copyright (c) 2022 Arm Limited. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0
+#
+# 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.
+import json
+import os
+import subprocess
+import sys
+from argparse import ArgumentParser
+
+
+def check_update_resources_downloaded(
+ resource_downloaded_dir: str, set_up_script_path: str
+):
+ """
+ Function that check if the resources downloaded need to be refreshed.
+
+ Parameters:
+ ----------
+ resource_downloaded_dir (string): Specifies the path to resources_downloaded folder.
+ set_up_script_path (string): Specifies the path to set_up_default_resources.py file.
+ """
+
+ metadata_file_path = os.path.join(
+ resource_downloaded_dir, "resources_downloaded_metadata.json"
+ )
+
+ if os.path.isfile(metadata_file_path):
+ with open(metadata_file_path) as metadata_json:
+
+ metadata_dict = json.load(metadata_json)
+ set_up_script_hash = metadata_dict["set_up_script_hash"]
+ command = f"git log -1 --pretty=tformat:%H {set_up_script_path}"
+
+ proc = subprocess.run(
+ command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True
+ )
+ git_commit_hash = proc.stdout.decode("utf-8").strip("\n")
+ proc.check_returncode()
+
+ if set_up_script_hash == git_commit_hash:
+ return 0
+ # Return code 1 if the resources need to be refreshed.
+ return 1
+ # Return error code 2 if the file doesn't exists.
+ return 2
+
+
+if __name__ == "__main__":
+ parser = ArgumentParser()
+ parser.add_argument(
+ "--resource_downloaded_dir", help="Resources downloaded directory.", type=str
+ )
+ parser.add_argument(
+ "--setup_script_path", help="Path to set_up_default_resources.py.", type=str
+ )
+ args = parser.parse_args()
+
+ # Check if the repo root directory is a git repository
+ root_file_dir = os.path.dirname(os.path.abspath(args.setup_script_path))
+ is_git_repo = os.path.exists(os.path.join(root_file_dir, ".git"))
+
+ # if we have a git repo then check the resources are downloaded,
+ # otherwise it's considered a prerequisite to have run
+ # the set_up_default_resources.py
+ status = (
+ check_update_resources_downloaded(
+ args.resource_downloaded_dir, args.setup_script_path
+ )
+ if is_git_repo
+ else 0
+ )
+ sys.exit(status)