Add package-notes-srpm-macros subpackage to configure rpm builds
This commit is contained in:
parent
d4bfe9cb08
commit
c0df21c270
49
generate-rpm-note.sh
Normal file
49
generate-rpm-note.sh
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
pad_string() {
|
||||||
|
for _ in $(seq "$1"); do
|
||||||
|
printf ' BYTE(0x00)'
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
write_string() {
|
||||||
|
text="$1"
|
||||||
|
prefix="$2"
|
||||||
|
label="$3"
|
||||||
|
total="$4"
|
||||||
|
|
||||||
|
printf "%s/* %s: '%s' */" "$prefix" "$label" "$text"
|
||||||
|
for i in $(seq ${#text}); do
|
||||||
|
if (( i % 4 == 1 )); then
|
||||||
|
printf '\n%s' "$prefix"
|
||||||
|
else
|
||||||
|
printf ' '
|
||||||
|
fi
|
||||||
|
printf 'BYTE(0x%02x)' "'${text:i-1:1}"
|
||||||
|
done
|
||||||
|
|
||||||
|
pad_string $(( total - ${#text} ))
|
||||||
|
printf '\n'
|
||||||
|
}
|
||||||
|
|
||||||
|
write_script() {
|
||||||
|
value_len=$(( (${#1} + 3) / 4 * 4 ))
|
||||||
|
|
||||||
|
printf 'SECTIONS\n{\n'
|
||||||
|
printf ' .note.package (READONLY) : ALIGN(4) {\n'
|
||||||
|
printf ' BYTE(0x04) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Owner including NUL */\n'
|
||||||
|
printf ' BYTE(0x%02x) BYTE(0x%02x) BYTE(0x00) BYTE(0x00) /* Length of Value including NUL */\n' \
|
||||||
|
$((value_len % 256)) $((value_len / 256))
|
||||||
|
|
||||||
|
printf ' BYTE(0x7e) BYTE(0x1a) BYTE(0xfe) BYTE(0xca) /* Note ID */\n'
|
||||||
|
printf " BYTE(0x46) BYTE(0x44) BYTE(0x4f) BYTE(0x00) /* Owner: 'FDO' */\n"
|
||||||
|
|
||||||
|
write_string "$1" ' ' 'Value' "$value_len"
|
||||||
|
|
||||||
|
printf ' }\n}\n'
|
||||||
|
printf 'INSERT AFTER .note.gnu.build-id;\n'
|
||||||
|
}
|
||||||
|
|
||||||
|
cpe="$(cat /usr/lib/system-release-cpe)"
|
||||||
|
json="$(printf '{"type":"rpm","name":"%s","version":"%s","architecture":"%s","osCpe":"%s"}' "$1" "$2" "$3" "$cpe")"
|
||||||
|
write_script "$json"
|
8
macros.generate-package-notes-srpm
Normal file
8
macros.generate-package-notes-srpm
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Add an ELF note with information about the package the code was compiled for.
|
||||||
|
# See https://fedoraproject.org/wiki/Changes/Package_information_on_ELF_objects
|
||||||
|
# for details.
|
||||||
|
%_package_note_file %{_builddir}/.package_note-%{name}-%{version}-%{release}.%{_arch}.ld
|
||||||
|
|
||||||
|
%_package_note_flags %{?name:-Wl,-dT,%{_package_note_file}}
|
||||||
|
|
||||||
|
%_generate_package_note_file %{?name: if ! [ -f %{_package_note_file} ] && [ -f %{_rpmconfigdir}/generate-rpm-note.sh ]; then %{_rpmconfigdir}/generate-rpm-note.sh %{name} %{version}-%{release} %{_arch} >%{_package_note_file}; fi}
|
@ -10,13 +10,25 @@ License: CC0
|
|||||||
URL: %{forgeurl}
|
URL: %{forgeurl}
|
||||||
Source0: %{forgesource}
|
Source0: %{forgesource}
|
||||||
|
|
||||||
|
Source1: generate-rpm-note.sh
|
||||||
|
Source2: macros.package-notes-srpm
|
||||||
|
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
BuildRequires: python3-devel
|
BuildRequires: python3-devel
|
||||||
Requires: python3dist(simplejson)
|
Requires: python3dist(simplejson)
|
||||||
|
|
||||||
%description
|
%description
|
||||||
This package provides a generator of linker scripts that insert a section with
|
This package provides a generator of linker scripts that insert a section with
|
||||||
a note with a JSON payload that describes the package the binary was built for.
|
an ELF note with a JSON payload that describes the package the binary was built
|
||||||
|
for.
|
||||||
|
|
||||||
|
%package srpm-macros
|
||||||
|
Summary: %{summary}
|
||||||
|
|
||||||
|
%description srpm-macros
|
||||||
|
RPM macros to inject a linker script into link flags and a helper to generate
|
||||||
|
a script that inserts a section with an ELF note with a JSON payload that
|
||||||
|
describes the package the binary was built for.
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%autosetup
|
%autosetup
|
||||||
@ -26,11 +38,19 @@ a note with a JSON payload that describes the package the binary was built for.
|
|||||||
|
|
||||||
%install
|
%install
|
||||||
install -Dt %{buildroot}%{_bindir}/ generate-package-notes
|
install -Dt %{buildroot}%{_bindir}/ generate-package-notes
|
||||||
install -m 0644 -Dt %{buildroot}%{_mandir}/man1/ debian/generate-package-notes.1
|
install -m0644 -Dt %{buildroot}%{_mandir}/man1/ debian/generate-package-notes.1
|
||||||
|
|
||||||
|
# A partial reimplementation without Python
|
||||||
|
install -Dt %{buildroot}%{_rpmconfigdir}/ %{SOURCE1}
|
||||||
|
install -m0644 -Dt %{buildroot}%{_rpmmacrodir}/ %{SOURCE2}
|
||||||
|
|
||||||
%files
|
%files
|
||||||
%{_bindir}/generate-package-notes
|
%{_bindir}/generate-package-notes
|
||||||
%{_mandir}/man1/generate-package-notes.1*
|
%{_mandir}/man1/generate-package-notes.1*
|
||||||
|
|
||||||
|
%files srpm-macros
|
||||||
|
%{_rpmconfigdir}/generate-rpm-note.sh
|
||||||
|
%{_rpmmacrodir}/macros.package-notes-srpm
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
%autochangelog
|
%autochangelog
|
||||||
|
Loading…
Reference in New Issue
Block a user