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