Skip to content

Commit

Permalink
Use ldd to determine glibc version instead of scanning binaries.
Browse files Browse the repository at this point in the history
Summary:
Use ldd to determine glibc version instead of scanning binaries.
Scanning binaries doens't work as there may not be any symbols tagged with the most recent
required glibc.

Test Plan: Jenkins: build only

Reviewers: devops, steve.varnau

Reviewed By: steve.varnau

Subscribers: devops

Differential Revision: https://phorge.dev.yugabyte.com/D33073
  • Loading branch information
jharveysmith committed Mar 12, 2024
1 parent 097bf94 commit 01b596f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 45 deletions.
11 changes: 11 additions & 0 deletions python/yugabyte/gen_version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def boolean_to_json_str(bool_flag: bool) -> str:
return str(bool_flag).lower()


def get_glibc_version() -> str:
glibc_v = subprocess.check_output('ldd --version', shell=True).decode('utf-8').strip()
# We only want the version
return glibc_v.split("\n")[0].split()[-1]


def get_git_sha1(git_repo_dir: str) -> Optional[str]:
try:
sha1 = subprocess.check_output(
Expand Down Expand Up @@ -187,6 +193,11 @@ def main() -> int:
"platform": os_platform,
"architecture": architecture
}

# Record our glibc version. This doesn't apply to mac/darwin.
if os_platform == 'linux':
data["glibc_v"] = get_glibc_version()

content = json.dumps(data)

# Frequently getting errors here when rebuilding on NFS:
Expand Down
43 changes: 0 additions & 43 deletions python/yugabyte/release_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,6 @@ def filter_bin_items(
]


def get_max_glibc_version(directory: str) -> str:
directory = shlex.quote(directory)
cmd = f'find {directory} \( -name "*.so" -or -name "*.so.*" -or -perm +x \)' # nopep8: W605
cmd += " -exec grep -Eoa 'GLIBC_[0-9.]+' {} \;" # nopep8: W605
try:
glibc_versions = subprocess.check_output(cmd, shell=True).decode('utf-8').strip().split()
except Exception as e:
logging.warning("Determining max glibc version with `{}` raised an error".format(cmd))
raise e

if not glibc_versions:
logging.warning("No GLIBC versions found using command `{}`".format(cmd))
raise RuntimeError('No GLIBC versions found')

# Return the last version in the list, it should be the highest.
return sorted(set(glibc_versions), key=parse_glibc_version)[-1]


def parse_glibc_version(glibc_v: str) -> List[int]:
""" Glibc versions look like GLIBC_1.2.3
Split on the _ to remove the text portion, then split on . to get a list of ints that the
sorted function can sort like we expect (as versions).
>>> parse_glibc_version('GLIBC_2.2.5')
[2, 2, 5]
>>> parse_glibc_version('GLIBC_2.20')
[2, 20]
"""
return list(map(int, glibc_v.split('_', 1)[1].split('.')))


class ReleaseUtil:
"""Packages a YugaByte package with the appropriate file naming schema."""
release_manifest: Dict[str, Any]
Expand Down Expand Up @@ -265,18 +234,6 @@ def create_distribution(self, distribution_dir: str) -> None:
os.path.join(current_dest_dir, os.path.basename(file_path)))
logging.info("Created the distribution at '{}'".format(distribution_dir))

def set_glibc_version(self, distribution_dir: str) -> None:
# Only linux has glibc
if platform.system() != 'Linux':
return
glibc_v = get_max_glibc_version(distribution_dir)
manifest_file = os.path.join(distribution_dir, VERSION_METADATA_FILE)
with open(manifest_file) as m:
metadata = json.load(m)
metadata['glibc_version'] = glibc_v
with open(manifest_file, "w") as m:
json.dump(metadata, m)

def update_manifest(self, distribution_dir: str) -> None:
for release_subdir in ['bin']:
if release_subdir in self.release_manifest:
Expand Down
2 changes: 0 additions & 2 deletions python/yugabyte/yb_release_core_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,6 @@ def main() -> None:
raise RuntimeError("Directory '{}' exists and is non-empty".format(build_target_dir))
release_util.create_distribution(build_target_dir)

release_util.set_glibc_version(build_target_dir)

# This will set rpath for executables and libraries when using Linuxbrew.
library_packager.postprocess_distribution(build_target_dir)

Expand Down

0 comments on commit 01b596f

Please sign in to comment.