# Macros to replace overly complicated references to CRAN URLs and source files. # %cran_source - # Expands to the CRAN URL for a package # Accepts zero to three arguments: # 1: The CRAN project name, defaulting to %packname if it is defined. # If not, R- will be stripped from %name and %packname defined to that. # 2: The CRAN version, defaulting to %version. # 3: The file extension, defaulting to %__cran_default_extension (tar.gz). # Requires %__cran_package_url_template and %__cran_default_extension to be defined. # %__cran_package_url_template will undergo substitution (case-sensitive): # * "PACKNAME" will be replaced with the above CRAN project name. # * "PACKVERSION" will be replaced with the above CRAN version. # * "EXTENSION" will be replaced with the above extension. # # %cran_url - # Expands to the CRAN URL for a package # Accepts zero or one arguments: # 1: The CRAN project name, defaulting to %packname if it is defined. # If not, R- will be stripped from %name and %packname defined to that. # Requires %__cran_project_url_template to be defined. # %__cran_project_url_template will undergo substitution (case-sensitive): # * "PACKNAME" will be replaced with the above CRAN project name. %__cran_project_url_template https://cran.r-project.org/package=PACKNAME %__cran_package_url_template %{__cran_project_url_template}&version=PACKVERSION#/PACKNAME_PACKVERSION.EXTENSION %__cran_default_extension tar.gz %cran_source() %{lua: local ver = rpm.expand('%1') local src = rpm.expand('%2') local ext = rpm.expand('%3') local url = rpm.expand('%__cran_package_url_template') \ -- If no first argument, use %version if ver == '%1' then ver = rpm.expand('%version') end \ -- If no second argument, try %packname, then %name with 'R-' stripped. -- Note that rpm leaves macros unchanged if they are not defined. if src == '%2' then src = rpm.expand('%packname') end if src == '%packname' then src = string.gsub(rpm.expand('%name'), "^R%-", "") -- Since packname wasn't defined, define it for convenience. rpm.define("packname " .. src) end \ -- If no third argument, use the preset default extension if ext == '%3' then ext = rpm.expand('%__cran_default_extension') end \ -- Now substitute in all the values url = string.gsub(url, "PACKNAME", src) url = string.gsub(url, "PACKVERSION", ver) url = string.gsub(url, "EXTENSION", ext) \ print(url) } %cran_url() %{lua: local src = rpm.expand('%1') local url = rpm.expand('%__cran_project_url_template') \ -- If no first argument, try %packname, then %name with 'R-' stripped. -- Note that rpm leaves macros unchanged if they are not defined. if src == '%1' then src = rpm.expand('%packname') end if src == '%packname' then src = string.gsub(rpm.expand('%name'), "^R%-", "") -- Since packname wasn't defined, define it for convenience. rpm.define("packname " .. src) end \ -- Substitute in the package name url = string.gsub(url, "PACKNAME", src) \ print(url) } # XXXXXXXXXX Experimental # The basic sections %r_prep %{lua:\ local packname = rpm.expand('%packname') local autosetup = rpm.expand("%{autosetup -c -n " .. packname .. "}") \ print(autosetup .. "\\\n") } %r_install %{lua:\ local rlibdir = rpm.expand('%rlibdir') local bindir = rpm.expand('%_bindir') local packname = rpm.expand('%packname') local buildroot = rpm.expand('%buildroot') \ -- A function to simplify conditionally adding to the file list local function add_file(file, type) if (file ~= nil) then print("[[ -e " .. buildroot .. rlibdir .. "/" .. packname .. "/" .. file .. " ]] && ") end print("echo '") if (type ~= nil) then print("%" .. type .. " ") end print(rlibdir .. "/" .. packname) if (file ~= nil) then print("/" .. file) end print("' >> " .. packname .. ".files\\\n") end \ print("mkdir -p " .. buildroot .. rlibdir .. "\\\n") print(bindir .. "/R CMD INSTALL -l " .. buildroot .. rlibdir .. " " .. packname .. "\\\n") print("test -d " .. packname .. "/src && (cd " .. packname .. "/src; rm -f *.o *.so)\\\n") print("rm -f " .. buildroot .. rlibdir .. "/R.css\\\n") \ -- R packages have a somewhat regularlized file structure -- This could be pushed out to a shell script and called like %find_lang is -- called. But for now we'll just inline the code. print("\\\n# Generate a default file list\\\n") add_file(nil, "dir") add_file("html/", "doc") add_file("libs", "dir") add_file("libs/" .. packname .. ".so") add_file("DESCRIPTION") add_file("COPYING", "license") add_file("LICENSE", "license") add_file("NEWS", "doc") add_file("INDEX") add_file("NAMESPACE") add_file("Meta/") add_file("R/") add_file("help/") \ print("ls -lR " .. buildroot .. "\\\n") } %r_check %{lua:\ local bindir = rpm.expand('%_bindir') local packname = rpm.expand('%packname') \ print(bindir .. "/R CMD check " .. packname .. "\\\n") } # For noarch packages %r_noarch_package %{lua:\ print("BuildArch: noarch\\\n") print("Requires: R-core\\\n") print("BuildRequires: R-devel tex(latex)\\\n") rpm.define("rlibdir %{_datadir}/R/library") print("%build\\\n\\\n") } %r_archful_package %{lua:\ print("BuildRequires: R-devel tex(latex)\\\n") rpm.define("rlibdir %{_libdir}/R/library") -- print("%build\\\n\\\n") } %r_simple_archful_package %{lua:\ print(rpm.expand("%r_archful_package")) \ local prep = rpm.expand("%r_prep") print("%prep\\\n") print(prep .. "\\\n\\\n") \ -- Hack around bizarre redefinition of %install. local pre_install = rpm.expand('%{?_enable_debug_packages:%{debug_package}}') print(pre_install .. "\\\n") \ local install = rpm.expand('%r_install') print("%install\\\n") print(install .. "\\\n\\\n") \ local check = rpm.expand('%r_check') print("%check\\\n") print(check .. "\\\n\\\n") \ -- We could even add the files section here, but this needs magic to -- determine packname since it hasn't yet been defined. -- print("%files -f " .. packname .. ".files\\n") }