From 71b92a5402594eeb927559b736311d9504f7cff9 Mon Sep 17 00:00:00 2001 From: Nicolas Mailhot Date: Jun 02 2009 21:41:20 +0000 Subject: 1.21 - rework main macro to handle more corner cases, split naming logic in its own macro, add some debug output --- diff --git a/changelog.txt b/changelog.txt index 13681af..316cb27 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,8 @@ +1.21 - Split naming computation in a separate %_font_pkg_name macro and + change its logic to handle more corner naming cases. Some fallout in + existing packages with weird naming choices is to be expected. + - Add debug output to give packagers feedback on the computed names and + help detect collisions 1.20 - Change %define to %global in templates 1.19 - Add partial templates for fonts subpackages of other packages, update for rpm 4.6 changes in fedora-devel @@ -6,23 +11,24 @@ 1.16 - Fix recently introduced typo in the simple spec template 1.15 - Replace shell hacks in the main macro by clean lua code 1.14 - New subpackage naming rules -1.13 - small fixes -1.12 - make some spec indenting closer to what rpmdevtools uses; make -%{_sysconfdir}/fonts a macro to avoid a cycle with the fontconfig package -1.11 - fix hosting info in readme -1.10 - renamed to “fontpackages” -1.9 - fix fontconfig documentation discrepancy noticed by Ankur Sinha, add doc -on fontconfig priorities -1.8 - simplify multi spec template: general case, 1 common license, 1 common -prio -1.7 - split fontconfig template documentation is separate files, to simplify -diff-ing against templates. -1.6 - simplify spec templates -1.5 - use ".conf" extension for fontconfig templates -1.4 - fontpackages-filesystem must be required by the common package in the -multi spec template -1.3 - remove trailing / from directory macro definitions. It's not what people -expect. -1.2 - add directory ownership in simple spec template -1.1 - add fontconfig templates -1.0 - initial release +1.13 - Small fixes +1.12 - Make some spec indenting closer to what rpmdevtools uses; make + %{_sysconfdir}/fonts a macro to avoid a cycle with the fontconfig + package +1.11 - Fix hosting info in readme +1.10 - Renamed to “fontpackages” +1.9 - Fix fontconfig documentation discrepancy noticed by Ankur Sinha, add doc + on fontconfig priorities +1.8 - Simplify multi spec template: general case, 1 common license, 1 common + prio +1.7 - Split fontconfig template documentation is separate files, to simplify + diff-ing against templates. +1.6 - Simplify spec templates +1.5 - Use ".conf" extension for fontconfig templates +1.4 - Fontpackages-filesystem must be required by the common package in the + multi spec template +1.3 - Remove trailing / from directory macro definitions. It's not what people + expect. +1.2 - Add directory ownership in simple spec template +1.1 - Add fontconfig templates +1.0 - Initial release diff --git a/rpm/macros.fonts b/rpm/macros.fonts index 8c50f9d..4cd5cef 100644 --- a/rpm/macros.fonts +++ b/rpm/macros.fonts @@ -24,7 +24,41 @@ ## Magic -# Font (sub)packaging magic +# Utility macro that computes a canonical font (sub)package name +# +# Expects an (optional) subpackage name as argument + +%_font_pkg_name() %{lua: +local function rpmeval(name) + local sname = rpm.expand(name) + if sname == name + then return "" + else + sname = string.lower("-" .. sname .. "-") + sname = string.gsub(sname, "[_%-]+", "-") + sname = string.gsub(sname, "%-font(s?)%-", "-") + sname = string.gsub(sname, "^%-", "") + sname = string.gsub(sname, "%-$", "") + return sname + end +end +local function meld(name1,name2) + local name3 = "-" .. name2 .. "-" + for token in string.gmatch(name1 .. "-" , "..-%-") do + token = string.gsub(token, "%-", "%%-") + name3 = string.gsub(name3, "%-" .. token, "-") + end + return string.gsub( name1 .. name3 , "%-+$", "") +end +local pkgname = rpmeval("%{name}") +local fontname = rpmeval("%{fontname}") +local subname = rpmeval("%1") +print(meld(meld(pkgname,fontname),subname) .. "-fonts") +} + + +# Macro to generate file sections and scriptlets for font (sub)packages +# # Expects: # – an (optional) subpackage name as argument: -n # without -n the macro will work on the core package @@ -39,34 +73,28 @@ # the corresponding symlink point to /dev/null %_font_pkg(n:f:) \ -\ -%define subpkg_name %{-n: %{lua: \ -if rpm.expand("%{name}") == rpm.expand("%{fontname}-fonts") \ -then print(rpm.expand("-n %{fontname}-%{-n*}-fonts")) \ -else print(rpm.expand("%{-n*}-fonts")) \ -end } } \ -\ -%post %{subpkg_name} \ +%define spn %_font_pkg_name %{-n:%{-n*}} \ +%{echo:Generating content for font package: %{spn} \ +}\ +%post -n %{spn} \ if [ -x %{_bindir}/fc-cache ]; then \ %{_bindir}/fc-cache %{_fontdir} || : \ fi \ \ \ -%postun %{subpkg_name} \ +%postun -n %{spn} \ if [ $1 -eq 0 -a -x %{_bindir}/fc-cache ] ; then \ %{_bindir}/fc-cache %{_fontdir} || : \ fi\ \ \ -%files %{subpkg_name} \ +%files -n %{spn} \ %defattr(0644,root,root,0755) \ \ %dir %{_fontdir} \ -\ +%{lua: \ +for arg=1,rpm.expand("%#") do \ + print(rpm.expand("%{_fontdir}/%" .. arg) .. "\\n") \ +end} \ %{-f:%{_fontconfig_templatedir}/%{-f*}} \ -%{-f:%config(noreplace) %{_fontconfig_confdir}/%{-f*}} \ -\ -\ -%{lua: for arg=1,rpm.expand("%#") do \ -print(rpm.expand("%{_fontdir}/%"..arg).."\\n") \ -end} +%{-f:%config(noreplace) %{_fontconfig_confdir}/%{-f*}}