github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/consensus/poet/sgx/setup.py (about) 1 # Copyright 2017 Intel Corporation 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # ------------------------------------------------------------------------------ 15 16 import os 17 import shutil 18 import subprocess 19 import sys 20 import sysconfig 21 22 from setuptools import setup, Extension, find_packages 23 from distutils.command import build as build_module 24 from shutil import copyfile 25 26 script_dir = os.path.dirname(os.path.realpath(__file__)) 27 28 29 if os.name == 'nt': 30 platform_dir = 'windows' 31 package_data = [] 32 33 ext_deps = ['deps/bin/libpoet-bridge.dll', 34 'deps/bin/libpoet-enclave.signed.dll', 35 'deps/bin/msvcp110.dll', 36 'deps/bin/msvcr110.dll'] 37 for f in ext_deps: 38 package_data.append(os.path.basename(f)) 39 extra_compile_args = ['/EHsc'] 40 libraries = ['json-c', 'cryptopp-static', 'libpoet-bridge'] 41 include_dirs = ['deps/include'] 42 43 else: 44 platform_dir = 'linux' 45 extra_compile_args = ['-std=c++11'] 46 libraries = ['json-c', 'crypto++', 'poet-bridge'] 47 ext_deps = ['deps/bin/libpoet-bridge.so', 48 'deps/bin/libpoet-enclave.signed.so'] 49 package_data = [] 50 include_dirs = [] 51 52 include_dirs += ['sawtooth_poet_sgx/poet_enclave_sgx', 53 'sawtooth_poet_sgx/poet_enclave_sgx/{}'.format(platform_dir), 54 'sawtooth_poet_sgx/libpoet_shared', 55 'sawtooth_poet_sgx/libpoet_shared/{}'.format(platform_dir), 56 '../common/c11_support', 57 '../common/c11_support/{}'.format(platform_dir)] 58 library_dirs = ['deps/lib'] 59 60 enclavemod = Extension( 61 '_poet_enclave', 62 ['sawtooth_poet_sgx/poet_enclave_sgx/poet_enclave.i', 63 'sawtooth_poet_sgx/poet_enclave_sgx/common.cpp', 64 'sawtooth_poet_sgx/poet_enclave_sgx/poet.cpp', 65 'sawtooth_poet_sgx/poet_enclave_sgx/wait_certificate.cpp', 66 'sawtooth_poet_sgx/poet_enclave_sgx/wait_timer.cpp', 67 'sawtooth_poet_sgx/poet_enclave_sgx/signup_data.cpp', 68 'sawtooth_poet_sgx/poet_enclave_sgx/signup_info.cpp', 69 'sawtooth_poet_sgx/poet_enclave_sgx/{}/platform_support.cpp'.format( 70 platform_dir)], 71 swig_opts=['-c++'], 72 extra_compile_args=extra_compile_args, include_dirs=include_dirs, 73 libraries=libraries, library_dirs=library_dirs) 74 75 76 class Build(build_module.build): 77 def build_poet(self): 78 print('Building PoET SGX module') 79 if not os.path.exists("build"): 80 os.mkdir("build") 81 os.chdir("build") 82 83 if os.name == 'nt': 84 args = ["-G", "Visual Studio 11 2012 Win64"] 85 else: 86 args = ["-G", "Unix Makefiles"] 87 88 subprocess.call(["cmake", ".."] + args) 89 90 if os.name == 'nt': 91 args = ["--config", "Release"] 92 else: 93 args = [] 94 95 subprocess.call(["cmake", "--build", "."] + args) 96 97 os.chdir("..") 98 99 for fl in ext_deps: 100 dst = os.path.join(script_dir, os.path.basename(fl)) 101 copyfile(fl, dst) 102 package_data.append(os.path.basename(fl)) 103 104 def run(self): 105 self.build_poet() 106 build_module.build.run(self) 107 108 109 if os.name == 'nt': 110 conf_dir = "C:\\Program Files (x86)\\Intel\\sawtooth\\conf" 111 else: 112 conf_dir = "/etc/sawtooth" 113 114 setup(name='sawtooth-poet-sgx', 115 version=subprocess.check_output( 116 ['../../../bin/get_version']).decode('utf-8').strip(), 117 description='Sawtooth PoET SGX Enclave', 118 author='Hyperledger Sawtooth', 119 url='http://www.intel.com', 120 packages=find_packages(), 121 install_requires=[ 122 'toml', 123 'sawtooth-ias-client', 124 'sawtooth-poet-common' 125 ], 126 ext_modules=[enclavemod], 127 py_modules=['sawtooth_poet_sgx.poet_enclave_sgx.poet_enclave'], 128 data_files=[ 129 ('lib', package_data), 130 (conf_dir, ['packaging/ias_rk_pub.pem', 131 'packaging/poet_enclave_sgx.toml.example'])], 132 cmdclass={'build': Build}, 133 entry_points={} 134 ) 135 136 if "clean" in sys.argv and "--all" in sys.argv: 137 directory = os.path.dirname(os.path.realpath(__file__)) 138 for root, fn_dir, files in os.walk(directory): 139 for fn in files: 140 if fn.endswith(".pyc"): 141 os.remove(os.path.join(root, fn)) 142 for filename in [".coverage", 143 "_poet_enclave{}".format( 144 sysconfig.get_config_var('EXT_SUFFIX')), 145 "libpoet-bridge.so", 146 "libpoet-enclave.signed.so", 147 os.path.join( 148 "sawtooth_poet_sgx", 149 "poet_enclave_sgx", 150 "poet_enclave.py"), 151 os.path.join( 152 "sawtooth_poet_sgx", 153 "poet_enclave_sgx", 154 "poet_enclave_wrap.cpp"), 155 "nose2-junit.xml"]: 156 if os.path.exists(os.path.join(directory, filename)): 157 os.remove(os.path.join(directory, filename)) 158 shutil.rmtree(os.path.join(directory, "build"), ignore_errors=True) 159 shutil.rmtree(os.path.join(directory, "htmlcov"), ignore_errors=True) 160 shutil.rmtree(os.path.join(directory, "deb_dist"), ignore_errors=True)