OmniROM:“Flex checkpolicy”出错

96
爱拼安小匠
2018.09.10 23:24* 字数 229

编译OmniROM 8.1时,在这个地方出错:

[ 21% 2441/11398] //external/selinux/checkpolicy:checkpolicy lex policy_scan.l [linux]
FAILED: /home/anclark/Wonderland/aosp3/omni8/out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/linux_x86_64/gen/lex/external/selinux/checkpolicy/policy_scan.c 
prebuilts/misc/linux-x86/flex/flex-2.5.39 -o/home/anclark/Wonderland/aosp3/omni8/out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/linux_x86_64/gen/lex/external/selinux/checkpolicy/policy_scan.c external/selinux/checkpolicy/policy_scan.l
flex-2.5.39: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed.
Aborted (core dumped)

其中涉及到了Flex这款语法解释器生成器(lexical analyser generator),它的作用是将以*.l为扩展名的源文件编译成解释器的C语言代码。checkpolicy这个用于检测SELinux策略(SELinux policy)的工具,正是使用flex来解析策略文件的语法的。

Android Ninja编译系统的好处是,会将出错的命令记录在屏幕上。拷贝上述出错的命令,重新执行:

prebuilts/misc/linux-x86/flex/flex-2.5.39 -o/home/anclark/Wonderland/aosp3/omni8/out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/linux_x86_64/gen/lex/external/selinux/checkpolicy/policy_scan.c external/selinux/checkpolicy/policy_scan.l

发现问题依旧。

于是,笔者试着更换一个Flex版本,以apt安装的版本2.6.4sudo apt install flex)尝试编译:

flex -o/home/anclark/Wonderland/aosp3/omni8/out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/linux_x86_64/gen/lex/external/selinux/checkpolicy/policy_scan.c external/selinux/checkpolicy/policy_scan.l

结果成功!

看来,问题就出在OmniROM源码附带的Flex2.5.39版本里。

暂时使用符号链接,将OmniROM自带的Flex更换为apt的最新版:

ln -s /usr/bin/flex prebuilts/misc/linux-x86/flex/flex-2.5.39
Android 适配笔记