blob: df6a4a1c21f4c8b2b4678bf3e70a368b21895f71 [file] [log] [blame]
raymes49fd5a32013-02-15 04:55:27 +00001#!/usr/bin/python2.6
2#
3# Copyright 2010 Google Inc. All Rights Reserved.
4
5"""Script to checkout the ChromeOS source.
6
7This script sets up the ChromeOS source in the given directory, matching a
8particular release of ChromeOS.
9"""
10
11__author__ = "raymes@google.com (Raymes Khoury)"
12
13import optparse
asharif8697d4e2013-02-15 09:18:09 +000014import os
raymes49fd5a32013-02-15 04:55:27 +000015import sys
16from utils import command_executer
17from utils import logger
18from utils import utils
19import build_chromeos
20
21cmd_executer = None
22
23
24def Usage(parser, message):
25 print "ERROR: " + message
26 parser.print_help()
27 sys.exit(0)
28
29
asharif8697d4e2013-02-15 09:18:09 +000030def Main(argv):
raymes49fd5a32013-02-15 04:55:27 +000031 """Build Chrome browser."""
32 # Common initializations
33 global cmd_executer
34 cmd_executer = command_executer.GetCommandExecuter()
35
36 parser = optparse.OptionParser()
37 parser.add_option("--chromeos_root", dest="chromeos_root",
38 help="Target directory for ChromeOS installation.")
raymes49fd5a32013-02-15 04:55:27 +000039 parser.add_option("--version", dest="version")
40 parser.add_option("--cflags", dest="cflags",
asharif32ed84e2013-02-15 05:15:55 +000041 default="",
raymes49fd5a32013-02-15 04:55:27 +000042 help="CFLAGS for the ChromeOS packages")
43 parser.add_option("--cxxflags", dest="cxxflags",
asharif32ed84e2013-02-15 05:15:55 +000044 default="",
raymes49fd5a32013-02-15 04:55:27 +000045 help="CXXFLAGS for the ChromeOS packages")
46 parser.add_option("--ldflags", dest="ldflags",
asharif32ed84e2013-02-15 05:15:55 +000047 default="",
raymes49fd5a32013-02-15 04:55:27 +000048 help="LDFLAGS for the ChromeOS packages")
49 parser.add_option("--board", dest="board",
50 help="ChromeOS target board, e.g. x86-generic")
asharif8697d4e2013-02-15 09:18:09 +000051 parser.add_option("--label", dest="label",
52 help="Optional label to apply to the ChromeOS image.")
raymes49fd5a32013-02-15 04:55:27 +000053
asharif8697d4e2013-02-15 09:18:09 +000054 options = parser.parse_args(argv)[0]
raymes49fd5a32013-02-15 04:55:27 +000055
56 if options.chromeos_root is None:
57 Usage(parser, "--chromeos_root must be set")
58
59 if options.board is None:
60 Usage(parser, "--board must be set")
61
raymes49fd5a32013-02-15 04:55:27 +000062 if options.version is None:
63 logger.GetLogger().LogOutput("No Chrome version given so "
64 "using the default checked in version.")
65 chrome_version = ""
66 else:
67 chrome_version = "CHROME_VERSION=%s" % options.version
68
raymes49fd5a32013-02-15 04:55:27 +000069 # Emerge the browser
70 ret = (build_chromeos.
asharif8697d4e2013-02-15 09:18:09 +000071 ExecuteCommandInChroot(options.chromeos_root,
raymes49fd5a32013-02-15 04:55:27 +000072 "CHROME_ORIGIN=SERVER_SOURCE %s "
raymesaa351762013-02-15 04:56:51 +000073 "CFLAGS=\"$(portageq-%s envvar CFLAGS) %s\" "
74 "LDFLAGS=\"$(portageq-%s envvar LDFLAGS) %s\" "
75 "CXXFLAGS=\"$(portageq-%s envvar CXXFLAGS) %s\" "
asharif9d6ccaa2013-02-15 04:57:17 +000076 "emerge-%s --buildpkg chromeos-chrome" %
raymesaa351762013-02-15 04:56:51 +000077 (chrome_version, options.board, options.cflags,
78 options.board, options.ldflags, options.board,
79 options.cxxflags, options.board)))
raymes49fd5a32013-02-15 04:55:27 +000080
81 utils.AssertTrue(ret == 0, "build_packages failed")
82
83 # Build image
84 ret = (build_chromeos.
asharif8697d4e2013-02-15 09:18:09 +000085 ExecuteCommandInChroot(options.chromeos_root,
asharife0cc3052013-02-15 05:20:48 +000086 utils.GetBuildImageCommand(options.board)))
raymes49fd5a32013-02-15 04:55:27 +000087
88 utils.AssertTrue(ret == 0, "build_image failed")
89
90 # Mod image for test
91 ret = (build_chromeos.
asharif8697d4e2013-02-15 09:18:09 +000092 ExecuteCommandInChroot(options.chromeos_root,
asharife0cc3052013-02-15 05:20:48 +000093 utils.GetModImageForTestCommand(options.board)))
raymes49fd5a32013-02-15 04:55:27 +000094
95 utils.AssertTrue(ret == 0, "mod_image_for_test failed")
96
asharif8697d4e2013-02-15 09:18:09 +000097 flags_file_name = "chrome_flags.txt"
98 flags_file_path = ("%s/src/build/images/%s/latest/%s" %
99 (options.chromeos_root,
100 options.board,
101 flags_file_name))
102 flags_file = open(flags_file_path, "wb")
103 flags_file.write("CFLAGS=%s\n" % options.cflags)
104 flags_file.write("CXXFLAGS=%s\n" % options.cxxflags)
105 flags_file.write("LDFLAGS=%s\n" % options.ldflags)
106 flags_file.close()
107
108
109 if options.label:
110 image_dir_path = ("%s/src/build/images/%s/latest" %
111 (options.chromeos_root,
112 options.board))
113 real_image_dir_path = os.path.realpath(image_dir_path)
114 command = ("ln -sf -T %s %s/%s" %
115 (os.path.basename(real_image_dir_path),
116 os.path.dirname(real_image_dir_path),
117 options.label))
118
119 ret = cmd_executer.RunCommand(command)
120 utils.AssertExit(ret == 0,
121 "Failed to apply symlink label %s" % options.label)
122
123 return ret
124
raymes49fd5a32013-02-15 04:55:27 +0000125if __name__ == "__main__":
asharif8697d4e2013-02-15 09:18:09 +0000126 Main(sys.argv)