Makefile.setup
author Justin Wood <Callek@gmail.com>
Wed, 09 May 2018 11:25:07 -0400
changeset 15764 41cb018a926beaddbecbd3649abb9e45792a92a1
parent 9791 7720318925fd03fbf83d75b5532cb8c7b3a53f05
permissions -rw-r--r--
Backed out changeset 99bed3302273

BASEDIR ?= $(shell pwd)
VIRTUALENV ?= virtualenv
PYTHON ?= /tools/python/bin/python
PIP_PACKAGES_FILE ?= master-pip.txt
HG ?= hg
HG_HOST = https://hg.mozilla.org
HG_DIR = build
MASTER_NAME = $(error MASTER_NAME must be defined (see setup-master.py -l for a list))
DATABASE = tm-b01-master01.mozilla.org/buildbot
MYSQL_CONFIG = $(HOME)/.$(MASTER_NAME)_update_from_files.conf
VIRTUALENV_PYTHON = $(BASEDIR)/bin/python
PIP = $(BASEDIR)/bin/pip
BUILDBOT = $(BASEDIR)/bin/buildbot
USER = cltbld
HOME = /home/$(USER)
BUILDBOT_BRANCH = production-0.8
BUILDBOTCUSTOM_BRANCH = production-0.8
BUILDBOTCONFIGS_BRANCH = production
TOOLS_BRANCH = default
TOOLS_REPO ?= $(HG_HOST)/$(HG_DIR)/tools
INSTALL_BUILDBOT_SLAVE=

# staging master setup
ifdef USE_DEV_MASTER
MASTERS_JSON = dev-master_config.json
HTTP_PORT = $(error HTTP_PORT must be defined)
PB_PORT = $(error PB_PORT must be defined)
SSH_PORT = $(error SSH_PORT must be defined)
ROLE = $(error ROLE must be defined)

GENERATE_MASTERS_JSON_CMD = \
    sed -e 's,@BASEDIR@,$(BASEDIR),g' \
        -e 's,@HTTP_PORT@,$(HTTP_PORT),g' \
        -e 's,@PB_PORT@,$(PB_PORT),g' \
        -e 's,@SSH_PORT@,$(SSH_PORT),g' \
        -e 's,@MASTER_NAME@,$(MASTER_NAME),g' \
        -e 's,@ROLE@,$(ROLE),g' \
        -e 's,@ROLE@,$(ROLE),g' \
        -e 's,@BUILDBOTCUSTOM_BRANCH@,$(BUILDBOTCUSTOM_BRANCH),g' \
        -e 's,@BUILDBOTCONFIGS_BRANCH@,$(BUILDBOTCONFIGS_BRANCH),g' \
        -e 's,@TOOLS_BRANCH@,$(TOOLS_BRANCH),g' \
        -e 's,@BUILDBOT_BRANCH@,$(BUILDBOT_BRANCH),g' \
        $(MASTERS_JSON).in > $(MASTERS_JSON)
endif

ifdef UNIVERSAL
UNIVERSAL_OPT=-u
else
UNIVERSAL_OPT=
endif

ifdef MASTERS_JSON
SETUP_MASTER=setup-master.py -j $(MASTERS_JSON)
else
SETUP_MASTER=setup-master.py -8
endif

all: virtualenv deps install-buildbot master master-makefile other-files done

done:
	@echo
	@echo
	@echo You probably want to update at least the following files to contain accurate passwords/descriptions:
	@echo BuildSlaves.py, passwords.py, $(MYSQL_CONFIG)

virtualenv:
	$(VIRTUALENV) --distribute --no-site-packages -p $(PYTHON) $(BASEDIR)

deps:
	$(PIP) install $(PIP_FLAGS) -r $(PIP_PACKAGES_FILE)
	
# HACK ALERT: This only works when there's only one python version in "lib".
# This is generally true when using virtualenvs.
install-buildbot: SITE_PACKAGES = $(BASEDIR)/lib/$(shell ls $(BASEDIR)/lib/)/site-packages
install-buildbot:
	test -d $(BASEDIR)/buildbot || $(HG) clone -b $(BUILDBOT_BRANCH) $(HG_HOST)/$(HG_DIR)/buildbot $(BASEDIR)/buildbot
	(cd $(BASEDIR)/buildbot/master; $(VIRTUALENV_PYTHON) setup.py develop install)
ifdef INSTALL_BUILDBOT_SLAVE
	(cd $(BASEDIR)/buildbot/slave; $(VIRTUALENV_PYTHON) setup.py develop install)
endif
	test -d $(BASEDIR)/buildbotcustom || $(HG) clone -b $(BUILDBOTCUSTOM_BRANCH) $(HG_HOST)/$(HG_DIR)/buildbotcustom $(BASEDIR)/buildbotcustom
	test -d $(BASEDIR)/buildbot-configs || $(HG) clone -b $(BUILDBOTCONFIGS_BRANCH) $(HG_HOST)/$(HG_DIR)/buildbot-configs $(BASEDIR)/buildbot-configs
	test -d $(BASEDIR)/tools || $(HG) clone -b $(TOOLS_BRANCH) $(TOOLS_REPO) $(BASEDIR)/tools
	# Get buildbotcustom and the build/tools library into PYTHONPATH
	ln -sf $(BASEDIR)/buildbotcustom $(SITE_PACKAGES)/buildbotcustom
	echo "$(BASEDIR)/tools/lib/python" > $(SITE_PACKAGES)/build-tools-lib.pth

master:
ifdef GENERATE_MASTERS_JSON_CMD
	cd $(BASEDIR)/buildbot-configs && $(GENERATE_MASTERS_JSON_CMD)
endif
	cd $(BASEDIR)/buildbot-configs && \
	    $(VIRTUALENV_PYTHON) $(SETUP_MASTER) $(UNIVERSAL_OPT) -b $(BUILDBOT) $(BASEDIR)/master $(MASTER_NAME)

master-makefile:
	ln -sf $(BASEDIR)/buildbot-configs/Makefile.master $(BASEDIR)/Makefile

other-files:
	echo "[DEFAULT]" > $(MYSQL_CONFIG)
	echo "database = mysql://buildbot:password@$(DATABASE)" >> $(MYSQL_CONFIG)
	echo "master = http://this-master:port" >> $(MYSQL_CONFIG)
	echo "name = $(MASTER_NAME)" >> $(MYSQL_CONFIG)

.PHONY: all done virtualenv deps install-buildbot master master-makefile other-files