Changeset View
Changeset View
Standalone View
Standalone View
contrib/gitian-build.py
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | def build(): | ||||
subprocess.check_call(['make', '-C', '../bitcoin-abc/depends', | subprocess.check_call(['make', '-C', '../bitcoin-abc/depends', | ||||
'download', 'SOURCES_PATH=' + os.getcwd() + '/cache/common']) | 'download', 'SOURCES_PATH=' + os.getcwd() + '/cache/common']) | ||||
if args.linux: | if args.linux: | ||||
print('\nCompiling ' + args.version + ' Linux') | print('\nCompiling ' + args.version + ' Linux') | ||||
subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'bitcoin='+args.commit, | subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'bitcoin='+args.commit, | ||||
'--url', 'bitcoin='+args.url, '../bitcoin-abc/contrib/gitian-descriptors/gitian-linux.yml']) | '--url', 'bitcoin='+args.url, '../bitcoin-abc/contrib/gitian-descriptors/gitian-linux.yml']) | ||||
subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version + | |||||
'-linux', '--destination', '../gitian.sigs/', '../bitcoin-abc/contrib/gitian-descriptors/gitian-linux.yml']) | |||||
os.makedirs('../' + base_output_dir + '/linux', exist_ok=True) | os.makedirs('../' + base_output_dir + '/linux', exist_ok=True) | ||||
subprocess.check_call( | subprocess.check_call( | ||||
'mv build/out/bitcoin-*.tar.gz ../' + base_output_dir + '/linux', shell=True) | 'mv build/out/bitcoin-*.tar.gz ../' + base_output_dir + '/linux', shell=True) | ||||
subprocess.check_call( | subprocess.check_call( | ||||
'mv build/out/src/bitcoin-*.tar.gz ../' + base_output_dir + '/src', shell=True) | 'mv build/out/src/bitcoin-*.tar.gz ../' + base_output_dir + '/src', shell=True) | ||||
if args.windows: | if args.windows: | ||||
print('\nCompiling ' + args.version + ' Windows') | print('\nCompiling ' + args.version + ' Windows') | ||||
subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'bitcoin='+args.commit, | subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'bitcoin='+args.commit, | ||||
'--url', 'bitcoin='+args.url, '../bitcoin-abc/contrib/gitian-descriptors/gitian-win.yml']) | '--url', 'bitcoin='+args.url, '../bitcoin-abc/contrib/gitian-descriptors/gitian-win.yml']) | ||||
subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version + | |||||
'-win-unsigned', '--destination', '../gitian.sigs/', '../bitcoin-abc/contrib/gitian-descriptors/gitian-win.yml']) | |||||
os.makedirs('../' + base_output_dir + '/win', exist_ok=True) | os.makedirs('../' + base_output_dir + '/win', exist_ok=True) | ||||
subprocess.check_call( | subprocess.check_call( | ||||
'mv build/out/bitcoin-*-win-unsigned.tar.gz inputs/', shell=True) | 'mv build/out/bitcoin-*-win-unsigned.tar.gz inputs/', shell=True) | ||||
subprocess.check_call( | subprocess.check_call( | ||||
'mv build/out/bitcoin-*.zip build/out/bitcoin-*.exe ../' + base_output_dir + '/win', shell=True) | 'mv build/out/bitcoin-*.zip build/out/bitcoin-*.exe ../' + base_output_dir + '/win', shell=True) | ||||
subprocess.check_call( | subprocess.check_call( | ||||
'mv build/out/src/bitcoin-*.tar.gz ../' + base_output_dir + '/src', shell=True) | 'mv build/out/src/bitcoin-*.tar.gz ../' + base_output_dir + '/src', shell=True) | ||||
if args.macos: | if args.macos: | ||||
print('\nCompiling ' + args.version + ' MacOS') | print('\nCompiling ' + args.version + ' MacOS') | ||||
subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'bitcoin='+args.commit, | subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'bitcoin='+args.commit, | ||||
'--url', 'bitcoin='+args.url, '../bitcoin-abc/contrib/gitian-descriptors/gitian-osx.yml']) | '--url', 'bitcoin='+args.url, '../bitcoin-abc/contrib/gitian-descriptors/gitian-osx.yml']) | ||||
subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version + | |||||
'-osx-unsigned', '--destination', '../gitian.sigs/', '../bitcoin-abc/contrib/gitian-descriptors/gitian-osx.yml']) | |||||
os.makedirs('../' + base_output_dir + '/osx', exist_ok=True) | os.makedirs('../' + base_output_dir + '/osx', exist_ok=True) | ||||
subprocess.check_call( | subprocess.check_call( | ||||
'mv build/out/bitcoin-*-osx-unsigned.tar.gz inputs/', shell=True) | 'mv build/out/bitcoin-*-osx-unsigned.tar.gz inputs/', shell=True) | ||||
subprocess.check_call( | subprocess.check_call( | ||||
'mv build/out/bitcoin-*.tar.gz build/out/bitcoin-*.dmg ../' + base_output_dir + '/osx', shell=True) | 'mv build/out/bitcoin-*.tar.gz build/out/bitcoin-*.dmg ../' + base_output_dir + '/osx', shell=True) | ||||
subprocess.check_call( | subprocess.check_call( | ||||
'mv build/out/src/bitcoin-*.tar.gz ../' + base_output_dir + '/src', shell=True) | 'mv build/out/src/bitcoin-*.tar.gz ../' + base_output_dir + '/src', shell=True) | ||||
os.chdir(workdir) | os.chdir(workdir) | ||||
def sign_build(): | |||||
global args, workdir | |||||
os.chdir('gitian-builder') | |||||
if args.linux: | |||||
print('\nSigning build ' + args.version + ' Linux') | |||||
subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version + | |||||
'-linux', '--destination', '../gitian.sigs/', '../bitcoin-abc/contrib/gitian-descriptors/gitian-linux.yml']) | |||||
if args.windows: | |||||
print('\nSigning build ' + args.version + ' Windows') | |||||
subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version + | |||||
'-win-unsigned', '--destination', '../gitian.sigs/', '../bitcoin-abc/contrib/gitian-descriptors/gitian-win.yml']) | |||||
if args.macos: | |||||
print('\nSigning build ' + args.version + ' MacOS') | |||||
subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version + | |||||
'-osx-unsigned', '--destination', '../gitian.sigs/', '../bitcoin-abc/contrib/gitian-descriptors/gitian-osx.yml']) | |||||
os.chdir(workdir) | |||||
if args.commit_files: | if args.commit_files: | ||||
print('\nCommitting '+args.version+' Unsigned Sigs\n') | print('\nCommitting '+args.version+' Unsigned Sigs\n') | ||||
os.chdir('gitian.sigs') | os.chdir('gitian.sigs') | ||||
subprocess.check_call( | subprocess.check_call( | ||||
['git', 'add', args.version+'-linux/'+args.signer]) | ['git', 'add', args.version+'-linux/'+args.signer]) | ||||
subprocess.check_call( | subprocess.check_call( | ||||
['git', 'add', args.version+'-win-unsigned/'+args.signer]) | ['git', 'add', args.version+'-win-unsigned/'+args.signer]) | ||||
subprocess.check_call( | subprocess.check_call( | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | def verify(): | ||||
os.chdir(workdir) | os.chdir(workdir) | ||||
def main(): | def main(): | ||||
global args, workdir | global args, workdir | ||||
num_cpus = multiprocessing.cpu_count() | num_cpus = multiprocessing.cpu_count() | ||||
parser = argparse.ArgumentParser(usage='%(prog)s [options] signer version') | parser = argparse.ArgumentParser(usage='%(prog)s [options] version') | ||||
parser.add_argument('-c', '--commit', action='store_true', dest='commit', | parser.add_argument('-c', '--commit', action='store_true', dest='commit', | ||||
help='Indicate that the version argument is for a commit or branch') | help='Indicate that the version argument is for a commit or branch') | ||||
parser.add_argument('-p', '--pull', action='store_true', dest='pull', | parser.add_argument('-p', '--pull', action='store_true', dest='pull', | ||||
help='Indicate that the version argument is the number of a github repository pull request') | help='Indicate that the version argument is the number of a github repository pull request') | ||||
parser.add_argument('-u', '--url', dest='url', default='https://github.com/Bitcoin-ABC/bitcoin-abc.git', | parser.add_argument('-u', '--url', dest='url', default='https://github.com/Bitcoin-ABC/bitcoin-abc.git', | ||||
help='Specify the URL of the repository. Default is %(default)s') | help='Specify the URL of the repository. Default is %(default)s') | ||||
parser.add_argument('-v', '--verify', action='store_true', | parser.add_argument('-v', '--verify', action='store_true', | ||||
dest='verify', help='Verify the Gitian build') | dest='verify', help='Verify the Gitian build') | ||||
parser.add_argument('-b', '--build', action='store_true', | parser.add_argument('-b', '--build', action='store_true', | ||||
dest='build', help='Do a Gitian build') | dest='build', help='Do a Gitian build') | ||||
parser.add_argument('-s', '--sign-binaries', action='store_true', dest='sign_binaries', | parser.add_argument('-s', '--signer', dest='signer', | ||||
help='Make signed binaries for Windows and MacOS') | help='GPG signer to sign each build assert file') | ||||
parser.add_argument('-i', '--sign-build', action='store_true', dest='sign_build', | |||||
help='Sign the build assert file. Must also set --signer. Default is to not sign the build assert file.') | |||||
parser.add_argument('-I', '--sign-binaries', action='store_true', dest='sign_binaries', | |||||
help='Make signed binaries for Windows and MacOS. Must also set --signer') | |||||
parser.add_argument('-o', '--os', dest='os', default='lwm', | parser.add_argument('-o', '--os', dest='os', default='lwm', | ||||
help='Specify which Operating Systems the build is for. Default is %(default)s. l for Linux, w for Windows, m for MacOS') | help='Specify which Operating Systems the build is for. Default is %(default)s. l for Linux, w for Windows, m for MacOS') | ||||
parser.add_argument('-j', '--jobs', dest='jobs', default=str(num_cpus), | parser.add_argument('-j', '--jobs', dest='jobs', default=str(num_cpus), | ||||
help='Number of processes to use. Default %(default)s') | help='Number of processes to use. Default %(default)s') | ||||
parser.add_argument('-m', '--memory', dest='memory', default='3500', | parser.add_argument('-m', '--memory', dest='memory', default='3500', | ||||
help='Memory to allocate in MiB. Default %(default)s') | help='Memory to allocate in MiB. Default %(default)s') | ||||
parser.add_argument('-k', '--kvm', action='store_true', | parser.add_argument('-k', '--kvm', action='store_true', | ||||
dest='kvm', help='Use KVM instead of LXC') | dest='kvm', help='Use KVM instead of LXC') | ||||
parser.add_argument('-d', '--docker', action='store_true', | parser.add_argument('-d', '--docker', action='store_true', | ||||
dest='docker', help='Use Docker instead of LXC') | dest='docker', help='Use Docker instead of LXC') | ||||
parser.add_argument('-S', '--setup', action='store_true', dest='setup', | parser.add_argument('-S', '--setup', action='store_true', dest='setup', | ||||
help='Set up the Gitian building environment. Uses LXC. If you want to use KVM, use the --kvm option. Only works on Debian-based systems (Ubuntu, Debian)') | help='Set up the Gitian building environment. Uses LXC. If you want to use KVM, use the --kvm option. Only works on Debian-based systems (Ubuntu, Debian)') | ||||
parser.add_argument('-D', '--detach-sign', action='store_true', dest='detach_sign', | parser.add_argument('-D', '--detach-sign', action='store_true', dest='detach_sign', | ||||
help='Create the assert file for detached signing. Will not commit anything.') | help='Create the assert file for detached signing. Will not commit anything.') | ||||
parser.add_argument('-n', '--no-commit', action='store_false', | parser.add_argument('-n', '--no-commit', action='store_false', | ||||
dest='commit_files', help='Do not commit anything to git') | dest='commit_files', help='Do not commit anything to git') | ||||
parser.add_argument( | parser.add_argument( | ||||
'signer', help='GPG signer to sign each build assert file') | |||||
parser.add_argument( | |||||
'version', help='Version number, commit, or branch to build. If building a commit or branch, the -c option must be specified') | 'version', help='Version number, commit, or branch to build. If building a commit or branch, the -c option must be specified') | ||||
args = parser.parse_args() | args = parser.parse_args() | ||||
workdir = os.getcwd() | workdir = os.getcwd() | ||||
args.linux = 'l' in args.os | args.linux = 'l' in args.os | ||||
args.windows = 'w' in args.os | args.windows = 'w' in args.os | ||||
args.macos = 'm' in args.os | args.macos = 'm' in args.os | ||||
Show All 17 Lines | elif not args.kvm: | ||||
os.environ['LXC_GUEST_IP'] = '10.0.3.5' | os.environ['LXC_GUEST_IP'] = '10.0.3.5' | ||||
# Disable for MacOS if no SDK found | # Disable for MacOS if no SDK found | ||||
if args.macos and not os.path.isfile('gitian-builder/inputs/MacOSX10.11.sdk.tar.gz'): | if args.macos and not os.path.isfile('gitian-builder/inputs/MacOSX10.11.sdk.tar.gz'): | ||||
print('Cannot build for MacOS, SDK does not exist. Will build for other OSes') | print('Cannot build for MacOS, SDK does not exist. Will build for other OSes') | ||||
args.macos = False | args.macos = False | ||||
script_name = os.path.basename(sys.argv[0]) | script_name = os.path.basename(sys.argv[0]) | ||||
# Signer and version shouldn't be empty | # Version shouldn't be empty | ||||
if args.signer == '': | |||||
print(script_name+': Missing signer.') | |||||
print('Try '+script_name+' --help for more information') | |||||
exit(1) | |||||
if args.version == '': | if args.version == '': | ||||
print(script_name+': Missing version.') | print(script_name+': Missing version.') | ||||
print('Try '+script_name+' --help for more information') | print('Try '+script_name+' --help for more information') | ||||
exit(1) | exit(1) | ||||
# Add leading 'v' for tags | # Add leading 'v' for tags | ||||
if args.commit and args.pull: | if args.commit and args.pull: | ||||
raise Exception('Cannot have both commit and pull') | raise Exception('Cannot have both commit and pull') | ||||
Show All 15 Lines | def main(): | ||||
print(args.commit) | print(args.commit) | ||||
subprocess.check_call(['git', 'fetch']) | subprocess.check_call(['git', 'fetch']) | ||||
subprocess.check_call(['git', 'checkout', args.commit]) | subprocess.check_call(['git', 'checkout', args.commit]) | ||||
os.chdir(workdir) | os.chdir(workdir) | ||||
if args.build: | if args.build: | ||||
build() | build() | ||||
if (args.sign_build or args.sign_binaries) and not args.signer: | |||||
print(script_name+': Missing signer.') | |||||
Fabien: Style nit: spaces around the operator | |||||
print('Try '+script_name+' --help for more information') | |||||
FabienUnsubmitted Not Done Inline ActionsDito Fabien: Dito | |||||
exit(1) | |||||
FabienUnsubmitted Not Done Inline Actionssys.exit(1) Fabien: `sys.exit(1)` | |||||
if args.sign_build: | |||||
sign_build() | |||||
if args.sign_binaries: | if args.sign_binaries: | ||||
sign_binaries() | sign_binaries() | ||||
if args.verify: | if args.verify: | ||||
verify() | verify() | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |
Style nit: spaces around the operator