bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 1 | #!/usr/bin/python2.6 |
| 2 | # |
| 3 | # Copyright 2010 Google Inc. All Rights Reserved. |
| 4 | |
| 5 | """Script to build the ChromeOS toolchain. |
| 6 | |
| 7 | This script sets up the toolchain if you give it the gcctools directory. |
| 8 | """ |
| 9 | |
| 10 | __author__ = "asharif@google.com (Ahmad Sharif)" |
| 11 | |
asharif | 80c6e55 | 2013-02-15 04:35:40 +0000 | [diff] [blame] | 12 | import getpass |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 13 | import optparse |
| 14 | import sys |
| 15 | from utils import utils |
| 16 | |
| 17 | # Common initializations |
| 18 | (rootdir, basename) = utils.GetRoot(sys.argv[0]) |
| 19 | utils.InitLogger(rootdir, basename) |
| 20 | |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 21 | |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 22 | def 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", |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 32 | action="store_true", default=False, |
| 33 | help="Uninstall the toolchain.") |
asharif | 80c6e55 | 2013-02-15 04:35:40 +0000 | [diff] [blame] | 34 | parser.add_option("-f", "--force", dest="force", |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 35 | action="store_true", default=False, |
| 36 | help="Do an uninstall/install cycle.") |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 37 | parser.add_option("-i", "--incremental", dest="incremental", |
| 38 | help="The toolchain component that should be " |
| 39 | "incrementally compiled.") |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 40 | parser.add_option("-B", "--binary", dest="binary", |
| 41 | action="store_true", default=False, |
| 42 | help="The toolchain should use binaries stored in " |
| 43 | "the install/ directory.") |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 44 | |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 45 | options = parser.parse_args()[0] |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 46 | |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 47 | if options.toolchain_root is None or options.board is None: |
| 48 | parser.print_help() |
| 49 | sys.exit() |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 50 | |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 51 | if options.chromeos_root is None: |
| 52 | options.chromeos_root = "../.." |
| 53 | |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 54 | portage_flags = "" |
| 55 | if options.binary == True: |
| 56 | # FIXME(asharif): This should be using --usepkg but that was not working. |
| 57 | portage_flags = "--usepkgonly" |
| 58 | |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 59 | f = open(options.chromeos_root + "/src/overlays/overlay-" + |
| 60 | options.board + "/toolchain.conf", "r") |
| 61 | target = f.read() |
| 62 | f.close() |
| 63 | target = target.strip() |
asharif | 80c6e55 | 2013-02-15 04:35:40 +0000 | [diff] [blame] | 64 | features = "noclean userfetch userpriv usersandbox" |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 65 | env = CreateEnvVarString(" FEATURES", features) |
asharif | 80c6e55 | 2013-02-15 04:35:40 +0000 | [diff] [blame] | 66 | env += CreateEnvVarString(" PORTAGE_USERNAME", getpass.getuser()) |
| 67 | version_number = utils.GetRoot(rootdir)[1] |
| 68 | version_dir = "/home/${USER}/toolchain_root/" + version_number |
| 69 | env += CreateEnvVarString(" PORT_LOGDIR", version_dir + "/logs") |
| 70 | env += CreateEnvVarString(" PKGDIR", version_dir + "/install") |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 71 | env += CreateEnvVarString(" PORTAGE_BINHOST", version_dir + |
| 72 | "/cross/" + target) |
asharif | 80c6e55 | 2013-02-15 04:35:40 +0000 | [diff] [blame] | 73 | env += CreateEnvVarString(" PORTAGE_TMPDIR", version_dir + "/objects") |
| 74 | if options.force == True: |
| 75 | BuildTC(options.chromeos_root, options.toolchain_root, env, target, |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 76 | True, options.incremental, portage_flags) |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 77 | BuildTC(options.chromeos_root, options.toolchain_root, env, target, |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 78 | options.clean, options.incremental, portage_flags) |
| 79 | |
| 80 | |
| 81 | def CreateCrossdevPortageFlags(portage_flags): |
| 82 | if not portage_flags: |
| 83 | return "" |
| 84 | crossdev_flags = " --portage " |
| 85 | crossdev_flags += " --portage ".join(portage_flags.split(" ")) |
| 86 | return crossdev_flags |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 87 | |
| 88 | |
| 89 | def CreateEnvVarString(variable, value): |
| 90 | return variable + "=" + EscapeQuoteString(value) |
| 91 | |
| 92 | |
| 93 | def EscapeQuoteString(string): |
| 94 | return "\\\"" + string + "\\\"" |
| 95 | |
| 96 | |
| 97 | def BuildTC(chromeos_root, toolchain_root, env, target, uninstall, |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 98 | incremental_component, portage_flags): |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 99 | """Build the toolchain.""" |
| 100 | binutils_version = "2.20.1-r1" |
| 101 | gcc_version = "9999" |
| 102 | libc_version = "2.10.1-r1" |
| 103 | kernel_version = "2.6.30-r1" |
asharif | 80c6e55 | 2013-02-15 04:35:40 +0000 | [diff] [blame] | 104 | if incremental_component is not None and incremental_component: |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 105 | env += " FEATURES+=" + EscapeQuoteString("keepwork") |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 106 | |
| 107 | if uninstall == True: |
| 108 | tflag = " -C " |
| 109 | else: |
| 110 | tflag = " -t " |
| 111 | |
| 112 | command = (rootdir + "/tc-enter-chroot.sh") |
| 113 | if chromeos_root is not None: |
| 114 | command += " --chromeos_root=" + chromeos_root |
| 115 | if toolchain_root is not None: |
| 116 | command += " --toolchain_root=" + toolchain_root |
| 117 | command += " -- sudo " + env |
| 118 | |
| 119 | if incremental_component == "binutils": |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 120 | command += (" emerge =cross-" + target + "/binutils-" + binutils_version + |
| 121 | portage_flags) |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 122 | elif incremental_component == "gcc": |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 123 | command += (" emerge =cross-" + target + "/gcc-" + gcc_version + |
| 124 | portage_flags) |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 125 | elif incremental_component == "libc" or incremental_component == "glibc": |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 126 | command += (" emerge =cross-" + target + "/glibc-" + libc_version + |
| 127 | portage_flags) |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 128 | else: |
| 129 | command += (" crossdev -v " + tflag + target + |
| 130 | " --binutils " + binutils_version + |
| 131 | " --libc " + libc_version + |
| 132 | " --gcc " + gcc_version + |
| 133 | " --kernel " + kernel_version + |
| 134 | " --portage -b --portage --newuse") |
asharif | e2cca30 | 2013-02-15 04:35:42 +0000 | [diff] [blame^] | 135 | crossdev_flags = CreateCrossdevPortageFlags(portage_flags) |
| 136 | command += crossdev_flags |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 137 | |
| 138 | retval = utils.RunCommand(command) |
| 139 | return retval |
| 140 | |
| 141 | if __name__ == "__main__": |
| 142 | Main() |