Get original host archtecture not the one of KVM container sandbox/chanleebf/host_arch
authorChan Lee <chan45.lee@samsung.com>
Thu, 1 Dec 2016 01:23:45 +0000 (10:23 +0900)
committerChan Lee <chan45.lee@samsung.com>
Thu, 1 Dec 2016 02:41:45 +0000 (11:41 +0900)
‘uname -m’ inside KVM container returns target build architecture
but not the build host one (it’s done by qemu-user).
So we can prepare statically linked binary to get original host
archtecture.

This patch is writen by Pavel Kopyl(p.kopyl@samsung.com).

Change-Id: I3f82e6782d02a9a7a80d333add3b50caa8f23774
Signed-off-by: Chan Lee <chan45.lee@samsung.com>
Build.pm
Makefile
debian/rules
host_arch.c [new file with mode: 0644]
packaging/build.spec

index 4277c4653e0405180a4a852a2b4d44768c75659c..9ad2ca0ac9962293ff92ac8ff26e0c5e6f91ff71 100644 (file)
--- a/Build.pm
+++ b/Build.pm
@@ -24,6 +24,7 @@ use strict;
 use Digest::MD5;
 use Build::Rpm;
 use Data::Dumper;
+use File::Basename;
 
 our $expand_dbg;
 
@@ -174,7 +175,8 @@ sub read_config_dist {
 }
 
 sub get_hostarch {
-       my $hostarch = `uname -m` || 'i586';
+       my $dirname = dirname(__FILE__);
+       my $hostarch = `$dirname/host_arch` || 'i586';
        return $hostarch;
 }
 
index 346a9086cc17d0ed70ab0d8babe415620668b4b4..44e5e9b7a052c2afac635c0fdfd036a97f9d5aa4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -91,6 +91,16 @@ initvm-install: initvm
        install -m755 -d $(DESTDIR)$(pkglibdir)
        install -m755 initvm.$(INITVM_ARCH) $(DESTDIR)$(pkglibdir)/initvm.$(INITVM_ARCH)
 
+host_arch: host_arch.c
+       $(CC) -o $@ -static $(CFLAGS) host_arch.c
+
+host_arch-all: host_arch
+
+host_arch-build: host_arch
+
+host_arch-install: host_arch
+       install -m755 -d $(DESTDIR)$(pkglibdir)
+       install -m755 host_arch $(DESTDIR)$(pkglibdir)/host_arch
 
 dist:
 ifeq ($(SCM),svn)
index bae842204541b52457d3b529b3a815a378a0fde2..214507864d810175f823f625077f9a0b90bd5ffc 100755 (executable)
@@ -25,6 +25,7 @@ configure-stamp:
 
 build: build-stamp
        make initvm-all
+       make host_arch-all
 build-stamp: configure-stamp
        dh_testdir
        touch build-stamp
@@ -43,6 +44,8 @@ install: build
        dh_installdirs
        make DESTDIR=$(CURDIR)/debian/build initvm-install
        chmod 0644 $(CURDIR)/debian/build/usr/lib/build/initvm.*
+       make DESTDIR=$(CURDIR)/debian/build host_arch-install
+       chmod 0644 $(CURDIR)/debian/build/usr/lib/build/host_arch
        make DESTDIR=$(CURDIR)/debian/build install
 
 binary-arch: build install
diff --git a/host_arch.c b/host_arch.c
new file mode 100644 (file)
index 0000000..362c6bf
--- /dev/null
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/utsname.h>
+
+int main(void) {
+
+       struct utsname buffer;
+
+       errno = 0;
+       if (uname(&buffer) != 0) {
+               perror("uname");
+               exit(EXIT_FAILURE);
+       }
+
+       printf("%s\n", buffer.machine);
+
+       return EXIT_SUCCESS;
+}
+
index 5659cb83309108f3169b465100eeb9877ed97500..9434c582a156a7d29d91d38f3d4f95ee68f4a838 100644 (file)
@@ -36,6 +36,11 @@ BuildRoot:      %{_tmppath}/%{name}-%{version}-build
 AutoReqProv:    off
 # Keep the following dependencies in sync with obs-worker package
 BuildRequires:  glibc-devel
+%if 0%{?suse_version}
+BuildRequires:  glibc-devel-static
+%else
+BuildRequires:  glibc-static
+%endif
 Requires:       bash
 Requires:       perl
 Requires:       binutils
@@ -134,6 +139,8 @@ chroot or a secure virtualized
 %build
 # initvm
 make CFLAGS="$RPM_BUILD_FLAGS" initvm-all
+# host_arch
+make CFLAGS="$RPM_BUILD_FLAGS" host_arch-all
 
 %if 0%{?fedora} == 23
 %global debug_package %{nil}
@@ -145,6 +152,11 @@ make DESTDIR=$RPM_BUILD_ROOT initvm-install
 strip $RPM_BUILD_ROOT/usr/lib/build/initvm.*
 export NO_BRP_STRIP_DEBUG="true"
 chmod 0644 $RPM_BUILD_ROOT/usr/lib/build/initvm.*
+# host_arch
+make DESTDIR=$RPM_BUILD_ROOT host_arch-install
+strip $RPM_BUILD_ROOT/usr/lib/build/host_arch
+export NO_BRP_STRIP_DEBUG="true"
+chmod 0644 $RPM_BUILD_ROOT/usr/lib/build/host_arch
 
 # main
 make DESTDIR=$RPM_BUILD_ROOT install