Skip to content

Commit 944ef53

Browse files
committed
Don't use directory symlinks
RPM does not properly support replacing directories with symlinks or vice versa. Our attempt to work around this using a pretrans scriptlet did not fully work. This instead replaces the directory symlinks with a fully copy of the directory structure, with the individual files being symlinked instead.
1 parent e4bb3e5 commit 944ef53

File tree

1 file changed

+31
-148
lines changed

1 file changed

+31
-148
lines changed

llvm.spec

Lines changed: 31 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
#region main package
227227
Name: %{pkg_name_llvm}
228228
Version: %{maj_ver}.%{min_ver}.%{patch_ver}%{?rc_ver:~rc%{rc_ver}}%{?llvm_snapshot_version_suffix:~%{llvm_snapshot_version_suffix}}
229-
Release: 5%{?dist}
229+
Release: 6%{?dist}
230230
Summary: The Low Level Virtual Machine
231231

232232
License: Apache-2.0 WITH LLVM-exception OR NCSA
@@ -1768,37 +1768,25 @@ rmdir %{buildroot}%{install_mandir}/man1
17681768
rmdir %{buildroot}%{install_mandir}
17691769

17701770
%if %{without compat_build}
1771+
# We don't create directory symlinks, because RPM does not support
1772+
# switching between a directory and a symlink, causing upgrade/downgrade issues.
1773+
# Instead, recursively copy the directories while creating symlinks.
1774+
copy_with_relative_symlinks() {
1775+
local src="$1"
1776+
local dest="$2"
1777+
mkdir -p "$dest"
1778+
1779+
# Change to source directory to simplify relative paths
1780+
(cd "$src" && \
1781+
find * -type d -exec mkdir -p "$dest/{}" \; && \
1782+
find * \( -type f -o -type l \) -exec ln -s --relative "$src/{}" "$dest/{}" \;)
1783+
}
1784+
17711785
# Add symlinks for libraries.
1772-
mkdir -p %{buildroot}%{_libdir}
1773-
for f in %{buildroot}%{install_libdir}/*; do
1774-
filename=`basename $f`
1775-
if [ "$filename" != "cmake" ]; then
1776-
ln -s ../../%{install_libdir}/$filename %{buildroot}/%{_libdir}/$filename
1777-
fi
1778-
done
1779-
# Special handling for cmake, as we don't own the cmake directory itself.
1780-
mkdir -p %{buildroot}%{_libdir}/cmake
1781-
for f in %{buildroot}%{install_libdir}/cmake/*; do
1782-
filename=`basename $f`
1783-
ln -s ../../../%{install_libdir}/cmake/$filename %{buildroot}/%{_libdir}/cmake/$filename
1784-
done
1785-
mkdir -p %{buildroot}%{_libexecdir}
1786-
for f in %{buildroot}%{install_libexecdir}/*; do
1787-
filename=`basename $f`
1788-
ln -s ../../%{install_libexecdir}/$filename %{buildroot}/%{_libexecdir}/$filename
1789-
done
1790-
# Add symlinks for include directories.
1791-
mkdir -p %{buildroot}%{_includedir}
1792-
for f in %{buildroot}%{install_includedir}/*; do
1793-
filename=`basename $f`
1794-
ln -s ../../%{install_includedir}/$filename %{buildroot}/%{_includedir}/$filename
1795-
done
1796-
# Add symlinks for data directories.
1797-
mkdir -p %{buildroot}%{_datadir}
1798-
for f in %{buildroot}%{install_datadir}/*; do
1799-
filename=`basename $f`
1800-
ln -s ../../%{install_datadir}/$filename %{buildroot}/%{_datadir}/$filename
1801-
done
1786+
copy_with_relative_symlinks %{buildroot}%{install_libdir} %{buildroot}%{_libdir}
1787+
copy_with_relative_symlinks %{buildroot}%{install_libexecdir} %{buildroot}%{_libexecdir}
1788+
copy_with_relative_symlinks %{buildroot}%{install_includedir} %{buildroot}%{_includedir}
1789+
copy_with_relative_symlinks %{buildroot}%{install_datadir} %{buildroot}%{_datadir}
18021790
%endif
18031791

18041792
# ghost presence for llvm-config, managed by alternatives.
@@ -2315,58 +2303,6 @@ fi
23152303
%define expand_includes() %{expand_generic -d %{_includedir} -i %{install_includedir} %*}
23162304
%define expand_datas() %{expand_generic -d %{_datadir} -i %{install_datadir} %*}
23172305

2318-
2319-
# The pretrans_rpmmove_dirs macro exists for packages to replace directories
2320-
# with symbolic links which normally is not possible with RPM. The trick is to
2321-
# use the generated scriptlet below to rename existing directories before
2322-
# replacing them with a symbolic link.
2323-
#
2324-
# Make sure you call this macro at the end of a %%files section for a package.
2325-
# This macro will then automatically add the %%ghost entries for the moved
2326-
# paths for you.
2327-
#
2328-
# When building in compat mode, the pretrans_rpmmove_dirs macro does nothing.
2329-
#
2330-
# See this page for a detailed problem description:
2331-
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Directory_Replacement/
2332-
%if %{with compat_build}
2333-
%define pretrans_rpmmove_dirs(n:) %{nil}
2334-
%else
2335-
%define pretrans_rpmmove_dirs(n:) %{lua:
2336-
local packagename = string.gsub(rpm.expand("%{-n*}"), "%s*", "")
2337-
local paths_str = '"'..string.gsub(rpm.expand("%*"), "%s+", '",\\n"')
2338-
paths_str = string.sub(paths_str,0,-4)
2339-
2340-
for i = 1, rpm.expand("%#") do
2341-
print('%ghost '..string.gsub(rpm.expand([[%]]..i), "%s+", "")..'.rpmmoved\\n') \
2342-
end
2343-
2344-
print("\\n%pretrans -n " .. packagename .. " -p <lua> \\n")
2345-
print("local paths={\\n")
2346-
print(paths_str..'\\n')
2347-
print("}\\n")
2348-
print([[
2349-
for _, path in ipairs(paths) do
2350-
st = posix.stat(path)
2351-
if st and st.type == "directory" then
2352-
status = os.rename(path, path .. ".rpmmoved")
2353-
if not status then
2354-
suffix = 0
2355-
while not status do
2356-
suffix = suffix + 1
2357-
status = os.rename(path .. ".rpmmoved", path .. ".rpmmoved." .. suffix)
2358-
end
2359-
os.rename(path, path .. ".rpmmoved")
2360-
end
2361-
end
2362-
end
2363-
]])
2364-
-- Remove the following "end" and you'll get this error:
2365-
-- error: invalid syntax in lua scriptlet: [string "%pretrans"]:20: unexpected symbol near '#'
2366-
print("\\n%end")
2367-
}
2368-
%endif
2369-
23702306
#region LLVM lit files
23712307
%if %{with python_lit}
23722308
%files -n python%{python3_pkgversion}-lit
@@ -2537,10 +2473,6 @@ print("\\n%end")
25372473

25382474
%expand_datas opt-viewer
25392475

2540-
%{pretrans_rpmmove_dirs -n %{pkg_name_llvm}
2541-
%{_datadir}/opt-viewer
2542-
}
2543-
25442476
%files -n %{pkg_name_llvm}-libs
25452477
%license llvm/LICENSE.TXT
25462478
%{expand_libs %{expand:
@@ -2579,12 +2511,6 @@ print("\\n%end")
25792511
cmake/llvm
25802512
}}
25812513

2582-
%{pretrans_rpmmove_dirs -n %{pkg_name_llvm}-devel
2583-
%{_includedir}/llvm-c
2584-
%{_includedir}/llvm
2585-
%{_libdir}/cmake/llvm
2586-
}
2587-
25882514
%files -n %{pkg_name_llvm}-doc
25892515
%license llvm/LICENSE.TXT
25902516
%doc %{_pkgdocdir}/html/index.html
@@ -2624,11 +2550,6 @@ print("\\n%end")
26242550
}}
26252551
%expand_includes llvm-gtest llvm-gmock
26262552

2627-
%{pretrans_rpmmove_dirs -n %{pkg_name_llvm}-googletest
2628-
%{_includedir}/llvm-gmock
2629-
%{_includedir}/llvm-gtest
2630-
}
2631-
26322553
%if %{with snapshot_build}
26332554
%files -n %{pkg_name_llvm}-build-stats
26342555
%{_datadir}/.ninja_log
@@ -2686,16 +2607,9 @@ print("\\n%end")
26862607
%expand_bins clang-tblgen
26872608
%dir %{install_datadir}/clang/
26882609
%if %{without compat_build}
2689-
%{_datadir}/clang
2610+
%dir %{_datadir}/clang
26902611
%endif
26912612

2692-
%{pretrans_rpmmove_dirs -n %{pkg_name_clang}-devel
2693-
%{_includedir}/clang-c
2694-
%{_includedir}/clang
2695-
%{_libdir}/cmake/clang
2696-
%{_datadir}/clang
2697-
}
2698-
26992613
%files -n %{pkg_name_clang}-resource-filesystem
27002614
%license clang/LICENSE.TXT
27012615
%dir %{_prefix}/lib/clang/
@@ -2730,11 +2644,6 @@ print("\\n%end")
27302644
%{python3_sitelib}/libscanbuild
27312645
%endif
27322646

2733-
%{pretrans_rpmmove_dirs -n %{pkg_name_clang}-analyzer
2734-
%{_datadir}/scan-build
2735-
%{_datadir}/scan-view
2736-
}
2737-
27382647
%files -n %{pkg_name_clang}-tools-extra
27392648
%license clang-tools-extra/LICENSE.TXT
27402649
%{expand_bins %{expand:
@@ -2784,25 +2693,22 @@ print("\\n%end")
27842693
%{_emacs_sitestartdir}/clang-include-fixer.el
27852694
%endif
27862695
%expand_mans diagtool extraclangtools
2787-
# Do not use expand_datas here, as we'll create a symlink for the clang dir.
2788-
%{install_datadir}/clang/clang-format.py*
2789-
%{install_datadir}/clang/clang-format-diff.py*
2790-
%{install_datadir}/clang/clang-include-fixer.py*
2791-
%{install_datadir}/clang/clang-tidy-diff.py*
2792-
%{install_datadir}/clang/run-find-all-symbols.py*
2696+
%{expand_datas %{expand:
2697+
clang/clang-format.py*
2698+
clang/clang-format-diff.py*
2699+
clang/clang-include-fixer.py*
2700+
clang/clang-tidy-diff.py*
2701+
clang/run-find-all-symbols.py*
2702+
}}
27932703
%if %{maj_ver} < 20
2794-
%{install_datadir}/clang/clang-rename.py*
2704+
%expand_datas /clang/clang-rename.py*
27952705
%endif
27962706

27972707

27982708
%files -n %{pkg_name_clang}-tools-extra-devel
27992709
%license clang-tools-extra/LICENSE.TXT
28002710
%expand_includes clang-tidy
28012711

2802-
%{pretrans_rpmmove_dirs -n %{pkg_name_clang}-tools-extra-devel
2803-
%{_includedir}/clang-tidy
2804-
}
2805-
28062712
%files -n git-clang-format%{pkg_suffix}
28072713
%license clang/LICENSE.TXT
28082714
%expand_bins git-clang-format
@@ -2892,12 +2798,6 @@ print("\\n%end")
28922798
%expand_includes offload
28932799
%endif
28942800
%endif
2895-
2896-
%{pretrans_rpmmove_dirs -n %{pkg_name_libomp}-devel
2897-
%{_includedir}/offload
2898-
%{_libdir}/cmake/openmp
2899-
}
2900-
29012801
#endregion OPENMP files
29022802

29032803
#region LLD files
@@ -2927,11 +2827,6 @@ print("\\n%end")
29272827
cmake/lld
29282828
}}
29292829

2930-
%{pretrans_rpmmove_dirs -n %{pkg_name_lld}-devel
2931-
%{_includedir}/lld
2932-
%{_libdir}/cmake/lld
2933-
}
2934-
29352830
%files -n %{pkg_name_lld}-libs
29362831
%license lld/LICENSE.TXT
29372832
%{expand_libs %{expand:
@@ -2978,10 +2873,6 @@ print("\\n%end")
29782873
%files -n %{pkg_name_lldb}-devel
29792874
%expand_includes lldb
29802875

2981-
%{pretrans_rpmmove_dirs -n %{pkg_name_lldb}-devel
2982-
%{_includedir}/lldb
2983-
}
2984-
29852876
%files -n python%{python3_pkgversion}-lldb
29862877
%{python3_sitearch}/lldb
29872878
%endif
@@ -3036,12 +2927,6 @@ print("\\n%end")
30362927
libMLIR*.so
30372928
}}
30382929

3039-
%{pretrans_rpmmove_dirs -n %{pkg_name_mlir}-devel
3040-
%{_includedir}/mlir-c
3041-
%{_includedir}/mlir
3042-
%{_libdir}/cmake/mlir
3043-
}
3044-
30452930
%files -n python%{python3_pkgversion}-%{pkg_name_mlir}
30462931
%{python3_sitearch}/mlir/
30472932
%endif
@@ -3140,18 +3025,16 @@ print("\\n%end")
31403025
%expand_includes polly
31413026
%expand_libs cmake/polly
31423027

3143-
%{pretrans_rpmmove_dirs -n %{pkg_name_polly}-devel
3144-
%{_includedir}/polly
3145-
%{_libdir}/cmake/polly
3146-
}
3147-
31483028
%endif
31493029
#endregion polly files
31503030

31513031
#endregion files
31523032

31533033
#region changelog
31543034
%changelog
3035+
* Tue Feb 04 2025 Nikita Popov <[email protected]> - 19.1.7-6
3036+
- Don't use directory symlinks
3037+
31553038
* Fri Jan 31 2025 Konrad Kleine <[email protected]> - 19.1.7-5
31563039
- Address installability issue with directories that were turned into symlinks
31573040

0 commit comments

Comments
 (0)