Browse Source

waf: add strip_on_install plugin from engine repository

pull/98/head
Alibek Omarov 3 years ago
parent
commit
d9c5b04c54
  1. 46
      scripts/waifulib/strip_on_install.py
  2. 11
      scripts/waifulib/xcompile.py
  3. 4
      wscript

46
scripts/waifulib/strip_on_install.py

@ -0,0 +1,46 @@
#! /usr/bin/env python
# Modified: Alibek Omarov <a1ba.omarov@gmail.com>
# Originally taken from Thomas Nagy's blogpost
"""
Strip executables upon installation
"""
import shutil, os
from waflib import Build, Utils, Context, Errors, Logs
def options(opt):
grp = opt.option_groups['install/uninstall options']
grp.add_option('--no-strip', dest='no_strip', action='store_true', default=False,
help='don\'t strip binaries. You must pass this flag to install command(default: False)')
def configure(conf):
if conf.env.DEST_BINFMT in ['elf', 'mac-o']:
conf.find_program('strip')
if not conf.env.STRIPFLAGS:
conf.env.STRIPFLAGS = os.environ['STRIPFLAGS'] if 'STRIPFLAGS' in os.environ else []
def copy_fun(self, src, tgt):
inst_copy_fun(self, src, tgt)
if self.generator.bld.options.no_strip:
return
if conf.env.DEST_BINFMT not in ['elf', 'mac-o']: # don't strip unknown formats or PE
return
if getattr(self.generator, 'link_task', None) and self.generator.link_task.outputs[0] in self.inputs:
cmd = self.env.STRIP + self.env.STRIPFLAGS + [tgt]
try:
if not self.generator.bld.progress_bar:
c1 = Logs.colors.NORMAL
c2 = Logs.colors.CYAN
Logs.info('%s+ strip %s%s%s', c1, c2, tgt, c2)
self.generator.bld.cmd_and_log(cmd, output=Context.BOTH, quiet=Context.BOTH)
except Errors.WafError as e:
print(e.stdout, e.stderr)
inst_copy_fun = Build.inst.copy_fun
Build.inst.copy_fun = copy_fun

11
scripts/waifulib/xcompile.py

@ -156,7 +156,7 @@ class Android:
toolchain_host += '-'
# Assuming we are building on x86
if sys.maxsize > 2**32:
if sys.maxsize > 2**32:
toolchain_host += 'x86_64'
else: toolchain_host += 'x86'
@ -187,6 +187,9 @@ class Android:
triplet = self.ndk_triplet() + '-'
return os.path.join(self.gen_gcc_toolchain_path(), 'bin', triplet)
def gen_binutils_path(self):
return os.path.join(self.gen_gcc_toolchain_path(), self.ndk_triplet(), 'bin')
def cc(self):
if self.is_host():
return 'clang'
@ -197,6 +200,11 @@ class Android:
return 'clang++'
return self.toolchain_path + ('clang++' if self.is_clang() else 'g++')
def strip(self):
if self.is_host():
return 'strip'
return os.path.join(self.gen_binutils_path(), 'strip')
def system_stl(self):
# TODO: proper STL support
return os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'system', 'include'))
@ -305,6 +313,7 @@ def configure(conf):
setattr(conf, 'android', android)
conf.environ['CC'] = android.cc()
conf.environ['CXX'] = android.cxx()
conf.environ['STRIP'] = android.strip()
conf.env.CFLAGS += android.cflags()
conf.env.CXXFLAGS += android.cflags()
conf.env.LINKFLAGS += android.linkflags()

4
wscript

@ -29,7 +29,7 @@ def options(opt):
opt.recurse('cl_dll dlls')
opt.load('xcompile compiler_cxx compiler_c clang_compilation_database')
opt.load('xcompile compiler_cxx compiler_c clang_compilation_database strip_on_install')
if sys.platform == 'win32':
opt.load('msvc msdev')
opt.load('reconfigure')
@ -68,7 +68,7 @@ def configure(conf):
conf.env.MSVC_TARGETS = ['x86'] # explicitly request x86 target for MSVC
if sys.platform == 'win32':
conf.load('msvc msdev')
conf.load('xcompile compiler_c compiler_cxx')
conf.load('xcompile compiler_c compiler_cxx strip_on_install')
if conf.env.DEST_OS2 == 'android':
conf.options.ALLOW64 = True

Loading…
Cancel
Save