minijail-tools: move constants.json from minijail
It makes more sense to keep constants.json in the minijail package, because that's where the tool that consumes it, compile_seccomp_policy, lives. By having it in this package, we can set it as the default location for compile_seccomp_policy, which means it shouldn't ever even need to be specified on the command line (although it still can be). And we can hook into the cross-compilation machinery to get it to automatically use the constants for the right architecture. I've also changed from generating constants.json by running a test program in qemu-user to generating it from LLVM IR, which will save a huge QEMU build dependency.
This commit is contained in:
parent
e63a5d0875
commit
eb38d95b8a
2 changed files with 29 additions and 21 deletions
|
@ -1,13 +1,4 @@
|
|||
{ stdenv, lib, fetchFromGitiles, glibc, libcap, qemu }:
|
||||
|
||||
let
|
||||
dumpConstants =
|
||||
if stdenv.buildPlatform == stdenv.hostPlatform then "./dump_constants"
|
||||
else if stdenv.hostPlatform.isAarch32 then "qemu-arm dump_constants"
|
||||
else if stdenv.hostPlatform.isAarch64 then "qemu-aarch64 dump_constants"
|
||||
else if stdenv.hostPlatform.isx86_64 then "qemu-x86_64 dump_constants"
|
||||
else throw "Unsupported host platform";
|
||||
in
|
||||
{ stdenv, lib, fetchFromGitiles, libcap }:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "minijail";
|
||||
|
@ -19,24 +10,15 @@ stdenv.mkDerivation rec {
|
|||
sha256 = "sha256-OpwzISZ5iZNQvJAX7UJJ4gELEaVfcQgY9cqMM0YvBzc=";
|
||||
};
|
||||
|
||||
nativeBuildInputs =
|
||||
lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) qemu;
|
||||
buildInputs = [ libcap ];
|
||||
|
||||
makeFlags = [ "ECHO=echo" "LIBDIR=$(out)/lib" ];
|
||||
dumpConstantsFlags = lib.optional (stdenv.hostPlatform.libc == "glibc")
|
||||
"LDFLAGS=-L${glibc.static}/lib";
|
||||
|
||||
postPatch = ''
|
||||
substituteInPlace Makefile --replace /bin/echo echo
|
||||
patchShebangs platform2_preinstall.sh
|
||||
'';
|
||||
|
||||
postBuild = ''
|
||||
make $makeFlags $buildFlags $dumpConstantsFlags dump_constants
|
||||
${dumpConstants} > constants.json
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
./platform2_preinstall.sh ${version} $out/include/chromeos
|
||||
|
||||
|
@ -47,7 +29,6 @@ stdenv.mkDerivation rec {
|
|||
cp -v *.pc $out/lib/pkgconfig
|
||||
cp -v libminijail.h scoped_minijail.h $out/include/chromeos
|
||||
cp -v minijail0 $out/bin
|
||||
cp -v constants.json $out/share/minijail
|
||||
'';
|
||||
|
||||
enableParallelBuilding = true;
|
||||
|
|
|
@ -1,9 +1,36 @@
|
|||
{ buildPythonApplication, lib, minijail }:
|
||||
{ lib, stdenv, buildPythonApplication, pkgsBuildTarget, python, minijail }:
|
||||
|
||||
let
|
||||
targetClang = pkgsBuildTarget.targetPackages.clangStdenv.cc;
|
||||
in
|
||||
|
||||
buildPythonApplication {
|
||||
pname = "minijail-tools";
|
||||
inherit (minijail) version src;
|
||||
|
||||
postPatch = ''
|
||||
substituteInPlace Makefile --replace /bin/echo echo
|
||||
'';
|
||||
|
||||
postConfigure = ''
|
||||
substituteInPlace tools/compile_seccomp_policy.py \
|
||||
--replace "'constants.json'" "'$out/share/constants.json'"
|
||||
'';
|
||||
|
||||
preBuild = ''
|
||||
make libconstants.gen.c libsyscalls.gen.c
|
||||
${targetClang}/bin/${targetClang.targetPrefix}cc -S -emit-llvm \
|
||||
libconstants.gen.c libsyscalls.gen.c
|
||||
${python.pythonForBuild.interpreter} tools/generate_constants_json.py \
|
||||
--output constants.json \
|
||||
libconstants.gen.ll libsyscalls.gen.ll
|
||||
'';
|
||||
|
||||
postInstall = ''
|
||||
mkdir -p $out/share
|
||||
cp -v constants.json $out/share/constants.json
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
homepage = "https://android.googlesource.com/platform/external/minijail/+/refs/heads/master/tools/";
|
||||
description = "A set of tools for minijail";
|
||||
|
|
Loading…
Reference in a new issue