packaging: Add support for %run_tests_on_device
[platform/upstream/glibc.git] / packaging / glibc.spec
index e08d04a..0782863 100644 (file)
 %define glibc_run_tests 1
 %endif
 
+# Enable this when testing on device to:
+# 1. Enable macro to turn on testsuite building ('glibc_run_tests 1')
+# 2. Keep 'build-dir/' folder in build stage as we do not want to rebuild all
+# glibc again on device after invoking rpmbuild --short-circuit -bc ...
+# 3. Skip configure and make commands and go directly to 'make check'
+%if 0%{?run_tests_on_device}
+%define glibc_run_tests 1
+%define glibc_keep_build_dir 1
+%define glibc_skip_configure 1
+%define glibc_skip_make 1
+%endif
+
+# Exit right after 'make ..' step to keep all object files produced by glibc build
+%if 0%{?exit_on_make_finish}
+%define glibc_exit_on_make_finish 1
+%endif
+
+%if 0%{?dump_configure}
+%define glibc_dump_configure 1
+%endif
+
 # This will avoid building some parts of glibc
 %define asan_arch x86_64 armv7l aarch64
 %bcond_with    fast_build
@@ -37,6 +58,9 @@ BuildRequires:  python3-base
 BuildRequires:  glibc-devel-static
 %endif
 }
+%if 0%{?glibc_dump_configure}
+BuildRequires: configure-dumper
+%endif
 #BuildRequires:  pkgconfig(systemd)
 %define _filter_GLIBC_PRIVATE 1
 %if %_target_cpu == "i686"
@@ -85,7 +109,7 @@ Source7:        bindresvport.blacklist
 Source8:        glibc_post_upgrade.c
 Source9:        glibc.rpmlintrc
 Source10:       baselibs.conf
-# For systemd 
+# For systemd
 Source1001:    glibc.manifest
 
 Requires(pre):  filesystem
@@ -234,8 +258,17 @@ ln -s --force /%{_lib}/libc-2.24.so /%{_lib}/libc.so.6
 %endif
 }
 
+%{?glibc_dump_configure:
+%package configure-dump
+Summary:       GNU Glibc configure dump
+License:       GPL-3.0+
+Group:         Development/Languages
+%description configure-dump
+This package contains dump of configure variables of Glibc
+}
+
 %prep
-%setup -n glibc-%{version} -q 
+%setup -n glibc-%{version} -q
 cp %{SOURCE1001} .
 
 %build
@@ -310,17 +343,21 @@ configure_and_build_glibc() {
        local dirname="$1"; shift
        local cflags="$1"; shift
        local addons="$1"; shift
+       %{!?glibc_keep_build_dir:
+         rm -rf "cc-$dirname"
+        }
        mkdir "cc-$dirname"
        cd "cc-$dirname"
        conf_cflags="$cflags -funwind-tables -fPIC"
        %{?asan: conf_cflags="$conf_cflags -DASAN_INIT_FIRST"}
-
+       %{?glibc_dump_configure:patch_configure.pl ..}
        profile="--disable-profile"
 %if %{build_profile}
         if [ "$dirname" = "base" ] ; then
            profile="--enable-profile"
        fi
 %endif
+%{!?glibc_skip_configure:
        CFLAGS="$conf_cflags" BUILD_CFLAGS="$conf_cflags" \
         CC="$BuildCC" CXX="$BuildCCplus"  ../configure \
                --prefix=%{_prefix} \
@@ -335,7 +372,7 @@ configure_and_build_glibc() {
 %ifnarch %{multiarcharches}
                --disable-multi-arch \
 %endif
-%ifarch %{ix86} x86_64 
+%ifarch %{ix86} x86_64
                --disable-mathvec \
 %endif
                --enable-kernel=%{enablekernel} \
@@ -343,9 +380,20 @@ configure_and_build_glibc() {
                --disable-nscd \
                --disable-experimental-malloc \
                libc_cv_cc_pie_default=yes
-       # explicitly set CFLAGS to use the full CFLAGS (not the reduced one for configure)
-       make %{?_smp_mflags} #CFLAGS="$cflags" BUILD_CFLAGS="$cflags"
+ }
+%{!?glibc_skip_make:
+       make %{?_smp_mflags}
+       %{?glibc_dump_configure:
+         dump_configure.pl .. . \
+                           --project glibc \
+                           --project-version %{version} \
+                           --out_db glibc-%{version}-%{release}-%_project-%_repository.db
+        }
+       %{?glibc_exit_on_make_finish:
+         exit 1
+        }
        cd ..
+ }
 }
 
 configure_flags="--prefix=/usr --without-cvs --without-selinux --enable-stackguard-randomization --enable-obsolete-rpc --disable-mathvec"
@@ -457,6 +505,10 @@ touch %{buildroot}%{_libdir}/gconv/gconv-modules.cache
 # Install base glibc
 make %{?_smp_mflags} install_root=%{buildroot} install -C cc-base
 
+%{?glibc_dump_configure:
+  install -D -m 0644 cc-base/glibc-%{version}-%{release}-%_project-%_repository.db %{buildroot}%{_datadir}/glibc-%{version}-%{release}-%_project-%_repository.db
+}
+
 install_optimized_variant() {
        local dirname="$1"; shift
        local subdir="$1"; shift
@@ -744,7 +796,7 @@ done
 %files devel
 %manifest %{name}.manifest
 %defattr(-,root,root)
-%license COPYING COPYING.LIB 
+%license COPYING COPYING.LIB
 %doc NEWS README
 %{_bindir}/rpcgen
 %{_includedir}/*
@@ -848,4 +900,10 @@ done
 %doc testresults/*
 }
 
+%{?glibc_dump_configure:
+%files configure-dump
+%manifest glibc.manifest
+%{_datadir}/glibc-%{version}-%{release}-%_project-%_repository.db
+}
+
 %docs_package