Skip to content

Commit 2d1583e

Browse files
author
MarcoFalke
committed
Merge #15236: scripts and tools: Make --setup command independent
e0eae1b Make --setup command independent (Hennadii Stepanov) Pull request description: This PR allows a user to run: ```sh ./gitian-build.py --setup ``` without unused `signer` and `version` options. In master the `signer` and `version` options are mandatory. This implies the following code is dead: https://github.com/bitcoin/bitcoin/blob/387eb5b34307448f16d3769ac0245c4e3d996a38/contrib/gitian-build.py#L192-L200 This PR fixes those lines of code. Also this PR has a nice side effect: there is no more warnings about macOS build during processing `--setup` command. Ref: bitcoin/bitcoin#13998 (comment) Note: https://github.com/bitcoin-core/docs/blob/master/gitian-building.md will be updated when this PR is merged. ACKs for commit e0eae1: Tree-SHA512: df851fe461e402229c57b410f30f1d8bc816e8a2600ece4249aa39c763566de5b661e7aa0af171d484727eb463a6d0e10cfcf459aa60ae1a5d4e12974a8615c6
2 parents f49b8d4 + e0eae1b commit 2d1583e

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

contrib/gitian-build.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def verify():
152152
def main():
153153
global args, workdir
154154

155-
parser = argparse.ArgumentParser(usage='%(prog)s [options] signer version')
155+
parser = argparse.ArgumentParser(description='Script for running full Gitian builds.')
156156
parser.add_argument('-c', '--commit', action='store_true', dest='commit', help='Indicate that the version argument is for a commit or branch')
157157
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')
158158
parser.add_argument('-u', '--url', dest='url', default='https://github.com/bitcoin/bitcoin', help='Specify the URL of the repository. Default is %(default)s')
@@ -168,27 +168,17 @@ def main():
168168
parser.add_argument('-S', '--setup', action='store_true', dest='setup', help='Set up the Gitian building environment. Only works on Debian-based systems (Ubuntu, Debian)')
169169
parser.add_argument('-D', '--detach-sign', action='store_true', dest='detach_sign', help='Create the assert file for detached signing. Will not commit anything.')
170170
parser.add_argument('-n', '--no-commit', action='store_false', dest='commit_files', help='Do not commit anything to git')
171-
parser.add_argument('signer', help='GPG signer to sign each build assert file')
172-
parser.add_argument('version', help='Version number, commit, or branch to build. If building a commit or branch, the -c option must be specified')
171+
parser.add_argument('signer', nargs='?', help='GPG signer to sign each build assert file')
172+
parser.add_argument('version', nargs='?', help='Version number, commit, or branch to build. If building a commit or branch, the -c option must be specified')
173173

174174
args = parser.parse_args()
175175
workdir = os.getcwd()
176176

177-
args.linux = 'l' in args.os
178-
args.windows = 'w' in args.os
179-
args.macos = 'm' in args.os
180-
181177
args.is_bionic = b'bionic' in subprocess.check_output(['lsb_release', '-cs'])
182178

183-
if args.buildsign:
184-
args.build = True
185-
args.sign = True
186-
187179
if args.kvm and args.docker:
188180
raise Exception('Error: cannot have both kvm and docker')
189181

190-
args.sign_prog = 'true' if args.detach_sign else 'gpg --detach-sign'
191-
192182
# Ensure no more than one environment variable for gitian-builder (USE_LXC, USE_VBOX, USE_DOCKER) is set as they
193183
# can interfere (e.g., USE_LXC being set shadows USE_DOCKER; for details see gitian-builder/libexec/make-clean-vm).
194184
os.environ['USE_LXC'] = ''
@@ -203,19 +193,34 @@ def main():
203193
if 'LXC_GUEST_IP' not in os.environ.keys():
204194
os.environ['LXC_GUEST_IP'] = '10.0.3.5'
205195

196+
if args.setup:
197+
setup()
198+
199+
if args.buildsign:
200+
args.build = True
201+
args.sign = True
202+
203+
if not args.build and not args.sign and not args.verify:
204+
sys.exit(0)
205+
206+
args.linux = 'l' in args.os
207+
args.windows = 'w' in args.os
208+
args.macos = 'm' in args.os
209+
206210
# Disable for MacOS if no SDK found
207211
if args.macos and not os.path.isfile('gitian-builder/inputs/MacOSX10.11.sdk.tar.gz'):
208212
print('Cannot build for MacOS, SDK does not exist. Will build for other OSes')
209213
args.macos = False
210214

215+
args.sign_prog = 'true' if args.detach_sign else 'gpg --detach-sign'
216+
211217
script_name = os.path.basename(sys.argv[0])
212-
# Signer and version shouldn't be empty
213-
if args.signer == '':
214-
print(script_name+': Missing signer.')
218+
if not args.signer:
219+
print(script_name+': Missing signer')
215220
print('Try '+script_name+' --help for more information')
216221
sys.exit(1)
217-
if args.version == '':
218-
print(script_name+': Missing version.')
222+
if not args.version:
223+
print(script_name+': Missing version')
219224
print('Try '+script_name+' --help for more information')
220225
sys.exit(1)
221226

@@ -224,9 +229,6 @@ def main():
224229
raise Exception('Cannot have both commit and pull')
225230
args.commit = ('' if args.commit else 'v') + args.version
226231

227-
if args.setup:
228-
setup()
229-
230232
os.chdir('bitcoin')
231233
if args.pull:
232234
subprocess.check_call(['git', 'fetch', args.url, 'refs/pull/'+args.version+'/merge'])

0 commit comments

Comments
 (0)