blob: 0548bd852675924844bec056e7dee47e556f7fd1 [file] [log] [blame]
bjanakiraman7f4a4852013-02-15 04:35:28 +00001#!/usr/bin/python2.6
2#
3# Copyright 2010 Google Inc. All Rights Reserved.
4
5"""Utilities for toolchain build."""
6
bjanakiraman7f4a4852013-02-15 04:35:28 +00007__author__ = "asharif@google.com (Ahmad Sharif)"
8
asharif4d2b7162013-02-15 05:14:57 +00009import hashlib
kbaclawski6999ada2013-02-15 19:57:09 +000010import os
11import re
12import logger
asharif7aad14d2013-02-15 21:15:13 +000013from contextlib import contextmanager
bjanakiraman7f4a4852013-02-15 04:35:28 +000014
15
16def GetRoot(scr_name):
17 """Break up pathname into (dir+name)."""
18 abs_path = os.path.abspath(scr_name)
19 return (os.path.dirname(abs_path), os.path.basename(abs_path))
20
21
asharifcefd1382013-02-15 04:49:12 +000022def FormatQuotedCommand(command):
23 return command.replace("\"", "\\\"")
24
kbaclawski5fec5502013-02-15 19:55:56 +000025
asharif0e0e2682013-02-15 05:15:29 +000026def FormatCommands(commands):
kbaclawski08b1e152013-02-15 20:00:19 +000027 output = str(commands)
kbaclawski5fec5502013-02-15 19:55:56 +000028 output = re.sub("&&", "&&\n", output)
29 output = re.sub(";", ";\n", output)
30 output = re.sub("\n+\s*", "\n", output)
31 return output
asharif0e0e2682013-02-15 05:15:29 +000032
kbaclawski6999ada2013-02-15 19:57:09 +000033
asharife0cc3052013-02-15 05:20:48 +000034def GetBuildPackagesCommand(board):
raymesfc4e4f12013-02-15 19:55:58 +000035 return "./build_packages --nousepkg --withdev --withtest --withautotest " \
asharif852482f2013-02-15 21:19:59 +000036 "--skip_toolchain_update --nowithdebug --board=%s" % board
kbaclawski5fec5502013-02-15 19:55:56 +000037
asharife0cc3052013-02-15 05:20:48 +000038
39def GetBuildImageCommand(board):
kbaclawski5fec5502013-02-15 19:55:56 +000040 return "./build_image --withdev --board=%s" % board
41
asharife0cc3052013-02-15 05:20:48 +000042
43def GetModImageForTestCommand(board):
kbaclawski5fec5502013-02-15 19:55:56 +000044 return "./mod_image_for_test.sh --yes --board=%s" % board
asharife0cc3052013-02-15 05:20:48 +000045
kbaclawski5fec5502013-02-15 19:55:56 +000046
47def GetSetupBoardCommand(board, gcc_version=None, binutils_version=None,
48 usepkg=None, force=None):
49 options = []
50
51 if gcc_version:
52 options.append("--gcc_version=%s" % gcc_version)
53
54 if binutils_version:
55 options.append("--binutils_version=%s" % binutils_version)
56
57 if usepkg:
58 options.append("--usepkg")
asharife0cc3052013-02-15 05:20:48 +000059 else:
kbaclawski5fec5502013-02-15 19:55:56 +000060 options.append("--nousepkg")
61
62 if force:
63 options.append("--force")
64
65 return "./setup_board --board=%s %s" % (board, " ".join(options))
asharife0cc3052013-02-15 05:20:48 +000066
asharif0e0e2682013-02-15 05:15:29 +000067
asharif7aad14d2013-02-15 21:15:13 +000068@contextmanager
69def WorkingDirectory(new_dir):
70 old_dir = os.getcwd()
ashariff6e91952013-02-15 22:36:16 +000071 if old_dir != new_dir:
72 msg = "cd %s" % new_dir
73 logger.GetLogger().LogCmd(msg)
asharif7aad14d2013-02-15 21:15:13 +000074 os.chdir(new_dir)
75 yield new_dir
ashariff6e91952013-02-15 22:36:16 +000076 if old_dir != new_dir:
77 msg = "cd %s" % old_dir
78 logger.GetLogger().LogCmd(msg)
asharif7aad14d2013-02-15 21:15:13 +000079 os.chdir(old_dir)