2023-04-21 02:39:21 -03:00
|
|
|
#!/usr/bin/env python3
|
2017-09-04 20:00:09 -03:00
|
|
|
|
|
|
|
"""
|
|
|
|
script to build the latest binaries for each vehicle type, ready to upload
|
|
|
|
Peter Barker, August 2017
|
|
|
|
based on build_binaries.sh by Andrew Tridgell, March 2013
|
2021-03-31 20:53:02 -03:00
|
|
|
|
|
|
|
AP_FLAKE8_CLEAN
|
2017-09-04 20:00:09 -03:00
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import time
|
2020-08-27 09:34:29 -03:00
|
|
|
import string
|
2017-09-04 20:00:09 -03:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2022-02-22 19:33:30 -04:00
|
|
|
import traceback
|
2017-09-04 20:00:09 -03:00
|
|
|
|
|
|
|
# local imports
|
2021-03-31 20:53:02 -03:00
|
|
|
import generate_manifest
|
|
|
|
import gen_stable
|
2020-03-06 22:41:41 -04:00
|
|
|
import build_binaries_history
|
2017-09-04 20:00:09 -03:00
|
|
|
|
2022-02-24 01:34:08 -04:00
|
|
|
import board_list
|
|
|
|
from board_list import AP_PERIPH_BOARDS
|
2021-08-05 06:43:16 -03:00
|
|
|
|
2020-07-19 23:54:19 -03:00
|
|
|
if sys.version_info[0] < 3:
|
|
|
|
running_python3 = False
|
|
|
|
else:
|
|
|
|
running_python3 = True
|
|
|
|
|
|
|
|
|
2022-07-29 00:42:02 -03:00
|
|
|
def topdir():
|
|
|
|
'''return path to ardupilot checkout directory. This is to cope with
|
|
|
|
running on developer's machines (where autotest is typically
|
|
|
|
invoked from the root directory), and on the autotest server where
|
|
|
|
it is invoked in the checkout's parent directory.
|
|
|
|
'''
|
|
|
|
for path in [
|
|
|
|
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", ".."),
|
|
|
|
"",
|
|
|
|
]:
|
|
|
|
if os.path.exists(os.path.join(path, "libraries", "AP_HAL_ChibiOS")):
|
|
|
|
return path
|
|
|
|
raise Exception("Unable to find ardupilot checkout dir")
|
|
|
|
|
|
|
|
|
2021-07-25 18:26:09 -03:00
|
|
|
def is_chibios_build(board):
|
|
|
|
'''see if a board is using HAL_ChibiOS'''
|
2021-07-31 19:39:48 -03:00
|
|
|
# cope with both running from Tools/scripts or running from cwd
|
2022-07-29 00:42:02 -03:00
|
|
|
hwdef_dir = os.path.join(topdir(), "libraries", "AP_HAL_ChibiOS", "hwdef")
|
|
|
|
|
|
|
|
return os.path.exists(os.path.join(hwdef_dir, board, "hwdef.dat"))
|
2021-07-25 18:26:09 -03:00
|
|
|
|
|
|
|
|
2022-03-01 17:34:56 -04:00
|
|
|
def get_required_compiler(vehicle, tag, board):
|
2021-07-25 18:26:09 -03:00
|
|
|
'''return required compiler for a build tag.
|
|
|
|
return format is the version string that waf configure will detect.
|
|
|
|
You should setup a link from this name in $HOME/arm-gcc directory pointing at the
|
|
|
|
appropriate compiler
|
|
|
|
'''
|
|
|
|
if not is_chibios_build(board):
|
|
|
|
# only override compiler for ChibiOS builds
|
|
|
|
return None
|
2022-03-01 17:34:56 -04:00
|
|
|
# use 10.2.1 compiler for all other builds
|
|
|
|
return "g++-10.2.1"
|
2021-07-25 18:26:09 -03:00
|
|
|
|
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
class build_binaries(object):
|
|
|
|
def __init__(self, tags):
|
|
|
|
self.tags = tags
|
|
|
|
self.dirty = False
|
2022-02-24 01:34:08 -04:00
|
|
|
self.board_list = board_list.BoardList()
|
2017-09-04 20:00:09 -03:00
|
|
|
|
|
|
|
def progress(self, string):
|
|
|
|
'''pretty-print progress'''
|
|
|
|
print("BB: %s" % string)
|
|
|
|
|
|
|
|
def run_git(self, args):
|
|
|
|
'''run git with args git_args; returns git's output'''
|
|
|
|
cmd_list = ["git"]
|
|
|
|
cmd_list.extend(args)
|
|
|
|
return self.run_program("BB-GIT", cmd_list)
|
|
|
|
|
|
|
|
def board_branch_bit(self, board):
|
2018-03-06 22:24:18 -04:00
|
|
|
'''return a fragment which might modify the branch name.
|
|
|
|
this was previously used to have a master-AVR branch etc
|
|
|
|
if the board type was apm1 or apm2'''
|
2017-09-04 20:00:09 -03:00
|
|
|
return None
|
|
|
|
|
|
|
|
def board_options(self, board):
|
|
|
|
'''return board-specific options'''
|
2021-09-26 01:27:02 -03:00
|
|
|
if board in ["bebop", "disco"]:
|
2017-09-04 20:00:09 -03:00
|
|
|
return ["--static"]
|
|
|
|
return []
|
|
|
|
|
2021-07-25 18:26:09 -03:00
|
|
|
def run_waf(self, args, compiler=None):
|
2017-09-04 20:00:09 -03:00
|
|
|
if os.path.exists("waf"):
|
|
|
|
waf = "./waf"
|
|
|
|
else:
|
|
|
|
waf = os.path.join(".", "modules", "waf", "waf-light")
|
2023-04-21 02:39:21 -03:00
|
|
|
cmd_list = ["python3", waf]
|
2017-09-04 20:00:09 -03:00
|
|
|
cmd_list.extend(args)
|
2021-07-25 18:26:09 -03:00
|
|
|
env = None
|
|
|
|
if compiler is not None:
|
|
|
|
# default to $HOME/arm-gcc, but allow for any path with AP_GCC_HOME environment variable
|
|
|
|
gcc_home = os.environ.get("AP_GCC_HOME", os.path.join(os.environ["HOME"], "arm-gcc"))
|
|
|
|
gcc_path = os.path.join(gcc_home, compiler, "bin")
|
|
|
|
if os.path.exists(gcc_path):
|
|
|
|
# setup PATH to point at the right compiler, and setup to use ccache
|
|
|
|
env = os.environ.copy()
|
|
|
|
env["PATH"] = gcc_path + ":" + env["PATH"]
|
|
|
|
env["CC"] = "ccache arm-none-eabi-gcc"
|
|
|
|
env["CXX"] = "ccache arm-none-eabi-g++"
|
|
|
|
else:
|
|
|
|
raise Exception("BB-WAF: Missing compiler %s" % gcc_path)
|
|
|
|
self.run_program("BB-WAF", cmd_list, env=env)
|
|
|
|
|
2023-02-08 23:45:12 -04:00
|
|
|
def run_program(self, prefix, cmd_list, show_output=True, env=None, force_success=False):
|
2018-07-04 20:15:59 -03:00
|
|
|
if show_output:
|
|
|
|
self.progress("Running (%s)" % " ".join(cmd_list))
|
2023-04-30 00:55:07 -03:00
|
|
|
p = subprocess.Popen(cmd_list, stdin=None,
|
2017-09-04 20:00:09 -03:00
|
|
|
stdout=subprocess.PIPE, close_fds=True,
|
2021-07-25 18:26:09 -03:00
|
|
|
stderr=subprocess.STDOUT, env=env)
|
2017-09-04 20:00:09 -03:00
|
|
|
output = ""
|
|
|
|
while True:
|
|
|
|
x = p.stdout.readline()
|
|
|
|
if len(x) == 0:
|
2018-03-01 00:21:16 -04:00
|
|
|
returncode = os.waitpid(p.pid, 0)
|
|
|
|
if returncode:
|
2017-09-04 20:00:09 -03:00
|
|
|
break
|
|
|
|
# select not available on Windows... probably...
|
2018-03-01 00:21:16 -04:00
|
|
|
time.sleep(0.1)
|
|
|
|
continue
|
2020-07-19 23:54:19 -03:00
|
|
|
if running_python3:
|
2020-08-27 09:34:29 -03:00
|
|
|
x = bytearray(x)
|
|
|
|
x = filter(lambda x : chr(x) in string.printable, x)
|
|
|
|
x = "".join([chr(c) for c in x])
|
2017-09-04 20:00:09 -03:00
|
|
|
output += x
|
|
|
|
x = x.rstrip()
|
2018-07-04 20:15:59 -03:00
|
|
|
if show_output:
|
|
|
|
print("%s: %s" % (prefix, x))
|
2018-03-01 00:21:16 -04:00
|
|
|
(_, status) = returncode
|
2023-02-08 23:45:12 -04:00
|
|
|
if status != 0 and not force_success:
|
2018-03-01 00:21:16 -04:00
|
|
|
self.progress("Process failed (%s)" %
|
|
|
|
str(returncode))
|
|
|
|
raise subprocess.CalledProcessError(
|
|
|
|
returncode, cmd_list)
|
2017-09-04 20:00:09 -03:00
|
|
|
return output
|
|
|
|
|
|
|
|
def run_make(self, args):
|
|
|
|
cmd_list = ["make"]
|
|
|
|
cmd_list.extend(args)
|
|
|
|
self.run_program("BB-MAKE", cmd_list)
|
|
|
|
|
|
|
|
def run_git_update_submodules(self):
|
|
|
|
'''if submodules are present initialise and update them'''
|
|
|
|
if os.path.exists(os.path.join(self.basedir, ".gitmodules")):
|
|
|
|
self.run_git(["submodule",
|
|
|
|
"update",
|
|
|
|
"--init",
|
|
|
|
"--recursive",
|
|
|
|
"-f"])
|
|
|
|
|
2019-06-03 04:53:30 -03:00
|
|
|
def checkout(self, vehicle, ctag, cboard=None, cframe=None, submodule_update=True):
|
2017-09-04 20:00:09 -03:00
|
|
|
'''attempt to check out a git tree. Various permutations are
|
|
|
|
attempted based on ctag - for examplle, if the board is avr and ctag
|
|
|
|
is bob we will attempt to checkout bob-AVR'''
|
|
|
|
if self.dirty:
|
|
|
|
self.progress("Skipping checkout for dirty build")
|
|
|
|
return True
|
|
|
|
|
|
|
|
self.progress("Trying checkout %s %s %s %s" %
|
|
|
|
(vehicle, ctag, cboard, cframe))
|
|
|
|
self.run_git(['stash'])
|
|
|
|
if ctag == "latest":
|
|
|
|
vtag = "master"
|
|
|
|
else:
|
2020-04-14 21:54:38 -03:00
|
|
|
tagvehicle = vehicle
|
|
|
|
if tagvehicle == "Rover":
|
|
|
|
# FIXME: Rover tags in git still named APMrover2 :-(
|
|
|
|
tagvehicle = "APMrover2"
|
|
|
|
vtag = "%s-%s" % (tagvehicle, ctag)
|
2017-09-04 20:00:09 -03:00
|
|
|
|
|
|
|
branches = []
|
|
|
|
if cframe is not None:
|
|
|
|
# try frame specific tag
|
|
|
|
branches.append("%s-%s" % (vtag, cframe))
|
|
|
|
if cboard is not None:
|
|
|
|
bbb = self.board_branch_bit(cboard)
|
|
|
|
if bbb is not None:
|
|
|
|
# try board type specific branch extension
|
|
|
|
branches.append("".join([vtag, bbb]))
|
|
|
|
branches.append(vtag)
|
|
|
|
|
|
|
|
for branch in branches:
|
|
|
|
try:
|
|
|
|
self.progress("Trying branch %s" % branch)
|
|
|
|
self.run_git(["checkout", "-f", branch])
|
2019-06-03 04:53:30 -03:00
|
|
|
if submodule_update:
|
|
|
|
self.run_git_update_submodules()
|
2017-09-04 20:00:09 -03:00
|
|
|
self.run_git(["log", "-1"])
|
|
|
|
return True
|
2019-04-29 05:12:48 -03:00
|
|
|
except subprocess.CalledProcessError:
|
2017-09-04 20:00:09 -03:00
|
|
|
self.progress("Checkout branch %s failed" % branch)
|
|
|
|
|
|
|
|
self.progress("Failed to find tag for %s %s %s %s" %
|
|
|
|
(vehicle, ctag, cboard, cframe))
|
|
|
|
return False
|
|
|
|
|
|
|
|
def skip_board_waf(self, board):
|
2021-07-25 18:26:09 -03:00
|
|
|
'''check if we should skip this build because we do not support the
|
2017-09-04 20:00:09 -03:00
|
|
|
board in this release
|
|
|
|
'''
|
|
|
|
|
|
|
|
try:
|
2023-02-08 23:45:12 -04:00
|
|
|
out = self.run_program(
|
|
|
|
'waf',
|
2023-04-21 02:39:21 -03:00
|
|
|
["python3", './waf', 'configure', '--board=BOARDTEST'],
|
2023-02-08 23:45:12 -04:00
|
|
|
show_output=False,
|
|
|
|
force_success=True
|
|
|
|
)
|
2018-07-04 20:15:59 -03:00
|
|
|
lines = out.split('\n')
|
2019-03-11 01:55:57 -03:00
|
|
|
needles = ["BOARDTEST' (choose from", "BOARDTEST': choices are"]
|
2018-07-04 20:15:59 -03:00
|
|
|
for line in lines:
|
2019-03-11 01:55:57 -03:00
|
|
|
for needle in needles:
|
|
|
|
idx = line.find(needle)
|
|
|
|
if idx != -1:
|
|
|
|
break
|
2018-07-04 20:15:59 -03:00
|
|
|
if idx != -1:
|
|
|
|
line = line[idx+len(needle):-1]
|
2019-04-29 05:12:48 -03:00
|
|
|
line = line.replace("'", "")
|
|
|
|
line = line.replace(" ", "")
|
2018-07-04 20:15:59 -03:00
|
|
|
boards = line.split(",")
|
2022-07-20 21:24:00 -03:00
|
|
|
ret = board not in boards
|
|
|
|
if ret:
|
|
|
|
self.progress("Skipping board (%s) - not in board list" % board)
|
|
|
|
return ret
|
2017-09-04 20:00:09 -03:00
|
|
|
except IOError as e:
|
|
|
|
if e.errno != 2:
|
|
|
|
raise
|
2018-04-10 00:00:55 -03:00
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
self.progress("Skipping unsupported board %s" % (board,))
|
|
|
|
return True
|
|
|
|
|
|
|
|
def skip_frame(self, board, frame):
|
|
|
|
'''returns true if this board/frame combination should not be built'''
|
|
|
|
if frame == "heli":
|
2019-09-12 00:08:43 -03:00
|
|
|
if board in ["bebop", "aerofc-v1", "skyviper-v2450", "CubeSolo", "CubeGreen-solo", 'skyviper-journey']:
|
2017-09-04 20:00:09 -03:00
|
|
|
self.progress("Skipping heli build for %s" % board)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def first_line_of_filepath(self, filepath):
|
|
|
|
'''returns the first (text) line from filepath'''
|
|
|
|
with open(filepath) as fh:
|
|
|
|
line = fh.readline()
|
|
|
|
return line
|
|
|
|
|
|
|
|
def skip_build(self, buildtag, builddir):
|
|
|
|
'''check if we should skip this build because we have already built
|
|
|
|
this version
|
|
|
|
'''
|
|
|
|
|
|
|
|
if os.getenv("FORCE_BUILD", False):
|
|
|
|
return False
|
|
|
|
|
|
|
|
if not os.path.exists(os.path.join(self.basedir, '.gitmodules')):
|
|
|
|
self.progress("Skipping build without submodules")
|
|
|
|
return True
|
|
|
|
|
|
|
|
bname = os.path.basename(builddir)
|
|
|
|
ldir = os.path.join(os.path.dirname(os.path.dirname(
|
|
|
|
os.path.dirname(builddir))), buildtag, bname) # FIXME: WTF
|
|
|
|
|
|
|
|
oldversion_filepath = os.path.join(ldir, "git-version.txt")
|
|
|
|
if not os.path.exists(oldversion_filepath):
|
|
|
|
self.progress("%s doesn't exist - building" % oldversion_filepath)
|
|
|
|
return False
|
|
|
|
|
|
|
|
oldversion = self.first_line_of_filepath(oldversion_filepath)
|
|
|
|
newversion = self.run_git(["log", "-1"])
|
|
|
|
newversion = newversion.splitlines()[0]
|
|
|
|
oldversion = oldversion.rstrip()
|
|
|
|
newversion = newversion.rstrip()
|
|
|
|
self.progress("oldversion=%s newversion=%s" %
|
|
|
|
(oldversion, newversion,))
|
|
|
|
if oldversion == newversion:
|
|
|
|
self.progress("Skipping build - version match (%s)" %
|
|
|
|
(newversion,))
|
|
|
|
return True
|
|
|
|
|
|
|
|
self.progress("%s needs rebuild" % (ldir,))
|
|
|
|
return False
|
|
|
|
|
|
|
|
def write_string_to_filepath(self, string, filepath):
|
|
|
|
'''writes the entirety of string to filepath'''
|
|
|
|
with open(filepath, "w") as x:
|
|
|
|
x.write(string)
|
|
|
|
|
2019-10-24 22:12:44 -03:00
|
|
|
def version_h_path(self, src):
|
|
|
|
'''return path to version.h'''
|
|
|
|
if src == 'AP_Periph':
|
|
|
|
return os.path.join('Tools', src, "version.h")
|
|
|
|
return os.path.join(src, "version.h")
|
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
def addfwversion_gitversion(self, destdir, src):
|
|
|
|
# create git-version.txt:
|
|
|
|
gitlog = self.run_git(["log", "-1"])
|
|
|
|
gitversion_filepath = os.path.join(destdir, "git-version.txt")
|
|
|
|
gitversion_content = gitlog
|
2019-10-24 22:12:44 -03:00
|
|
|
versionfile = self.version_h_path(src)
|
2017-09-04 20:00:09 -03:00
|
|
|
if os.path.exists(versionfile):
|
|
|
|
content = self.read_string_from_filepath(versionfile)
|
|
|
|
match = re.search('define.THISFIRMWARE "([^"]+)"', content)
|
|
|
|
if match is None:
|
|
|
|
self.progress("Failed to retrieve THISFIRMWARE from version.h")
|
|
|
|
self.progress("Content: (%s)" % content)
|
2018-02-28 22:53:57 -04:00
|
|
|
self.progress("Writing version info to %s" %
|
|
|
|
(gitversion_filepath,))
|
2017-09-04 20:00:09 -03:00
|
|
|
gitversion_content += "\nAPMVERSION: %s\n" % (match.group(1))
|
|
|
|
else:
|
|
|
|
self.progress("%s does not exist" % versionfile)
|
|
|
|
|
|
|
|
self.write_string_to_filepath(gitversion_content, gitversion_filepath)
|
|
|
|
|
|
|
|
def addfwversion_firmwareversiontxt(self, destdir, src):
|
|
|
|
# create firmware-version.txt
|
2019-10-24 22:12:44 -03:00
|
|
|
versionfile = self.version_h_path(src)
|
2017-09-04 20:00:09 -03:00
|
|
|
if not os.path.exists(versionfile):
|
|
|
|
self.progress("%s does not exist" % (versionfile,))
|
2018-02-28 22:53:57 -04:00
|
|
|
return
|
2021-03-31 20:53:02 -03:00
|
|
|
ss = r".*define +FIRMWARE_VERSION[ ]+(?P<major>\d+)[ ]*,[ ]*" \
|
|
|
|
r"(?P<minor>\d+)[ ]*,[ ]*(?P<point>\d+)[ ]*,[ ]*" \
|
|
|
|
r"(?P<type>[A-Z_]+)[ ]*"
|
2017-09-04 20:00:09 -03:00
|
|
|
content = self.read_string_from_filepath(versionfile)
|
|
|
|
match = re.search(ss, content)
|
|
|
|
if match is None:
|
|
|
|
self.progress("Failed to retrieve FIRMWARE_VERSION from version.h")
|
|
|
|
self.progress("Content: (%s)" % content)
|
|
|
|
return
|
|
|
|
ver = "%d.%d.%d-%s\n" % (int(match.group("major")),
|
|
|
|
int(match.group("minor")),
|
|
|
|
int(match.group("point")),
|
|
|
|
match.group("type"))
|
|
|
|
firmware_version_filepath = "firmware-version.txt"
|
|
|
|
self.progress("Writing version (%s) to %s" %
|
|
|
|
(ver, firmware_version_filepath,))
|
|
|
|
self.write_string_to_filepath(
|
|
|
|
ver, os.path.join(destdir, firmware_version_filepath))
|
|
|
|
|
|
|
|
def addfwversion(self, destdir, src):
|
|
|
|
'''write version information into destdir'''
|
|
|
|
self.addfwversion_gitversion(destdir, src)
|
|
|
|
self.addfwversion_firmwareversiontxt(destdir, src)
|
|
|
|
|
|
|
|
def read_string_from_filepath(self, filepath):
|
|
|
|
'''returns content of filepath as a string'''
|
|
|
|
with open(filepath, 'rb') as fh:
|
|
|
|
content = fh.read()
|
2022-02-22 20:08:52 -04:00
|
|
|
|
|
|
|
if running_python3:
|
|
|
|
return content.decode('ascii')
|
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
return content
|
|
|
|
|
|
|
|
def string_in_filepath(self, string, filepath):
|
|
|
|
'''returns true if string exists in the contents of filepath'''
|
|
|
|
return string in self.read_string_from_filepath(filepath)
|
|
|
|
|
2018-03-20 20:07:40 -03:00
|
|
|
def mkpath(self, path):
|
|
|
|
'''make directory path and all elements leading to it'''
|
|
|
|
'''distutils.dir_util.mkpath was playing up'''
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != 17: # EEXIST
|
|
|
|
raise e
|
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
def touch_filepath(self, filepath):
|
|
|
|
'''creates a file at filepath, or updates the timestamp on filepath'''
|
|
|
|
if os.path.exists(filepath):
|
|
|
|
os.utime(filepath, None)
|
|
|
|
else:
|
|
|
|
with open(filepath, "a"):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def build_vehicle(self, tag, vehicle, boards, vehicle_binaries_subdir,
|
2021-07-25 18:40:53 -03:00
|
|
|
binaryname, frames=[None]):
|
2017-09-04 20:00:09 -03:00
|
|
|
'''build vehicle binaries'''
|
|
|
|
self.progress("Building %s %s binaries (cwd=%s)" %
|
|
|
|
(vehicle, tag, os.getcwd()))
|
|
|
|
|
2020-02-05 21:07:13 -04:00
|
|
|
board_count = len(boards)
|
|
|
|
count = 0
|
|
|
|
for board in sorted(boards, key=str.lower):
|
2019-05-30 18:36:16 -03:00
|
|
|
now = datetime.datetime.now()
|
2020-02-05 21:07:13 -04:00
|
|
|
count += 1
|
|
|
|
self.progress("[%u/%u] Building board: %s at %s" %
|
|
|
|
(count, board_count, board, str(now)))
|
2017-09-04 20:00:09 -03:00
|
|
|
for frame in frames:
|
|
|
|
if frame is not None:
|
|
|
|
self.progress("Considering frame %s for board %s" %
|
|
|
|
(frame, board))
|
|
|
|
if frame is None:
|
|
|
|
framesuffix = ""
|
|
|
|
else:
|
|
|
|
framesuffix = "-%s" % frame
|
2019-06-03 04:53:30 -03:00
|
|
|
if not self.checkout(vehicle, tag, board, frame, submodule_update=False):
|
2018-03-06 22:34:36 -04:00
|
|
|
msg = ("Failed checkout of %s %s %s %s" %
|
|
|
|
(vehicle, board, tag, frame,))
|
|
|
|
self.progress(msg)
|
|
|
|
self.error_strings.append(msg)
|
2017-09-04 20:00:09 -03:00
|
|
|
continue
|
2019-06-03 04:53:30 -03:00
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
self.progress("Building %s %s %s binaries %s" %
|
|
|
|
(vehicle, tag, board, frame))
|
|
|
|
ddir = os.path.join(self.binaries,
|
|
|
|
vehicle_binaries_subdir,
|
|
|
|
self.hdate_ym,
|
|
|
|
self.hdate_ymdhm,
|
|
|
|
"".join([board, framesuffix]))
|
|
|
|
if self.skip_build(tag, ddir):
|
|
|
|
continue
|
|
|
|
if self.skip_frame(board, frame):
|
|
|
|
continue
|
2018-04-09 23:48:21 -03:00
|
|
|
|
2019-06-03 04:53:30 -03:00
|
|
|
# we do the submodule update after the skip_board_waf check to avoid doing it on
|
|
|
|
# builds we will not be running
|
|
|
|
self.run_git_update_submodules()
|
|
|
|
|
2019-06-03 08:48:27 -03:00
|
|
|
if self.skip_board_waf(board):
|
|
|
|
continue
|
2020-12-12 16:16:42 -04:00
|
|
|
|
2018-06-21 23:40:54 -03:00
|
|
|
if os.path.exists(self.buildroot):
|
|
|
|
shutil.rmtree(self.buildroot)
|
|
|
|
|
2019-04-29 05:12:48 -03:00
|
|
|
self.remove_tmpdir()
|
2018-04-09 23:48:21 -03:00
|
|
|
|
2020-03-06 22:41:41 -04:00
|
|
|
githash = self.run_git(["rev-parse", "HEAD"]).rstrip()
|
|
|
|
|
2019-06-03 04:53:30 -03:00
|
|
|
t0 = time.time()
|
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
self.progress("Configuring for %s in %s" %
|
|
|
|
(board, self.buildroot))
|
|
|
|
try:
|
|
|
|
waf_opts = ["configure",
|
|
|
|
"--board", board,
|
|
|
|
"--out", self.buildroot,
|
|
|
|
"clean"]
|
2022-03-01 17:34:56 -04:00
|
|
|
gccstring = get_required_compiler(vehicle, tag, board)
|
|
|
|
if gccstring is not None and gccstring.find("g++-6.3") == -1:
|
|
|
|
# versions using the old compiler don't have the --assert-cc-version option
|
2021-07-25 18:26:09 -03:00
|
|
|
waf_opts += ["--assert-cc-version", gccstring]
|
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
waf_opts.extend(self.board_options(board))
|
2021-07-25 18:26:09 -03:00
|
|
|
self.run_waf(waf_opts, compiler=gccstring)
|
2019-04-29 05:12:48 -03:00
|
|
|
except subprocess.CalledProcessError:
|
2017-09-04 20:00:09 -03:00
|
|
|
self.progress("waf configure failed")
|
|
|
|
continue
|
2021-11-17 18:38:19 -04:00
|
|
|
|
|
|
|
time_taken_to_configure = time.time() - t0
|
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
try:
|
|
|
|
target = os.path.join("bin",
|
|
|
|
"".join([binaryname, framesuffix]))
|
2021-07-25 18:26:09 -03:00
|
|
|
self.run_waf(["build", "--targets", target], compiler=gccstring)
|
2019-04-29 05:12:48 -03:00
|
|
|
except subprocess.CalledProcessError:
|
2018-03-06 22:34:36 -04:00
|
|
|
msg = ("Failed build of %s %s%s %s" %
|
|
|
|
(vehicle, board, framesuffix, tag))
|
|
|
|
self.progress(msg)
|
|
|
|
self.error_strings.append(msg)
|
2020-03-06 22:41:41 -04:00
|
|
|
# record some history about this build
|
|
|
|
t1 = time.time()
|
|
|
|
time_taken_to_build = t1-t0
|
|
|
|
self.history.record_build(githash, tag, vehicle, board, frame, None, t0, time_taken_to_build)
|
2017-09-04 20:00:09 -03:00
|
|
|
continue
|
|
|
|
|
2021-11-17 18:38:19 -04:00
|
|
|
time_taken_to_build = (time.time()-t0) - time_taken_to_configure
|
|
|
|
|
|
|
|
time_taken = time.time()-t0
|
|
|
|
self.progress("Making %s %s %s %s took %u seconds (configure=%u build=%u)" %
|
|
|
|
(vehicle, tag, board, frame, time_taken, time_taken_to_configure, time_taken_to_build))
|
2019-06-03 04:53:30 -03:00
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
bare_path = os.path.join(self.buildroot,
|
|
|
|
board,
|
|
|
|
"bin",
|
|
|
|
"".join([binaryname, framesuffix]))
|
2018-03-20 02:08:08 -03:00
|
|
|
files_to_copy = []
|
2021-07-25 18:40:53 -03:00
|
|
|
extensions = [".apj", ".abin", "_with_bl.hex", ".hex"]
|
2019-10-24 21:57:15 -03:00
|
|
|
if vehicle == 'AP_Periph':
|
|
|
|
# need bin file for uavcan-gui-tool and MissionPlanner
|
|
|
|
extensions.append('.bin')
|
|
|
|
for extension in extensions:
|
2018-03-20 02:08:08 -03:00
|
|
|
filepath = "".join([bare_path, extension])
|
|
|
|
if os.path.exists(filepath):
|
2022-08-11 02:44:46 -03:00
|
|
|
files_to_copy.append((filepath, os.path.basename(filepath)))
|
2020-03-06 22:41:41 -04:00
|
|
|
if not os.path.exists(bare_path):
|
|
|
|
raise Exception("No elf file?!")
|
2022-07-29 00:42:02 -03:00
|
|
|
|
|
|
|
# attempt to run an extract_features.py to create features.txt:
|
|
|
|
features_text = None
|
|
|
|
ef_path = os.path.join(topdir(), "Tools", "scripts", "extract_features.py")
|
|
|
|
if os.path.exists(ef_path):
|
|
|
|
try:
|
|
|
|
features_text = self.run_program("EF", [ef_path, bare_path], show_output=False)
|
|
|
|
except Exception as e:
|
|
|
|
self.print_exception_caught(e)
|
|
|
|
self.progress("Failed to extract features")
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.progress("Not extracting features as (%s) does not exist" % (ef_path,))
|
|
|
|
|
2022-08-11 02:44:46 -03:00
|
|
|
# only rename the elf if we have have other files to
|
|
|
|
# copy. So linux gets "arducopter" and stm32 gets
|
|
|
|
# "arducopter.elf"
|
|
|
|
target_elf_filename = os.path.basename(bare_path)
|
|
|
|
if len(files_to_copy) > 0:
|
|
|
|
target_elf_filename += ".elf"
|
|
|
|
files_to_copy.append((bare_path, target_elf_filename))
|
|
|
|
|
|
|
|
for (path, target_filename) in files_to_copy:
|
2018-03-20 02:08:08 -03:00
|
|
|
try:
|
2022-08-11 02:14:31 -03:00
|
|
|
'''copy path into various places, adding metadata'''
|
|
|
|
bname = os.path.basename(ddir)
|
|
|
|
tdir = os.path.join(os.path.dirname(os.path.dirname(
|
|
|
|
os.path.dirname(ddir))), tag, bname)
|
|
|
|
if tag == "latest":
|
2022-08-11 02:31:09 -03:00
|
|
|
# we keep a permanent archive of all
|
|
|
|
# "latest" builds, their path including a
|
|
|
|
# build timestamp:
|
|
|
|
if not os.path.exists(ddir):
|
|
|
|
self.mkpath(ddir)
|
2022-08-21 21:34:15 -03:00
|
|
|
self.addfwversion(ddir, vehicle)
|
2022-07-29 00:42:02 -03:00
|
|
|
features_filepath = os.path.join(ddir, "features.txt",)
|
2023-07-12 03:51:09 -03:00
|
|
|
if features_text is not None:
|
|
|
|
self.progress("Writing (%s)" % features_filepath)
|
|
|
|
self.write_string_to_filepath(features_text, features_filepath)
|
2022-08-11 02:14:31 -03:00
|
|
|
self.progress("Copying %s to %s" % (path, ddir,))
|
2022-08-11 02:44:46 -03:00
|
|
|
shutil.copy(path, os.path.join(ddir, target_filename))
|
2022-08-11 02:14:31 -03:00
|
|
|
# the most recent build of every tag is kept around:
|
|
|
|
self.progress("Copying %s to %s" % (path, tdir))
|
2022-08-11 02:31:09 -03:00
|
|
|
if not os.path.exists(tdir):
|
|
|
|
self.mkpath(tdir)
|
2022-08-21 21:34:15 -03:00
|
|
|
# must addfwversion even if path already
|
|
|
|
# exists as we re-use the "beta" directories
|
|
|
|
self.addfwversion(tdir, vehicle)
|
2022-07-29 00:42:02 -03:00
|
|
|
features_filepath = os.path.join(tdir, "features.txt")
|
|
|
|
self.progress("Writing (%s)" % features_filepath)
|
|
|
|
self.write_string_to_filepath(features_text, features_filepath)
|
2022-08-11 02:44:46 -03:00
|
|
|
shutil.copy(path, os.path.join(tdir, target_filename))
|
2018-03-20 02:08:08 -03:00
|
|
|
except Exception as e:
|
2022-02-22 19:33:30 -04:00
|
|
|
self.print_exception_caught(e)
|
2022-07-29 00:42:02 -03:00
|
|
|
self.progress("Failed to copy %s to %s: %s" % (path, tdir, str(e)))
|
2017-09-04 20:00:09 -03:00
|
|
|
# why is touching this important? -pb20170816
|
|
|
|
self.touch_filepath(os.path.join(self.binaries,
|
|
|
|
vehicle_binaries_subdir, tag))
|
|
|
|
|
2020-03-06 22:41:41 -04:00
|
|
|
# record some history about this build
|
|
|
|
self.history.record_build(githash, tag, vehicle, board, frame, bare_path, t0, time_taken_to_build)
|
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
self.checkout(vehicle, "latest")
|
|
|
|
|
2023-05-23 10:33:21 -03:00
|
|
|
def _get_exception_stacktrace(self, e):
|
2022-02-22 19:33:30 -04:00
|
|
|
if sys.version_info[0] >= 3:
|
|
|
|
ret = "%s\n" % e
|
2022-03-06 21:45:19 -04:00
|
|
|
ret += ''.join(traceback.format_exception(type(e),
|
|
|
|
e,
|
2022-02-22 19:33:30 -04:00
|
|
|
tb=e.__traceback__))
|
|
|
|
return ret
|
2022-03-06 21:45:19 -04:00
|
|
|
|
|
|
|
# Python2:
|
2022-02-22 19:33:30 -04:00
|
|
|
return traceback.format_exc(e)
|
|
|
|
|
2023-05-23 10:33:21 -03:00
|
|
|
def get_exception_stacktrace(self, e):
|
|
|
|
try:
|
|
|
|
return self._get_exception_stacktrace(e)
|
|
|
|
except Exception:
|
|
|
|
return "FAILED TO GET EXCEPTION STACKTRACE"
|
|
|
|
|
2022-02-22 19:33:30 -04:00
|
|
|
def print_exception_caught(self, e, send_statustext=True):
|
|
|
|
self.progress("Exception caught: %s" %
|
|
|
|
self.get_exception_stacktrace(e))
|
|
|
|
|
2019-10-24 08:35:47 -03:00
|
|
|
def AP_Periph_boards(self):
|
2021-08-05 06:43:16 -03:00
|
|
|
return AP_PERIPH_BOARDS
|
2019-10-24 08:35:47 -03:00
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
def build_arducopter(self, tag):
|
|
|
|
'''build Copter binaries'''
|
2022-02-24 01:34:08 -04:00
|
|
|
|
2018-03-20 00:16:57 -03:00
|
|
|
boards = []
|
2022-02-24 01:34:08 -04:00
|
|
|
boards.extend(["aerofc-v1", "bebop"])
|
|
|
|
boards.extend(self.board_list.find_autobuild_boards('Copter'))
|
2017-09-04 20:00:09 -03:00
|
|
|
self.build_vehicle(tag,
|
|
|
|
"ArduCopter",
|
|
|
|
boards,
|
|
|
|
"Copter",
|
|
|
|
"arducopter",
|
|
|
|
frames=[None, "heli"])
|
|
|
|
|
|
|
|
def build_arduplane(self, tag):
|
|
|
|
'''build Plane binaries'''
|
2022-02-24 01:34:08 -04:00
|
|
|
boards = self.board_list.find_autobuild_boards('Plane')[:]
|
2017-09-04 20:00:09 -03:00
|
|
|
boards.append("disco")
|
|
|
|
self.build_vehicle(tag,
|
|
|
|
"ArduPlane",
|
|
|
|
boards,
|
|
|
|
"Plane",
|
2021-07-25 18:40:53 -03:00
|
|
|
"arduplane")
|
2017-09-04 20:00:09 -03:00
|
|
|
|
|
|
|
def build_antennatracker(self, tag):
|
|
|
|
'''build Tracker binaries'''
|
|
|
|
self.build_vehicle(tag,
|
|
|
|
"AntennaTracker",
|
2022-02-24 01:34:08 -04:00
|
|
|
self.board_list.find_autobuild_boards('Tracker')[:],
|
2017-09-04 20:00:09 -03:00
|
|
|
"AntennaTracker",
|
2021-07-25 18:40:53 -03:00
|
|
|
"antennatracker")
|
2017-09-04 20:00:09 -03:00
|
|
|
|
|
|
|
def build_rover(self, tag):
|
|
|
|
'''build Rover binaries'''
|
|
|
|
self.build_vehicle(tag,
|
2020-03-26 21:51:16 -03:00
|
|
|
"Rover",
|
2022-02-24 01:34:08 -04:00
|
|
|
self.board_list.find_autobuild_boards('Rover')[:],
|
2017-09-04 20:00:09 -03:00
|
|
|
"Rover",
|
2021-07-25 18:40:53 -03:00
|
|
|
"ardurover")
|
2017-09-04 20:00:09 -03:00
|
|
|
|
|
|
|
def build_ardusub(self, tag):
|
|
|
|
'''build Sub binaries'''
|
|
|
|
self.build_vehicle(tag,
|
|
|
|
"ArduSub",
|
2022-02-24 01:34:08 -04:00
|
|
|
self.board_list.find_autobuild_boards('Sub')[:],
|
2017-09-04 20:00:09 -03:00
|
|
|
"Sub",
|
2021-07-25 18:40:53 -03:00
|
|
|
"ardusub")
|
2017-09-04 20:00:09 -03:00
|
|
|
|
2019-10-24 08:35:47 -03:00
|
|
|
def build_AP_Periph(self, tag):
|
|
|
|
'''build AP_Periph binaries'''
|
|
|
|
boards = self.AP_Periph_boards()
|
|
|
|
self.build_vehicle(tag,
|
|
|
|
"AP_Periph",
|
|
|
|
boards,
|
|
|
|
"AP_Periph",
|
|
|
|
"AP_Periph")
|
|
|
|
|
2022-01-05 03:50:01 -04:00
|
|
|
def build_blimp(self, tag):
|
|
|
|
'''build Blimp binaries'''
|
|
|
|
self.build_vehicle(tag,
|
|
|
|
"Blimp",
|
2022-02-24 01:34:08 -04:00
|
|
|
self.board_list.find_autobuild_boards('Blimp')[:],
|
2022-01-05 03:50:01 -04:00
|
|
|
"Blimp",
|
|
|
|
"blimp")
|
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
def generate_manifest(self):
|
|
|
|
'''generate manigest files for GCS to download'''
|
|
|
|
self.progress("Generating manifest")
|
2019-12-07 16:44:14 -04:00
|
|
|
base_url = 'https://firmware.ardupilot.org'
|
2017-09-04 20:00:09 -03:00
|
|
|
generator = generate_manifest.ManifestGenerator(self.binaries,
|
|
|
|
base_url)
|
2022-07-29 02:19:37 -03:00
|
|
|
generator.run()
|
|
|
|
|
|
|
|
generator.write_manifest_json(os.path.join(self.binaries, "manifest.json"))
|
2017-09-04 20:00:09 -03:00
|
|
|
self.progress("Manifest generation successful")
|
|
|
|
|
2019-05-24 22:50:02 -03:00
|
|
|
self.progress("Generating stable releases")
|
|
|
|
gen_stable.make_all_stable(self.binaries)
|
|
|
|
self.progress("Generate stable releases done")
|
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
def validate(self):
|
|
|
|
'''run pre-run validation checks'''
|
|
|
|
if "dirty" in self.tags:
|
|
|
|
if len(self.tags) > 1:
|
|
|
|
raise ValueError("dirty must be only tag if present (%s)" %
|
|
|
|
(str(self.tags)))
|
|
|
|
self.dirty = True
|
|
|
|
|
2018-04-09 23:48:21 -03:00
|
|
|
def remove_tmpdir(self):
|
|
|
|
if os.path.exists(self.tmpdir):
|
|
|
|
self.progress("Removing (%s)" % (self.tmpdir,))
|
|
|
|
shutil.rmtree(self.tmpdir)
|
|
|
|
|
2019-08-20 21:48:05 -03:00
|
|
|
def buildlogs_dirpath(self):
|
|
|
|
return os.getenv("BUILDLOGS",
|
|
|
|
os.path.join(os.getcwd(), "..", "buildlogs"))
|
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
def run(self):
|
|
|
|
self.validate()
|
|
|
|
|
2022-02-25 20:46:53 -04:00
|
|
|
self.mkpath(self.buildlogs_dirpath())
|
|
|
|
|
|
|
|
binaries_history_filepath = os.path.join(
|
|
|
|
self.buildlogs_dirpath(), "build_binaries_history.sqlite")
|
|
|
|
self.history = build_binaries_history.BuildBinariesHistory(binaries_history_filepath)
|
|
|
|
|
2017-09-04 20:00:09 -03:00
|
|
|
prefix_bin_dirpath = os.path.join(os.environ.get('HOME'),
|
|
|
|
"prefix", "bin")
|
|
|
|
origin_env_path = os.environ.get("PATH")
|
|
|
|
os.environ["PATH"] = ':'.join([prefix_bin_dirpath, origin_env_path,
|
|
|
|
"/bin", "/usr/bin"])
|
2019-06-05 20:10:32 -03:00
|
|
|
if 'BUILD_BINARIES_PATH' in os.environ:
|
|
|
|
self.tmpdir = os.environ['BUILD_BINARIES_PATH']
|
|
|
|
else:
|
|
|
|
self.tmpdir = os.path.join(os.getcwd(), 'build.tmp.binaries')
|
2017-09-04 20:00:09 -03:00
|
|
|
os.environ["TMPDIR"] = self.tmpdir
|
|
|
|
|
|
|
|
print(self.tmpdir)
|
2019-04-29 05:12:48 -03:00
|
|
|
self.remove_tmpdir()
|
2017-09-04 20:00:09 -03:00
|
|
|
|
|
|
|
self.progress("Building in %s" % self.tmpdir)
|
|
|
|
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
self.progress(now)
|
|
|
|
|
|
|
|
if not self.dirty:
|
|
|
|
self.run_git(["checkout", "-f", "master"])
|
|
|
|
githash = self.run_git(["rev-parse", "HEAD"])
|
|
|
|
githash = githash.rstrip()
|
|
|
|
self.progress("git hash: %s" % str(githash))
|
|
|
|
|
|
|
|
self.hdate_ym = now.strftime("%Y-%m")
|
|
|
|
self.hdate_ymdhm = now.strftime("%Y-%m-%d-%H:%m")
|
|
|
|
|
2018-03-20 20:07:40 -03:00
|
|
|
self.mkpath(os.path.join("binaries", self.hdate_ym,
|
|
|
|
self.hdate_ymdhm))
|
2019-08-20 21:48:05 -03:00
|
|
|
self.binaries = os.path.join(self.buildlogs_dirpath(), "binaries")
|
2017-09-04 20:00:09 -03:00
|
|
|
self.basedir = os.getcwd()
|
2018-03-06 22:34:36 -04:00
|
|
|
self.error_strings = []
|
2017-09-04 20:00:09 -03:00
|
|
|
|
|
|
|
if not self.dirty:
|
|
|
|
self.run_git_update_submodules()
|
|
|
|
self.buildroot = os.path.join(os.environ.get("TMPDIR"),
|
|
|
|
"binaries.build")
|
|
|
|
|
|
|
|
for tag in self.tags:
|
2020-03-06 22:41:41 -04:00
|
|
|
t0 = time.time()
|
2017-09-04 20:00:09 -03:00
|
|
|
self.build_arducopter(tag)
|
|
|
|
self.build_arduplane(tag)
|
|
|
|
self.build_rover(tag)
|
|
|
|
self.build_antennatracker(tag)
|
|
|
|
self.build_ardusub(tag)
|
2019-10-24 08:35:47 -03:00
|
|
|
self.build_AP_Periph(tag)
|
2022-01-05 03:50:01 -04:00
|
|
|
self.build_blimp(tag)
|
2020-03-06 22:41:41 -04:00
|
|
|
self.history.record_run(githash, tag, t0, time.time()-t0)
|
2017-09-04 20:00:09 -03:00
|
|
|
|
|
|
|
if os.path.exists(self.tmpdir):
|
|
|
|
shutil.rmtree(self.tmpdir)
|
|
|
|
|
|
|
|
self.generate_manifest()
|
|
|
|
|
2018-03-06 22:34:36 -04:00
|
|
|
for error_string in self.error_strings:
|
|
|
|
self.progress("%s" % error_string)
|
|
|
|
sys.exit(len(self.error_strings))
|
2017-09-04 20:00:09 -03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = optparse.OptionParser("build_binaries.py")
|
|
|
|
|
|
|
|
parser.add_option("", "--tags", action="append", type="string",
|
|
|
|
default=[], help="tags to build")
|
|
|
|
cmd_opts, cmd_args = parser.parse_args()
|
|
|
|
|
|
|
|
tags = cmd_opts.tags
|
|
|
|
if len(tags) == 0:
|
|
|
|
# FIXME: wedge this defaulting into parser somehow
|
2023-05-23 02:36:35 -03:00
|
|
|
tags = ["stable", "beta-4.3", "beta", "latest"]
|
2017-09-04 20:00:09 -03:00
|
|
|
|
|
|
|
bb = build_binaries(tags)
|
|
|
|
bb.run()
|