-
Notifications
You must be signed in to change notification settings - Fork 3
Added support for Spec and Post-Install #58
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
Draft
akritkbehera
wants to merge
9
commits into
bitsorg:main
Choose a base branch
from
akritkbehera:Support_for_spec
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+246
−5
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9bb04f5
Added support for Spec and Post-Install
akritkbehera 1cbc8cc
Added generate_rpm to tests
akritkbehera e278038
Stage 1
akritkbehera 06aed46
Updates on dependency checking
akritkbehera f5bb4ac
Merge branch 'main' into Support_for_spec
akritkbehera 02c4d65
Proper json dependencies
akritkbehera e1599c5
rpm dependency checking
akritkbehera 54123b8
Improved Efficency
akritkbehera b4ef1f0
Updated template.spec
akritkbehera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import os | ||
| import subprocess | ||
| import shutil | ||
| import glob | ||
| import json | ||
| from typing import Dict, List, Optional, Set | ||
| from bits_helpers.log import debug, info, banner, warning | ||
|
|
||
|
|
||
| class RPMPackageManager: | ||
|
|
||
| def load_json(filepath: str) -> Dict[str, List[str]]: | ||
| """Load JSON file and return as dictionary.""" | ||
| with open(filepath, 'r') as f: | ||
| return json.load(f) | ||
|
|
||
| def build_provides_set(provides: Dict[str, List[str]]) -> Set[str]: | ||
| """Build a set of all provided dependencies.""" | ||
| all_provides = set() | ||
| for package, dependencies in provides.items(): | ||
| all_provides.update(dependencies) | ||
| return all_provides | ||
|
|
||
| def check_dependencies(file_path: str) -> Dict: | ||
| """ | ||
| Check if all required dependencies are satisfied. | ||
| Returns a dictionary with results. | ||
| """ | ||
| requires_path = os.path.join(file_path, "requires.json") | ||
| provides_path = os.path.join(file_path, "provides.json") | ||
|
|
||
| requires = RPMPackageManager.load_json(requires_path) | ||
| provides = RPMPackageManager.load_json(provides_path) | ||
| provides_set = RPMPackageManager.build_provides_set(provides) | ||
|
|
||
| results = { | ||
| 'satisfied': [], | ||
| 'missing': [], | ||
| 'packages_with_missing': {} | ||
| } | ||
|
|
||
| for package, dependencies in requires.items(): | ||
| package_missing = [] | ||
| debug(f"Checking dependencies for package: {package}") | ||
|
|
||
| for dep in dependencies: | ||
| if dep.startswith('rpmlib('): | ||
| continue | ||
|
|
||
| if dep not in provides_set: | ||
| debug(f" [MISSING] {dep}") | ||
| package_missing.append(dep) | ||
| results['missing'].append({ | ||
| 'package': package, | ||
| 'dependency': dep | ||
| }) | ||
| else: | ||
| debug(f" [OK] {dep}") | ||
| results['satisfied'].append({ | ||
| 'package': package, | ||
| 'dependency': dep | ||
| }) | ||
|
|
||
| if package_missing: | ||
| results['packages_with_missing'][package] = package_missing | ||
|
|
||
| if results['missing']: | ||
| warning(f"Dependency Check Failed: {len(results['missing'])} missing dependencies found.") | ||
| warning("\n" + "="*60) | ||
| warning("❌ MISSING DEPENDENCIES") | ||
| warning("="*60) | ||
| for i, dep in enumerate(results['missing'], 1): | ||
| if isinstance(dep, dict): | ||
| package = dep.get('package', 'Unknown') | ||
| dependency = dep.get('dependency', 'Unknown') | ||
| warning(f"\n{i}. 📦 {package}") | ||
| warning(f" └─ Requires: {dependency}") | ||
| else: | ||
| warning(f"\n{i}. ❌ {dep}") | ||
| warning("="*60 + "\n") | ||
| else: | ||
| banner("Dependency Check Passed: All dependencies satisfied.") | ||
|
|
||
| return results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| #!/bin/bash | ||
| # We don't build RPMs if we have requires.json and provides.json. We can just proceed with checking dependencies. | ||
| if [ -f "$INSTALLROOT/etc/requires.json" ] && [ -f "$INSTALLROOT/etc/provides.json" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Build system-provides RPM and extract provides.json and store in $WORK_DIR/provides.json from where it will be copied by into each package provides.json | ||
| if [ ! -f "$WORK_DIR/rpmbuild/RPMS/$(uname -m)/system-provides-1-1.$(uname -m).rpm" ]; then | ||
| mkdir -p "$WORK_DIR/rpmbuild"/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} | ||
| cp $WORK_DIR/SPECS/$ARCHITECTURE/$PKGNAME/$PKGVERSION-$PKGREVISION/system-provides.spec "$WORK_DIR/rpmbuild/SPECS/system-provides.spec" | ||
| rpmbuild -bb \ | ||
| --define "_topdir $WORK_DIR/rpmbuild" \ | ||
| --define "_buildarch $(uname -m)" \ | ||
| "$WORK_DIR/rpmbuild/SPECS/system-provides.spec" | ||
|
|
||
| rpm -qp --queryformat "%{NAME}\n[%{PROVIDES}\n]" "$WORK_DIR/rpmbuild/RPMS/$(uname -m)/system-provides-1-1.$(uname -m).rpm" | \ | ||
| jq -R -s ' | ||
| split("\n") | ||
| | map(select(length > 0)) | ||
| | { (.[0]): .[1:] } | ||
| ' > "$WORK_DIR/provides.json" | ||
| fi | ||
|
|
||
| if [ "$PKGNAME" != defaults-* ] && [ -f "$WORK_DIR/SPECS/$ARCHITECTURE/$PKGNAME/$PKGVERSION-$PKGREVISION/${PKGNAME}.spec" ]; then | ||
| mkdir -p "$WORK_DIR/rpmbuild"/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} | ||
| mkdir -p "$WORK_DIR/rpmbuild/BUILDROOT/${PKGNAME}" | ||
| chmod -R u+w "$WORK_DIR/rpmbuild" | ||
| source "$WORK_DIR/$ARCHITECTURE/rpm/latest/etc/profile.d/init.sh" || true | ||
| cp "$WORK_DIR/SPECS/$ARCHITECTURE/$PKGNAME/$PKGVERSION-$PKGREVISION/${PKGNAME}.spec" "$WORK_DIR/rpmbuild/SPECS/" | ||
| requires=() | ||
| for f in $REQUIRES; do | ||
| if [[ "$f" == "defaults-"* ]]; then | ||
| continue | ||
| fi | ||
| F=${f^^} | ||
| F=${F//-/_} | ||
| hash="${F}_HASH" | ||
| ver="${F}_VERSION" | ||
| rev="${F}_REVISION" | ||
| requires+=("${f}_${!ver}_${!rev}_${!hash}") | ||
| done | ||
|
|
||
| if [ ${#requires[@]} -eq 0 ]; then | ||
| requires_str="%{nil}" | ||
| else | ||
| printf -v requires_str '%s ' "${requires[@]}" | ||
| requires_str="${requires_str% }" | ||
| fi | ||
|
|
||
| rpmbuild -bb \ | ||
| --define "name ${PKGNAME}_${PKGVERSION}_${PKGREVISION}_${PKGHASH}" \ | ||
| --define "pkgname ${PKGNAME}" \ | ||
| --define "arch $(uname -m)" \ | ||
| --define "installroot $INSTALLROOT" \ | ||
| --define "requires $requires_str" \ | ||
| --define "_topdir $WORK_DIR/rpmbuild" \ | ||
| --define "buildroot $WORK_DIR/rpmbuild/BUILDROOT/${PKGNAME}" \ | ||
| "$WORK_DIR/rpmbuild/SPECS/${PKGNAME}.spec" | ||
|
|
||
| rpm -qp --queryformat "%{NAME}\n[%{REQUIRES}\n]" "$WORK_DIR/rpmbuild/RPMS/$(uname -m)/${PKGNAME}_${PKGVERSION}_${PKGREVISION}_${PKGHASH}-1-1.$(uname -m).rpm" | \ | ||
| jq -R -s ' | ||
| split("\n") | ||
| | map(select(length > 0)) | ||
| | { (.[0]): .[1:] } | ||
| ' > "$INSTALLROOT/etc/requires.json" | ||
|
|
||
| rpm -qp --queryformat "%{NAME}\n[%{PROVIDES}\n]" "$WORK_DIR/rpmbuild/RPMS/$(uname -m)/${PKGNAME}_${PKGVERSION}_${PKGREVISION}_${PKGHASH}-1-1.$(uname -m).rpm" | \ | ||
| jq -R -s ' | ||
| split("\n") | ||
| | map(select(length > 0)) | ||
| | { (.[0]): .[1:] } | ||
| ' > "$INSTALLROOT/etc/provides.json" | ||
|
|
||
| # Collect all provides.json for all the package mentioned in $REQUIRES and also system-provides.json and create a single provides.json file from where we can see if each | ||
| # REQUIRES is satisfied or not. | ||
| provides_files=("$INSTALLROOT/etc/provides.json") | ||
| provides_files+=("$WORK_DIR/provides.json") | ||
|
|
||
| for f in $REQUIRES; do | ||
| if [[ "$f" == "defaults-"* ]]; then | ||
| continue | ||
| fi | ||
| F=${f^^} | ||
| F=${F//-/_} | ||
| hash="${F}_HASH" | ||
| ver="${F}_VERSION" | ||
| rev="${F}_REVISION" | ||
|
|
||
| provides_file="${WORK_DIR}/$ARCHITECTURE/$f/${!ver}-${!rev}/etc/provides.json" | ||
|
|
||
| if [ -f "$provides_file" ]; then | ||
| provides_files+=("$provides_file") | ||
| fi | ||
| done | ||
|
|
||
| # Merge all provides.json files into a single file and store it in $INSTALLROOT/etc/provides.json | ||
| jq -s 'reduce .[] as $item ({}; . * $item)' "${provides_files[@]}" > "$INSTALLROOT/provides.json" | ||
| rm $INSTALLROOT/etc/provides.json | ||
| mv $INSTALLROOT/provides.json $INSTALLROOT/etc/provides.json | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| %define __os_install_post %{nil} | ||
| %define __spec_install_post %{nil} | ||
| %define __spec_install_pre %{___build_pre} | ||
| %define _empty_manifest_terminate_build 0 | ||
| %define _use_internal_dependency_generator 0 | ||
| %define _source_payload w9.gzdio | ||
| %define _binary_payload w9.gzdio | ||
|
|
||
| Name: %{name} | ||
| Version: 1 | ||
| Release: 1 | ||
| Summary: Package %{name} built using bits. | ||
| License: Public Domain | ||
| BuildArch: %{arch} | ||
| Vendor: CERN | ||
|
|
||
| %if "%{?requires}" != "" | ||
| Requires: %{requires} | ||
| %endif | ||
|
|
||
| %description | ||
|
|
||
| %prep | ||
|
|
||
| %build | ||
|
|
||
| %install | ||
| cp -a %{installroot}/* %{buildroot} | ||
|
|
||
| %files | ||
| /* | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @akritkbehera , I would suggest to add a |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akritkbehera , I would suggest to dump rpm provides and requires here and then run dependency checking ( by finding all its requires from its dependency packages). This way dependency checking can be run in parallel and once we are done here then package should be ready to be uploaded.