2015-08-08 01:41:26 +03:00
|
|
|
import os.path
|
2017-12-01 20:38:10 +03:00
|
|
|
import subprocess
|
|
|
|
import tempfile
|
2015-08-08 01:41:26 +03:00
|
|
|
from distutils.command.build import build as orig_build
|
|
|
|
from distutils.core import Command
|
|
|
|
|
|
|
|
from setuptools import Distribution
|
|
|
|
from setuptools import Extension
|
2015-08-08 01:40:26 +03:00
|
|
|
from setuptools import setup
|
2015-08-08 01:41:26 +03:00
|
|
|
from setuptools.command.install import install as orig_install
|
|
|
|
|
|
|
|
|
2016-05-15 08:04:19 +03:00
|
|
|
try:
|
|
|
|
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
|
|
|
|
|
|
|
|
class bdist_wheel(_bdist_wheel):
|
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
_bdist_wheel.finalize_options(self)
|
|
|
|
# Mark us as not a pure python package
|
|
|
|
self.root_is_pure = False
|
|
|
|
|
|
|
|
def get_tag(self):
|
|
|
|
python, abi, plat = _bdist_wheel.get_tag(self)
|
|
|
|
# We don't contain any python source
|
|
|
|
python, abi = 'py2.py3', 'none'
|
|
|
|
return python, abi, plat
|
|
|
|
except ImportError:
|
|
|
|
bdist_wheel = None
|
|
|
|
|
|
|
|
|
2015-08-08 01:41:26 +03:00
|
|
|
class ExeDistribution(Distribution):
|
|
|
|
c_executables = ()
|
|
|
|
|
|
|
|
|
|
|
|
class build(orig_build):
|
|
|
|
sub_commands = orig_build.sub_commands + [
|
|
|
|
('build_cexe', None),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class install(orig_install):
|
|
|
|
sub_commands = orig_install.sub_commands + [
|
|
|
|
('install_cexe', None),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class install_cexe(Command):
|
|
|
|
description = 'install C executables'
|
|
|
|
outfiles = ()
|
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
self.build_dir = self.install_dir = None
|
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
# this initializes attributes based on other commands' attributes
|
|
|
|
self.set_undefined_options('build', ('build_scripts', 'build_dir'))
|
|
|
|
self.set_undefined_options(
|
2019-07-15 20:44:20 +03:00
|
|
|
'install', ('install_scripts', 'install_dir'),
|
|
|
|
)
|
2015-08-08 01:41:26 +03:00
|
|
|
|
|
|
|
def run(self):
|
2015-09-18 21:08:49 +03:00
|
|
|
|
2015-08-08 01:41:26 +03:00
|
|
|
self.outfiles = self.copy_tree(self.build_dir, self.install_dir)
|
|
|
|
|
|
|
|
def get_outputs(self):
|
|
|
|
return self.outfiles
|
|
|
|
|
|
|
|
|
|
|
|
class build_cexe(Command):
|
|
|
|
description = 'build C executables'
|
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
self.build_scripts = None
|
|
|
|
self.build_temp = None
|
|
|
|
|
|
|
|
def finalize_options(self):
|
2015-08-10 19:32:56 +03:00
|
|
|
self.set_undefined_options(
|
|
|
|
'build',
|
|
|
|
('build_scripts', 'build_scripts'),
|
|
|
|
('build_temp', 'build_temp'),
|
|
|
|
)
|
2015-08-08 01:41:26 +03:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
# stolen and simplified from distutils.command.build_ext
|
|
|
|
from distutils.ccompiler import new_compiler
|
|
|
|
|
|
|
|
compiler = new_compiler(verbose=True)
|
|
|
|
|
2017-12-01 20:38:10 +03:00
|
|
|
print('supports -static... ', end='')
|
|
|
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.c') as f:
|
|
|
|
f.write('int main(void){}\n')
|
|
|
|
f.flush()
|
|
|
|
cmd = compiler.linker_exe + [f.name, '-static', '-o', os.devnull]
|
|
|
|
with open(os.devnull, 'wb') as devnull:
|
|
|
|
if not subprocess.call(cmd, stderr=devnull):
|
|
|
|
print('yes')
|
|
|
|
link_args = ['-static']
|
|
|
|
else:
|
|
|
|
print('no')
|
|
|
|
link_args = []
|
|
|
|
|
2015-08-08 01:41:26 +03:00
|
|
|
for exe in self.distribution.c_executables:
|
2017-12-01 20:38:10 +03:00
|
|
|
objects = compiler.compile(exe.sources, output_dir=self.build_temp)
|
2015-08-08 01:41:26 +03:00
|
|
|
compiler.link_executable(
|
|
|
|
objects,
|
|
|
|
exe.name,
|
|
|
|
output_dir=self.build_scripts,
|
2017-12-01 20:38:10 +03:00
|
|
|
extra_postargs=link_args,
|
2015-08-08 01:41:26 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
def get_outputs(self):
|
|
|
|
return [
|
|
|
|
os.path.join(self.build_scripts, exe.name)
|
|
|
|
for exe in self.distribution.c_executables
|
|
|
|
]
|
2015-08-08 01:40:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
setup(
|
|
|
|
name='dumb-init',
|
|
|
|
description='Simple wrapper script which proxies signals to a child',
|
2015-10-02 23:31:35 +03:00
|
|
|
version=open('VERSION').read().strip(),
|
2015-08-08 01:40:26 +03:00
|
|
|
author='Yelp',
|
2016-05-02 21:41:45 +03:00
|
|
|
url='https://github.com/Yelp/dumb-init/',
|
2015-08-08 01:40:26 +03:00
|
|
|
platforms='linux',
|
2017-12-01 20:38:10 +03:00
|
|
|
c_executables=[Extension('dumb-init', ['dumb-init.c'])],
|
2015-08-08 01:41:26 +03:00
|
|
|
cmdclass={
|
2016-05-15 08:04:19 +03:00
|
|
|
'bdist_wheel': bdist_wheel,
|
2015-08-08 01:41:26 +03:00
|
|
|
'build': build,
|
|
|
|
'build_cexe': build_cexe,
|
|
|
|
'install': install,
|
|
|
|
'install_cexe': install_cexe,
|
|
|
|
},
|
|
|
|
distclass=ExeDistribution,
|
2015-08-08 01:40:26 +03:00
|
|
|
)
|