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