raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 1 | #!/usr/bin/python2.6 |
| 2 | # |
| 3 | # Copyright 2010 Google Inc. All Rights Reserved. |
| 4 | |
| 5 | """Script to checkout the ChromeOS source. |
| 6 | |
| 7 | This script sets up the ChromeOS source in the given directory, matching a |
| 8 | particular release of ChromeOS. |
| 9 | """ |
| 10 | |
| 11 | __author__ = "raymes@google.com (Raymes Khoury)" |
| 12 | |
| 13 | import optparse |
| 14 | import os |
| 15 | import sys |
asharif | e3668f1 | 2013-02-15 04:46:29 +0000 | [diff] [blame] | 16 | import tc_enter_chroot |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 17 | from utils import command_executer |
| 18 | from utils import logger |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 19 | from utils import utils |
| 20 | |
asharif | e3668f1 | 2013-02-15 04:46:29 +0000 | [diff] [blame] | 21 | |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 22 | def Usage(parser, message): |
| 23 | print "ERROR: " + message |
| 24 | parser.print_help() |
| 25 | sys.exit(0) |
| 26 | |
raymes | 49fd5a3 | 2013-02-15 04:55:27 +0000 | [diff] [blame^] | 27 | #TODO(raymes): move this to a common utils file. |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 28 | def ExecuteCommandInChroot(chromeos_root, toolchain_root, command, |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 29 | return_output=False, chrome_root=""): |
asharif | e3668f1 | 2013-02-15 04:46:29 +0000 | [diff] [blame] | 30 | """Executes a command in the chroot.""" |
raymes | 49fd5a3 | 2013-02-15 04:55:27 +0000 | [diff] [blame^] | 31 | global cmd_executer |
| 32 | cmd_executer = command_executer.GetCommandExecuter() |
| 33 | |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 34 | chrome_mount = "" |
| 35 | if chrome_root: |
| 36 | chrome_mount = "--chrome_root=" + chromeos_root + "/" + chrome_root |
raymes | 49fd5a3 | 2013-02-15 04:55:27 +0000 | [diff] [blame^] | 37 | if toolchain_root is None: |
| 38 | return cmd_executer.RunCommand(chromeos_root + |
| 39 | "/src/scripts/enter_chroot.sh %s -- %s" |
| 40 | % ("chrome_root=" + chrome_root, |
| 41 | command)) |
| 42 | else: |
| 43 | argv = [os.path.dirname(os.path.abspath(__file__)) + "/tc_enter_chroot.py", |
| 44 | "--chromeos_root=" + chromeos_root, |
| 45 | "--toolchain_root=" + toolchain_root, |
| 46 | chrome_mount, |
| 47 | "\n" + command] |
| 48 | return tc_enter_chroot.Main(argv) |
asharif | e3668f1 | 2013-02-15 04:46:29 +0000 | [diff] [blame] | 49 | |
| 50 | |
| 51 | def MakeChroot(chromeos_root, clobber_chroot=False): |
| 52 | """Make a chroot given a chromeos checkout.""" |
| 53 | if (not os.path.isdir(chromeos_root + "/chroot") |
| 54 | or clobber_chroot): |
| 55 | commands = [] |
| 56 | commands.append("cd " + chromeos_root + "/src/scripts") |
| 57 | clobber_chroot = "" |
| 58 | if clobber_chroot: |
| 59 | clobber_chroot = "--replace" |
| 60 | commands.append("./make_chroot --fast " + clobber_chroot) |
asharif | 967d700 | 2013-02-15 04:51:00 +0000 | [diff] [blame] | 61 | ret = command_executer.GetCommandExecuter().RunCommands(commands) |
asharif | e3668f1 | 2013-02-15 04:46:29 +0000 | [diff] [blame] | 62 | utils.AssertTrue(ret == 0, "make_chroot failed") |
| 63 | else: |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 64 | logger.GetLogger().LogOutput("Did not make_chroot because it already exists") |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 65 | |
| 66 | |
bjanakiraman | 6496e5f | 2013-02-15 04:50:58 +0000 | [diff] [blame] | 67 | def Main(argv): |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 68 | """Build ChromeOS.""" |
| 69 | # Common initializations |
asharif | 5a9bb46 | 2013-02-15 04:50:57 +0000 | [diff] [blame] | 70 | cmd_executer = command_executer.GetCommandExecuter() |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 71 | |
| 72 | parser = optparse.OptionParser() |
| 73 | parser.add_option("--chromeos_root", dest="chromeos_root", |
| 74 | help="Target directory for ChromeOS installation.") |
| 75 | parser.add_option("--toolchain_root", dest="toolchain_root", |
| 76 | help="The gcctools directory of your P4 checkout.") |
| 77 | parser.add_option("--clobber_chroot", dest="clobber_chroot", |
| 78 | action="store_true", help= |
| 79 | "Delete the chroot and start fresh", default=False) |
| 80 | parser.add_option("--clobber_board", dest="clobber_board", |
| 81 | action="store_true", |
| 82 | help="Delete the board and start fresh", default=False) |
| 83 | parser.add_option("--cflags", dest="cflags", |
| 84 | help="CFLAGS for the ChromeOS packages") |
| 85 | parser.add_option("--cxxflags", dest="cxxflags", |
| 86 | help="CXXFLAGS for the ChromeOS packages") |
| 87 | parser.add_option("--ldflags", dest="ldflags", |
| 88 | help="LDFLAGS for the ChromeOS packages") |
| 89 | parser.add_option("--board", dest="board", |
| 90 | help="ChromeOS target board, e.g. x86-generic") |
| 91 | |
bjanakiraman | 6496e5f | 2013-02-15 04:50:58 +0000 | [diff] [blame] | 92 | options = parser.parse_args(argv[1:])[0] |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 93 | |
| 94 | if options.chromeos_root is None: |
| 95 | Usage(parser, "--chromeos_root must be set") |
| 96 | |
| 97 | if options.toolchain_root is None: |
| 98 | Usage(parser, "--toolchain_root must be set") |
| 99 | |
| 100 | if options.board is None: |
| 101 | Usage(parser, "--board must be set") |
| 102 | |
asharif | e3668f1 | 2013-02-15 04:46:29 +0000 | [diff] [blame] | 103 | MakeChroot(options.chromeos_root, options.clobber_chroot) |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 104 | |
| 105 | # Setup board |
raymes | 04164a1 | 2013-02-15 04:36:03 +0000 | [diff] [blame] | 106 | if not os.path.isdir(options.chromeos_root + "/chroot/build/" |
| 107 | + options.board) or options.clobber_board: |
raymes | 5f35b92 | 2013-02-15 04:35:57 +0000 | [diff] [blame] | 108 | force = "" |
| 109 | if options.clobber_board: |
| 110 | force = "--force" |
raymes | 04164a1 | 2013-02-15 04:36:03 +0000 | [diff] [blame] | 111 | # Run build_tc.py from binary package |
bjanakiraman | 6496e5f | 2013-02-15 04:50:58 +0000 | [diff] [blame] | 112 | rootdir = utils.GetRoot(argv[0])[0] |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 113 | ret = cmd_executer.RunCommand(rootdir + "/build_tc.py --chromeos_root=%s " |
| 114 | "--toolchain_root=%s --board=%s -B" |
| 115 | % (options.chromeos_root, |
| 116 | options.toolchain_root, options.board)) |
raymes | 04164a1 | 2013-02-15 04:36:03 +0000 | [diff] [blame] | 117 | utils.AssertTrue(ret == 0, "build_tc.py failed") |
raymes | 5f6be5f | 2013-02-15 04:36:13 +0000 | [diff] [blame] | 118 | version_number = utils.GetRoot(rootdir)[1] |
asharif | 541b639 | 2013-02-15 04:50:38 +0000 | [diff] [blame] | 119 | pkgdir = "/usr/local/toolchain_root/" + version_number + "/output/pkgs" |
raymes | 5f35b92 | 2013-02-15 04:35:57 +0000 | [diff] [blame] | 120 | ret = ExecuteCommandInChroot(options.chromeos_root, options.toolchain_root, |
raymes | 5f6be5f | 2013-02-15 04:36:13 +0000 | [diff] [blame] | 121 | "PKGDIR=%s ./setup_board --board=%s " |
| 122 | " --gcc_version=9999 " |
| 123 | "%s" % (pkgdir, options.board, force)) |
raymes | 5f35b92 | 2013-02-15 04:35:57 +0000 | [diff] [blame] | 124 | utils.AssertTrue(ret == 0, "setup_board failed") |
| 125 | else: |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 126 | logger.GetLogger().LogOutput("Did not setup_board " |
| 127 | "because it already exists") |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 128 | |
| 129 | # Modify make.conf to add CFLAGS/CXXFLAGS/LDFLAGS |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 130 | ret1 = ExecuteCommandInChroot(options.chromeos_root, options.toolchain_root, |
| 131 | "[ -e /build/%s/etc/make.conf.orig ] || " |
| 132 | "sudo mv /build/%s/etc/make.conf " |
| 133 | "/build/%s/etc/make.conf.orig" |
| 134 | % (options.board, options.board, options.board)) |
asharif | 541b639 | 2013-02-15 04:50:38 +0000 | [diff] [blame] | 135 | makeconf = ("source make.conf.orig\n") |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 136 | #"CFLAGS='%s'\\\nCXXFLAGS='%s'\\\nLDFLAGS='%s'\\\n" % |
| 137 | #(options.cflags, options.cxxflags, options.ldflags)) |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 138 | ret2 = ExecuteCommandInChroot(options.chromeos_root, options.toolchain_root, |
asharif | 541b639 | 2013-02-15 04:50:38 +0000 | [diff] [blame] | 139 | "if [ -e /build/%s/etc/make.conf.orig ] ; " |
| 140 | "then sudo echo -e \"%s\" | sudo tee " |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 141 | "/build/%s/etc/make.conf > /dev/null ;" |
asharif | 541b639 | 2013-02-15 04:50:38 +0000 | [diff] [blame] | 142 | "else exit 1 ; fi" |
raymes | 5f6be5f | 2013-02-15 04:36:13 +0000 | [diff] [blame] | 143 | % (options.board, makeconf, options.board)) |
raymes | 5f35b92 | 2013-02-15 04:35:57 +0000 | [diff] [blame] | 144 | |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 145 | utils.AssertTrue(ret1 == 0 and ret2 == 0, "Could not modify make.conf") |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 146 | |
| 147 | # Find Chrome browser version |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 148 | chrome_version = cmd_executer.RunCommand("%s/src/scripts/chromeos_version.sh " |
asharif | 541b639 | 2013-02-15 04:50:38 +0000 | [diff] [blame] | 149 | "| grep CHROME_VERSION" |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 150 | % options.chromeos_root, True) |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 151 | |
| 152 | ret = chrome_version[0] |
| 153 | utils.AssertTrue(ret == 0, "Could not determine Chrome browser version") |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 154 | |
| 155 | chrome_version = chrome_version[1].strip().split("=") |
| 156 | if len(chrome_version) == 2: |
| 157 | chrome_version = chrome_version[1] |
| 158 | else: |
| 159 | chrome_version = "" |
| 160 | |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 161 | # Build packages |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 162 | ret = ExecuteCommandInChroot(options.chromeos_root, options.toolchain_root, |
raymes | e91a6e6 | 2013-02-15 04:35:51 +0000 | [diff] [blame] | 163 | "CHROME_ORIGIN=SERVER_SOURCE CHROME_VERSION=%s " |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 164 | "./build_packages --withdev " |
| 165 | "--board=%s --withtest --withautotest" |
| 166 | % (chrome_version, options.board), |
| 167 | chrome_root="chrome_browser") |
| 168 | |
| 169 | utils.AssertTrue(ret == 0, "build_packages failed") |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 170 | |
| 171 | # Build image |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 172 | ret = ExecuteCommandInChroot(options.chromeos_root, options.toolchain_root, |
| 173 | "./build_image --board=%s" % options.board) |
| 174 | |
| 175 | utils.AssertTrue(ret == 0, "build_image failed") |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 176 | |
| 177 | # Mod image for test |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 178 | ret = ExecuteCommandInChroot(options.chromeos_root, options.toolchain_root, |
| 179 | "./mod_image_for_test.sh --board=%s" |
| 180 | % options.board) |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 181 | |
raymes | bfb5799 | 2013-02-15 04:35:45 +0000 | [diff] [blame] | 182 | utils.AssertTrue(ret == 0, "mod_image_for_test failed") |
raymes | 5154d7f | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 183 | |
| 184 | if __name__ == "__main__": |
bjanakiraman | 6496e5f | 2013-02-15 04:50:58 +0000 | [diff] [blame] | 185 | Main(sys.argv) |