From ed177fd767e885fcc1f36470ba6067e0dc506646 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 13 Oct 2023 14:04:56 -0700 Subject: [PATCH] Switch bootstrap.pl to Python. --- .gitignore | 3 +- tools/buildbot/bootstrap.pl | 86 ----------------------------- tools/buildbot/bootstrap.py | 98 +++++++++++++++++++++++++++++++++ tools/buildbot/buildconfig.json | 7 +++ 4 files changed, 106 insertions(+), 88 deletions(-) delete mode 100755 tools/buildbot/bootstrap.pl create mode 100644 tools/buildbot/bootstrap.py create mode 100644 tools/buildbot/buildconfig.json diff --git a/.gitignore b/.gitignore index c0e5edf5d4..23f431fe88 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,6 @@ LIB-Debug/ [Tt]humbs.db # AMBuild build directories -build*/ obj-*/ *~ *.rej @@ -39,4 +38,4 @@ obj-*/ objdir .vs/* -.vscode/* \ No newline at end of file +.vscode/* diff --git a/tools/buildbot/bootstrap.pl b/tools/buildbot/bootstrap.pl deleted file mode 100755 index 42ba61bb44..0000000000 --- a/tools/buildbot/bootstrap.pl +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/perl -# vim: set ts=2 sw=2 tw=99 noet: - -use strict; -use Cwd; -use File::Basename; -use File::Path; - -my ($myself, $path) = fileparse($0); -chdir($path); - -use FindBin; -use lib $FindBin::Bin; -require 'helpers.pm'; - -#Go back to tree root. -my ($result); -chdir(Build::PathFormat('../..')); -$result = `git submodule update --init --recursive`; -print "$result\n"; - -#Go back above build dir -chdir(Build::PathFormat('..')); - -#Get the source path. -our ($root) = getcwd(); - -my $trigger_file = 'build/tools/buildbot/trigger_full_rebuild'; -if (-f $trigger_file) { - my $trigger_mtime = (stat $trigger_file)[9]; - if (-f 'OUTPUT/.ambuild2/graph') { - my $graph_mtime = (stat 'OUTPUT/.ambuild2/graph')[9]; - if ($trigger_mtime > $graph_mtime) { - print "Trigger time $trigger_mtime > $graph_mtime, cleaning objdir...\n"; - rmtree('OUTPUT'); - } - } -} -if (!(-f 'OUTPUT/.ambuild2/graph') || !(-f 'OUTPUT/.ambuild2/vars')) { - rmtree('OUTPUT'); - mkdir('OUTPUT') or die("Failed to create output folder: $!\n"); -} -chdir('OUTPUT'); -my ($argn); -$argn = $#ARGV + 1; - -print "Attempting to reconfigure...\n"; - -my @conf_argv = ( - '--enable-optimize', - '--breakpad-dump', - '--no-color', - '--symbol-files' -); - -if ($^O =~ /darwin/) { - push(@conf_argv, '--hl2sdk-root=/Volumes/hgshare'); - push(@conf_argv, '--mms-path=/Users/builds/slaves/common/mmsource-master'); -} elsif ($^O =~ /linux/) { - push(@conf_argv, '--hl2sdk-root=/hgshare'); - push(@conf_argv, '--mms-path=/home/builds/common/mmsource-master'); -} elsif ($^O =~ /MSWin/) { - push(@conf_argv, '--hl2sdk-root=H:\\'); - push(@conf_argv, '--mms-path=D:\\Scripts\\common\\mmsource-master'); -} - -push(@conf_argv, '--targets=x86,x86_64'); -push(@conf_argv, '--sdks=all'); - -my $conf_args = join(' ', @conf_argv); - -if ($argn > 0 && $^O !~ /MSWin/) { - $result = `CC=$ARGV[0] CXX=$ARGV[1] python3 ../build/configure.py $conf_args`; -} else { - if ($^O =~ /MSWin/) { - $result = `C:\\Python38\\Python.exe ..\\build\\configure.py $conf_args`; - } else { - $result = `CC=clang CXX=clang python3 ../build/configure.py $conf_args`; - } -} -print "$result\n"; -if ($? != 0) { - die("Could not configure: $!\n"); -} - -exit(0); diff --git a/tools/buildbot/bootstrap.py b/tools/buildbot/bootstrap.py new file mode 100644 index 0000000000..7cf5365324 --- /dev/null +++ b/tools/buildbot/bootstrap.py @@ -0,0 +1,98 @@ +# vim: set sw=4 sts=4 ts=4 sw=99 et: +from contextlib import contextmanager +import argparse +import json +import os +import platform +import shutil +import subprocess + +@contextmanager +def Chdir(path): + old = os.getcwd() + os.chdir(path) + print('> cd {} # {}'.format(path, os.getcwd())) + try: + yield + finally: + os.chdir(old) + +def run_shell(argv, env = None): + if type(argv) is str: + print('> {}'.format(argv)) + shell = True + else: + print('> {}'.format(' '.join(argv))) + shell = False + try: + output = subprocess.check_output(argv, stderr = subprocess.STDOUT, env = env, shell = shell) + except subprocess.CalledProcessError as cpe: + if not shell: + print(cpe.output.decode('utf-8', 'ignore')) + raise + print(output.decode('utf-8', 'ignore')) + +def output_needs_cleaning(): + if not os.path.isdir('OUTPUT'): + return False + amb2_dir = os.path.join('OUTPUT', '.ambuild2') + if not os.path.exists(os.path.join(amb2_dir, 'graph')): + return True + if not os.path.exists(os.path.join(amb2_dir, 'vars')): + return True + return False + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--config', type = str, required = True, + help = 'Buildbot slave name') + parser.add_argument('--hl2sdk-root', type = str, required = True, + help = 'hl2sdk collection') + parser.add_argument('--python-cmd', type = str, required = True, + default = 'python3', + help = 'Python command') + parser.add_argument('--mms-path', type = str, required = True, + help = 'Metamod:Source path') + args = parser.parse_args() + + run_shell("git submodule update --init --recursive") + + source = os.getcwd() + + with open(os.path.join('tools', 'buildbot', 'buildconfig.json'), 'rt') as fp: + config_root = json.load(fp) + + config = config_root.get(args.config, {}) + + # Set build properties. + build_env = os.environ.copy() + for env_var in ['CC', 'CXX']: + if env_var not in config: + continue + build_env[env_var] = config[env_var] + + config_argv = [ + args.python_cmd, + os.path.join(source, 'configure.py'), + '--enable-optimize', + '--breakpad-dump', + '--no-color', + '--symbol-files', + '--targets=x86,x86_64', + '--sdks=all', + '--out=OUTPUT', + '--hl2sdk-root={}'.format(args.hl2sdk_root), + '--mms-path={}'.format(args.mms_path), + ] + + print("Attempting to reconfigure...") + + with Chdir('..'): + if output_needs_cleaning(): + shutil.rmtree('OUTPUT') + if not os.path.isdir('OUTPUT'): + os.makedirs('OUTPUT') + run_shell(config_argv, env = build_env) + +if __name__ == '__main__': + main() diff --git a/tools/buildbot/buildconfig.json b/tools/buildbot/buildconfig.json new file mode 100644 index 0000000000..eb0edd51c1 --- /dev/null +++ b/tools/buildbot/buildconfig.json @@ -0,0 +1,7 @@ +{ + "debian11": { + "CC": "clang-13", + "CXX": "clang++-13" + } +} +