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