packaging: Add support for %run_tests_on_device
[platform/upstream/glibc.git] / packaging / glibc.spec
index 8630731..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
@@ -268,18 +301,30 @@ echo "#define GITID \"%{git_id}\"" >> version.h
 #
 BuildFlags=$(echo %{optflags} | sed -e "s/-Wp,-D_FORTIFY_SOURCE=2//g" | sed -e "s/-ffast-math//" | sed -e "s/atom/i686/g" | sed -e "s/-fexceptions//" | sed -e "s/-fno-omit-frame-pointer//" )
 BuildFlags="$BuildFlags -O2 -g -U_FORTIFY_SOURCE"
-BuildFlags="$(echo $BuildFlags | sed -e 's#-fstack-protector##' -e 's#-ffortify=[0-9]*##')"
+BuildFlags="$(echo $BuildFlags | sed -e 's#-ffortify=[0-9]*##')"
+BuildFlags="$(echo $BuildFlags | sed -e 's#-fstack-protector-strong##')"
+BuildFlags="$(echo $BuildFlags | sed -e 's#-fstack-protector##')"
 BuildFlags="$(echo $BuildFlags | sed -e 's/-Wa,-mimplicit-it=thumb//g' | sed -e 's/-mthumb//g')"
 # Turn off all -Wformat enable flags as there are glibc tests that explicitly
 # append -Wno-format and with enabled Wformat options that produced warnings
 # that turns into errors. Remove -Wformat=1|2 or -Wformat-..-arg
 BuildFlags="$(echo $BuildFlags | sed -re 's/-Wformat((=[1-2])|((-\w+)+))?(\s|$)//g')"
 
+%ifarch %arm
+# Support DA build with armv8 cpu in 32bit mode: prevent Werror on sqrt function
+(echo ${BuildFlags} | grep '\-march=armv8') && BuildFlags="${BuildFlags} -Wno-error=unused-variable"
+%endif
+
 BuildCC="%__cc"
 BuildCCplus="%__cxx"
 add_ons=",libidn"
 
 BuildFlags="$BuildFlags -g"
+
+%ifarch %arm
+# Glibc must have both functions' implementations
+BuildFlags="$BuildFlags -U_LARGEFILE_SOURCE -U_LARGEFILE64_SOURCE -U_FILE_OFFSET_BITS"
+%endif
 %if %{disable_assert}
        BuildFlags="$BuildFlags -DNDEBUG=1"
 %endif
@@ -298,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 "}
-
+       %{?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} \
@@ -323,17 +372,28 @@ configure_and_build_glibc() {
 %ifnarch %{multiarcharches}
                --disable-multi-arch \
 %endif
-%ifarch %{ix86} x86_64 
+%ifarch %{ix86} x86_64
                --disable-mathvec \
 %endif
                --enable-kernel=%{enablekernel} \
                --enable-bind-now  --enable-obsolete-rpc \
                --disable-nscd \
                --disable-experimental-malloc \
-               libc_cv_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"
+               libc_cv_cc_pie_default=yes
+ }
+%{!?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"
@@ -348,6 +408,11 @@ build_asan() {
   unset CXXFLAGS
   unset CFLAGS
   unset LDFLAGS
+%ifarch %arm
+  # Glibc must have both functions' implementations
+  CPPFLAGS="-U_LARGEFILE_SOURCE -U_LARGEFILE64_SOURCE -U_FILE_OFFSET_BITS"
+%endif
+
   #chmod +x $HERE/asan-glibc-gcc-wrapper.py
   #build static wrapper, because we don't want asan to intercept allocators
   g++ -o gcc-wrapper gcc-wrapper.cc -O3 -funroll-loops -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-exceptions -static
@@ -356,6 +421,7 @@ build_asan() {
   mkdir -p $ASAN_BUILD
   cd $ASAN_BUILD
 #  CC=$HERE/asan-glibc-gcc-wrapper.py $GLIBC/configure $configure_flags
+  CPPFLAGS=$CPPFLAGS \
   CC=$HERE/gcc-wrapper $GLIBC/configure $configure_flags
 
   # Quick build - builds only libraries, but does not create symlinks.
@@ -439,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
@@ -726,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}/*
@@ -830,4 +900,10 @@ done
 %doc testresults/*
 }
 
+%{?glibc_dump_configure:
+%files configure-dump
+%manifest glibc.manifest
+%{_datadir}/glibc-%{version}-%{release}-%_project-%_repository.db
+}
+
 %docs_package