Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions ypkg2/examine.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@

global_xattrs = dict()

def is_elf_file(file_path):
try:
with open(file_path, 'rb') as file:
magic = file.read(4)
return magic == b'\x7fELF'
except FileNotFoundError as e:
print(f"File not found: {file_path} {e}")
return False
except Exception as e:
print(f"{e}")
return False
Comment on lines +45 to +50

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use the pretty-printing console_ui functions to print? If they were warnings, it would make it easier to see during the build.


def is_pkgconfig_file(pretty, mgs):
""" Simple as it sounds, work out if this is a pkgconfig file """
Expand Down
39 changes: 38 additions & 1 deletion ypkg2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .ypkgcontext import YpkgContext
from .scripts import ScriptGenerator
from .packages import PackageGenerator, PRIORITY_USER
from .examine import PackageExaminer
from .examine import PackageExaminer, is_elf_file
from . import metadata
from .dependencies import DependencyResolver
from . import packager_name, packager_email
Expand All @@ -38,6 +38,7 @@

from timeit import default_timer as timer
from datetime import timedelta
from pathlib import Path


def show_version():
Expand Down Expand Up @@ -190,6 +191,41 @@ def execute_step(context, step, step_n, work_dir):
return False
return True

was_avx2_context = False

def post_execute_step(context, step, step_n, work_dir):

hwcaps_v3_bin_dir = os.path.join(context.get_install_dir(), "usr", "hwcaps", "x86-64-v3", "bin")
hwcaps_v1_bin_dir = os.path.join(context.get_install_dir(), "usr", "hwcaps", "x86-64-v1", "bin")
bin_dir = os.path.join(context.get_install_dir(), "usr", "bin")

if context.avx2 and step_n == "install":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paired with my other suggestion about moving the step check, could we inverse this check and early return if the context is not avx2?

global was_avx2_context
was_avx2_context = True

os.makedirs(hwcaps_v3_bin_dir, exist_ok=True)
for dirpath, dirnames, filenames in os.walk(bin_dir):
for file in filenames:
file_path = os.path.join(dirpath, file)
if is_elf_file(file_path):
shutil.move(file_path, hwcaps_v3_bin_dir)

if context.emul32 is False and context.avx2 is False and step_n == "install" and was_avx2_context is True:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if we could also inverse all of this for an early return. There are a lot of elements in this check as well that make it a bit hard to read.

os.makedirs(hwcaps_v1_bin_dir, exist_ok=True)

dummy_hwcaps_loader = Path(bin_dir, "hwcaps-loader")
dummy_hwcaps_loader.touch()

for dirpath, dirnames, filenames in os.walk(bin_dir):
for file in filenames:
file_path = os.path.join(dirpath, file)
if is_elf_file(file_path):
shutil.move(file_path, hwcaps_v1_bin_dir)
relative_target = os.path.relpath(dummy_hwcaps_loader, start=os.path.dirname(file_path))
os.symlink(relative_target, file_path)

os.unlink(dummy_hwcaps_loader)


def build_package(filename, outputDir, buildDir=None):
""" Will in future be moved to a separate part of the module """
Expand Down Expand Up @@ -380,6 +416,7 @@ def build_package(filename, outputDir, buildDir=None):
end_time = timer()
console_ui.emit_success("Build", "{} successful ({})".
format(step, timedelta(seconds=end_time-start_time)))
post_execute_step(context, r_step, step, work_dir)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is run on every step of the build. I think it would make more sense to check if we're on the "install" step before running it here instead of inside the post_execute_step() function; it also slightly simplifies that function.

continue
console_ui.emit_error("Build", "{} failed for {}".format(step, spec.pkg_name))
sys.exit(1)
Expand Down