blob: 9d491f671e34228555e88b228416cf719416fcb6 [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"""Script to build the ChromeOS toolchain.
6
7This script sets up the toolchain if you give it the gcctools directory.
8"""
9
10__author__ = "asharif@google.com (Ahmad Sharif)"
11
asharif80c6e552013-02-15 04:35:40 +000012import getpass
bjanakiraman7f4a4852013-02-15 04:35:28 +000013import optparse
14import sys
15from utils import utils
16
17# Common initializations
18(rootdir, basename) = utils.GetRoot(sys.argv[0])
19utils.InitLogger(rootdir, basename)
20
bjanakiraman7f4a4852013-02-15 04:35:28 +000021
asharif19c73dd2013-02-15 04:35:37 +000022def Main():
23 """The main function."""
24 parser = optparse.OptionParser()
25 parser.add_option("-c", "--chromeos_root", dest="chromeos_root",
26 help="ChromeOS root checkout directory.")
27 parser.add_option("-t", "--toolchain_root", dest="toolchain_root",
28 help="Toolchain root directory.")
29 parser.add_option("-b", "--board", dest="board",
30 help="board is the argument to the setup_board command.")
31 parser.add_option("-C", "--clean", dest="clean",
32 action="store_true", help="Uninstall the toolchain.")
asharif80c6e552013-02-15 04:35:40 +000033 parser.add_option("-f", "--force", dest="force",
34 action="store_true", help="Do an uninstall/install cycle.")
asharif19c73dd2013-02-15 04:35:37 +000035 parser.add_option("-i", "--incremental", dest="incremental",
36 help="The toolchain component that should be "
37 "incrementally compiled.")
bjanakiraman7f4a4852013-02-15 04:35:28 +000038
asharif19c73dd2013-02-15 04:35:37 +000039 options = parser.parse_args()[0]
bjanakiraman7f4a4852013-02-15 04:35:28 +000040
asharif19c73dd2013-02-15 04:35:37 +000041 if options.toolchain_root is None or options.board is None:
42 parser.print_help()
43 sys.exit()
bjanakiraman7f4a4852013-02-15 04:35:28 +000044
asharif19c73dd2013-02-15 04:35:37 +000045 if options.chromeos_root is None:
46 options.chromeos_root = "../.."
47
48 f = open(options.chromeos_root + "/src/overlays/overlay-" +
49 options.board + "/toolchain.conf", "r")
50 target = f.read()
51 f.close()
52 target = target.strip()
asharif80c6e552013-02-15 04:35:40 +000053 features = "noclean userfetch userpriv usersandbox"
asharif19c73dd2013-02-15 04:35:37 +000054 env = CreateEnvVarString(" FEATURES", features)
asharif80c6e552013-02-15 04:35:40 +000055 env += CreateEnvVarString(" PORTAGE_USERNAME", getpass.getuser())
56 version_number = utils.GetRoot(rootdir)[1]
57 version_dir = "/home/${USER}/toolchain_root/" + version_number
58 env += CreateEnvVarString(" PORT_LOGDIR", version_dir + "/logs")
59 env += CreateEnvVarString(" PKGDIR", version_dir + "/install")
60 env += CreateEnvVarString(" PORTAGE_TMPDIR", version_dir + "/objects")
61 if options.force == True:
62 BuildTC(options.chromeos_root, options.toolchain_root, env, target,
63 True, options.incremental)
asharif19c73dd2013-02-15 04:35:37 +000064 BuildTC(options.chromeos_root, options.toolchain_root, env, target,
65 options.clean, options.incremental)
66
67
68def CreateEnvVarString(variable, value):
69 return variable + "=" + EscapeQuoteString(value)
70
71
72def EscapeQuoteString(string):
73 return "\\\"" + string + "\\\""
74
75
76def BuildTC(chromeos_root, toolchain_root, env, target, uninstall,
77 incremental_component):
78 """Build the toolchain."""
79 binutils_version = "2.20.1-r1"
80 gcc_version = "9999"
81 libc_version = "2.10.1-r1"
82 kernel_version = "2.6.30-r1"
asharif80c6e552013-02-15 04:35:40 +000083 if incremental_component is not None and incremental_component:
asharif19c73dd2013-02-15 04:35:37 +000084 env += "FEATURES+=" + EscapeQuoteString("keepwork")
85
86 if uninstall == True:
87 tflag = " -C "
88 else:
89 tflag = " -t "
90
91 command = (rootdir + "/tc-enter-chroot.sh")
92 if chromeos_root is not None:
93 command += " --chromeos_root=" + chromeos_root
94 if toolchain_root is not None:
95 command += " --toolchain_root=" + toolchain_root
96 command += " -- sudo " + env
97
98 if incremental_component == "binutils":
99 command += " emerge =cross-" + target + "/binutils-" + binutils_version
100 elif incremental_component == "gcc":
101 command += " emerge =cross-" + target + "/gcc-" + gcc_version
102 elif incremental_component == "libc" or incremental_component == "glibc":
103 command += " emerge =cross-" + target + "/glibc-" + libc_version
104 else:
105 command += (" crossdev -v " + tflag + target +
106 " --binutils " + binutils_version +
107 " --libc " + libc_version +
108 " --gcc " + gcc_version +
109 " --kernel " + kernel_version +
110 " --portage -b --portage --newuse")
111
112 retval = utils.RunCommand(command)
113 return retval
114
115if __name__ == "__main__":
116 Main()