Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache build base verion #68

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions scripts/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
RESULT_FILE = "runner_result.log"
BIG_WAIT_INTERVAL = 100
SMALL_WAIT_INTERVAL = 10
CACHED_VERSION_FILE_NAME = ".cached_version"


class Runner(Component):
Expand Down Expand Up @@ -150,12 +151,33 @@ def __normalize_dir(dirname: str, fail_with_text="") -> str:
sys.exit(f"Name '{fail_with_text}' was not specified")
return ""

def __is_use_cache(self) -> bool:
if not (self.build_base_cached and os.path.exists(self.build_base_cached)):
return False
if os.path.exists(CACHED_VERSION_FILE_NAME):
# There is a cached file - then we need to check version.
with open(CACHED_VERSION_FILE_NAME, errors='ignore', encoding='ascii') as f_version:
last_version = f_version.read()
if last_version == self.version:
self.logger.info(f"Reusing build base from {self.build_base_cached}, version: {last_version}")
return True
self.logger.info(f"Cached build base is outdated. "
f"Previous version is {last_version}, current version is {self.version}")
return False
# No cached file - do not reuse.
self.logger.info("Cannot find last cached version")
return False

def __cache_build_base(self):
if self.build_base_cached:
with open(CACHED_VERSION_FILE_NAME, "w", encoding='ascii') as f_version:
f_version.write(self.version)

def builder(self) -> str:
"""
Create a build base for specific
Create a build base for specific kernel
"""
if self.build_base_cached:
self.logger.info(f"Reusing build base from {self.build_base_cached}")
if self.__is_use_cache():
return self.build_base_cached
self.logger.info("Preparing build base")
builder_script = os.path.join(self.klever_home_dir, BUILDER_SCRIPT)
Expand All @@ -168,6 +190,7 @@ def builder(self) -> str:
build_base_dir = os.path.join(self.builder_work_dir,
f"build-base-{kernel_dir_rel}-{self.arch}-{self.make_cmd}")
self.logger.info(f"Build base has been prepared in {build_base_dir}")
self.__cache_build_base()
return build_base_dir

def __update_job_config(self, build_base_dir: str):
Expand Down
Loading