Skip to content

Commit

Permalink
Add minor OS version to platform object
Browse files Browse the repository at this point in the history
  • Loading branch information
leocardao committed Jun 18, 2024
1 parent 2c3bc49 commit 2b48ceb
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/e3/electrolyt/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ def _add_action(self, name: str, *args: Any, **kwargs: Any) -> None:
# If necessary adjust target machine name
if board is not None:
result.set_target(
result.target.platform,
result.target.os.version,
board,
result.target.os.mode,
name=result.target.platform,
version=result.target.os.version,
machine=board,
mode=result.target.os.mode,
)

# Set action attribute (with action name)
Expand Down
35 changes: 30 additions & 5 deletions src/e3/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def set_build(
self,
name: str | None = None,
version: str | None = None,
version_minor: str | None = None,
machine: str | None = None,
mode: str | None = None,
) -> None:
Expand All @@ -145,7 +146,11 @@ def set_build(
"""
e3.log.debug("set_build (build_name=%s, build_version=%s)", name, version)
self.build = Platform.get(
platform_name=name, version=version, machine=machine, mode=mode
platform_name=name,
version=version,
version_minor=version_minor,
machine=machine,
mode=mode,
)
self.host = self.build
self.target = self.build
Expand All @@ -154,6 +159,7 @@ def set_host(
self,
name: str | None = None,
version: str | None = None,
version_minor: str | None = None,
machine: str | None = None,
mode: str | None = None,
) -> None:
Expand Down Expand Up @@ -185,14 +191,19 @@ def set_host(
self.host = self.build
else:
self.host = Platform.get(
platform_name=name, version=version, machine=machine, mode=mode
platform_name=name,
version=version,
version_minor=version_minor,
machine=machine,
mode=mode,
)
self.target = self.host

def set_target(
self,
name: str | None = None,
version: str | None = None,
version_minor: str | None = None,
machine: str | None = None,
mode: str | None = None,
) -> None:
Expand Down Expand Up @@ -224,7 +235,11 @@ def set_target(
self.target = self.build
else:
self.target = Platform.get(
platform_name=name, version=version, machine=machine, mode=mode
platform_name=name,
version=version,
version_minor=version_minor,
machine=machine,
mode=mode,
)

def set_env(
Expand Down Expand Up @@ -267,7 +282,12 @@ def get_platform(
elif split_value[0] == "target":
return saved_target
elif not propagate_build_info:
return Platform.get(*split_value) # type: ignore
return Platform.get(
platform_name=split_value[0],
version=split_value[1],
machine=split_value[2],
mode=split_value[3],
)
else:
# Propagate machine name and OS version if necessary
if split_value[2] is None:
Expand All @@ -279,7 +299,12 @@ def get_platform(
# Linux machine should not change the OS version
if split_value[1] is None:
split_value[1] = saved_build.os.version
return Platform.get(*split_value) # type: ignore
return Platform.get(
platform_name=split_value[0],
version=split_value[1],
machine=split_value[2],
mode=split_value[3],
)

# Retrieve final values for build, host and target
build_opts = get_platform(build, propagate_build_info=True)
Expand Down
25 changes: 24 additions & 1 deletion src/e3/os/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ class OS(
[
"name",
"version",
"version_minor",
"kernel_version",
"exeext",
"dllext",
Expand Down Expand Up @@ -360,6 +361,7 @@ def get(
name: str,
is_host: bool = False,
version: str = UNKNOWN,
version_minor: str | None = UNKNOWN,
mode: str = UNKNOWN,
) -> OS:
"""Initialize OS instance.
Expand All @@ -377,14 +379,35 @@ def get(

dllext = KNOWLEDGE_BASE.os_info[name]["dllext"]

if not version_minor:
version_minor = UNKNOWN

# If version is not given by the user guess it or set it to the
# default (cross case)
if version == UNKNOWN:
if is_host:
SystemInfo.fetch_system_data()
version, kernel_version = SystemInfo.os_version()
if version_minor == UNKNOWN:
if "." in SystemInfo.ld_info["version"]: # type: ignore[index]
version_minor = SystemInfo.ld_info["version"].split(".")[1] # type: ignore[index]
elif "." in version: # Can occure when host is windows
version_minor = version.split(".")[1]
else:
version = KNOWLEDGE_BASE.os_info[name]["version"]
if version_minor == UNKNOWN and "." in version:
version_minor = version.split(".")[1]
kernel_version = UNKNOWN
else:
kernel_version = UNKNOWN
return OS(name, version, kernel_version, exeext, dllext, is_bareboard, mode)

return cls(
name,
version,
version_minor,
kernel_version,
exeext,
dllext,
is_bareboard,
mode,
)
13 changes: 11 additions & 2 deletions src/e3/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def get(
cls,
platform_name: str | None = None,
version: str | None = None,
version_minor: str | None = None,
machine: str | None = None,
mode: str | None = None,
compute_default: bool = False,
Expand All @@ -68,14 +69,19 @@ def get(
:param version: if None, assume default OS version or find it
automatically (native case only). Otherwise should be a valid
version string.
:param version_minor: if None, assume default OS minor version or find it
automatically. Otherwise should be a valid minor version string.
:param machine: name of the machine
:param mode: an os mode (ex: rtp for vxworks)
:param compute_default: if True compute the default Arch for the
current machine (this parameter is for internal purpose only).
:param mode: an os mode (ex: rtp for vxworks)
"""
# normalize arguments
if not version:
version = e3.os.platform.UNKNOWN
if not version_minor:
version_minor = e3.os.platform.UNKNOWN

if machine is None or machine == e3.os.platform.UNKNOWN:
machine = ""
if not mode:
Expand Down Expand Up @@ -112,7 +118,9 @@ def get(
assert platform_name is not None
pi = KNOWLEDGE_BASE.platform_info[platform_name]
cpu = e3.os.platform.CPU.get(pi["cpu"], pi.get("endian", None), is_host)
os = e3.os.platform.OS.get(pi["os"], is_host, version=version, mode=mode)
os = e3.os.platform.OS.get(
pi["os"], is_host, version=version, version_minor=version_minor, mode=mode
)
is_hie = pi["is_hie"]

# Find triplet
Expand Down Expand Up @@ -159,6 +167,7 @@ def __str__(self) -> str:
"OS\n"
" name: %(os_name)s\n"
" version: %(os_version)s\n"
" version_minor: %(os_version_minor)s\n"
" exeext: %(os_exeext)s\n"
" dllext: %(os_dllext)s\n"
" is_bareboard: %(os_is_bareboard)s\n"
Expand Down

0 comments on commit 2b48ceb

Please sign in to comment.