Synced repos to: 60208
diff --git a/crosperf/autotest_runner.py b/crosperf/autotest_runner.py
index 5df71ac..3b91d81 100644
--- a/crosperf/autotest_runner.py
+++ b/crosperf/autotest_runner.py
@@ -1,9 +1,8 @@
 #!/usr/bin/python
-
+#
 # Copyright 2011 Google Inc. All Rights Reserved.
 
 from utils import command_executer
-from utils import utils
 
 
 class AutotestRunner(object):
diff --git a/crosperf/benchmark_run.py b/crosperf/benchmark_run.py
index b2822a4..f7c37c3 100644
--- a/crosperf/benchmark_run.py
+++ b/crosperf/benchmark_run.py
@@ -11,6 +11,10 @@
 from results_cache import Result
 from utils import logger
 from utils import command_executer
+from autotest_runner import AutotestRunner
+from perf_processor import PerfProcessor
+from results_cache import ResultsCache
+
 
 STATUS_FAILED = "FAILED"
 STATUS_SUCCEEDED = "SUCCEEDED"
@@ -24,7 +28,7 @@
   def __init__(self, name, benchmark_name, autotest_name, autotest_args,
                label_name, chromeos_root, chromeos_image, board, iteration,
                cache_conditions, outlier_range, profile_counters, profile_type,
-               machine_manager, cache, autotest_runner, perf_processor,
+               machine_manager,
                logger_to_use):
     threading.Thread.__init__(self)
     self.name = name
@@ -37,6 +41,7 @@
     self.chromeos_image = os.path.expanduser(chromeos_image)
     self.board = board
     self.iteration = iteration
+    self.result = None
     self.results = {}
     self.terminated = False
     self.retval = None
@@ -46,9 +51,9 @@
     self.profile_counters = profile_counters
     self.profile_type = profile_type
     self.machine_manager = machine_manager
-    self.cache = cache
-    self.autotest_runner = autotest_runner
-    self.perf_processor = perf_processor
+    self.cache = ResultsCache()
+    self.autotest_runner = AutotestRunner(self._logger)
+    self.perf_processor = None
     self.machine = None
     self.full_name = self.autotest_name
     self.cache_conditions = cache_conditions
@@ -58,58 +63,26 @@
     self.failure_reason = ""
     self._ce = command_executer.GetCommandExecuter(self._logger)
 
-  def MeanExcludingOutliers(self, array, outlier_range):
-    """Return the arithmetic mean excluding outliers."""
-    mean = sum(array) / len(array)
-    array2 = []
-
-    for v in array:
-      if mean != 0 and abs(v - mean) / mean < outlier_range:
-        array2.append(v)
-
-    if array2:
-      return sum(array2) / len(array2)
-    else:
-      return mean
-
-  def ParseResults(self, output):
-    p = re.compile("^-+.*?^-+", re.DOTALL | re.MULTILINE)
-    matches = p.findall(output)
-    for i in range(len(matches)):
-      results = matches[i]
-      results_dict = {}
-      for line in results.splitlines()[1:-1]:
-        mo = re.match("(.*\S)\s+\[\s+(PASSED|FAILED)\s+\]", line)
-        if mo:
-          results_dict[mo.group(1)] = mo.group(2)
-          continue
-        mo = re.match("(.*\S)\s+(.*)", line)
-        if mo:
-          results_dict[mo.group(1)] = mo.group(2)
-
-      return results_dict
-    return {}
-
-  def ProcessResults(self, result, cache_hit):
+  def ProcessResults(self):
     # Generate results from the output file.
-    results_dir = self._GetResultsDir(result.out)
-    self.full_name = os.path.basename(results_dir)
-    self.results = result.keyvals
+    self.full_name = os.path.basename(self.results_dir)
+    self.results = self.result.keyvals
 
     # Store the autotest output in the cache also.
-    if not cache_hit:
-      self.cache.StoreResult(result)
-      self.cache.StoreAutotestOutput(results_dir)
+    if not self.cache_hit:
+      self.cache.StoreResult(self.result)
+      self.cache.StoreAutotestOutput(self.results_dir)
 
+    self.perf_processor = PerfProcessor(self.results_dir,
+                                        self.chromeos_root,
+                                        self.board,
+                                        self._logger)
     # Generate a perf report and cache it.
     if self.profile_type:
-      if cache_hit:
+      if self.cache_hit:
         self.perf_results = self.cache.ReadPerfResults()
       else:
-        self.perf_results = (self.perf_processor.
-                             GeneratePerfResults(results_dir,
-                                                 self.chromeos_root,
-                                                 self.board))
+        self.perf_results = self.perf_processor.GeneratePerfResults()
         self.cache.StorePerfResults(self.perf_results)
 
     # If there are valid results from perf stat, combine them with the
@@ -139,31 +112,32 @@
                       self.cache_conditions,
                       self._logger)
 
-      result = self.cache.ReadResult()
-      self.cache_hit = (result is not None)
+      self.result = self.cache.ReadResult()
+      self.cache_hit = (self.result is not None)
 
-      if result:
+      if self.result:
         self._logger.LogOutput("%s: Cache hit." % self.name)
-        self._logger.LogOutput(result.out + "\n" + result.err)
+        self._logger.LogOutput(self.result.out + "\n" + self.result.err)
+        self.results_dir = self._GetResultsDir(self.result.out)
       else:
         self._logger.LogOutput("%s: No cache hit." % self.name)
         self.status = STATUS_WAITING
         # Try to acquire a machine now.
         self.machine = self.AcquireMachine()
         self.cache.remote = self.machine.name
-        result = self.RunTest(self.machine)
+        self.result = self.RunTest(self.machine)
 
       if self.terminated:
         return
 
-      if not result.retval:
+      if not self.result.retval:
         self.status = STATUS_SUCCEEDED
       else:
         if self.status != STATUS_FAILED:
           self.status = STATUS_FAILED
           self.failure_reason = "Return value of autotest was non-zero."
 
-      self.ProcessResults(result, self.cache_hit)
+      self.ProcessResults()
 
     except Exception, e:
       self._logger.LogError("Benchmark run: '%s' failed: %s" % (self.name, e))
@@ -216,18 +190,18 @@
     self.run_completed = True
 
     # Include the keyvals in the result.
-    results_dir = self._GetResultsDir(out)
-    keyvals = self._GetKeyvals(results_dir)
+    self.results_dir = self._GetResultsDir(out)
+    keyvals = self._GetKeyvals()
     keyvals["retval"] = retval
 
     result = Result(out, err, retval, keyvals)
 
     return result
 
-  def _GetKeyvals(self, results_dir):
+  def _GetKeyvals(self):
     full_results_dir = os.path.join(self.chromeos_root,
                                     "chroot",
-                                    results_dir.lstrip("/"))
+                                    self.results_dir.lstrip("/"))
     command = "find %s -regex .*results/keyval$" % full_results_dir
     [ret, out, err] = self._ce.RunCommand(command, return_output=True)
     keyvals_dict = {}
diff --git a/crosperf/experiment.py b/crosperf/experiment.py
index 83889b0..8ac1a70 100644
--- a/crosperf/experiment.py
+++ b/crosperf/experiment.py
@@ -66,9 +66,6 @@
           logger_to_use = logger.Logger(os.path.dirname(__file__),
                                         "run.%s" % (full_name),
                                         True)
-          ar = AutotestRunner(logger_to_use=logger_to_use)
-          rc = ResultsCache()
-          pp = PerfProcessor(logger_to_use=logger_to_use)
           benchmark_run = BenchmarkRun(benchmark_run_name,
                                        benchmark.name,
                                        benchmark.autotest_name,
@@ -83,9 +80,6 @@
                                        benchmark.profile_counters,
                                        benchmark.profile_type,
                                        self.machine_manager,
-                                       rc,
-                                       ar,
-                                       pp,
                                        logger_to_use)
 
           benchmark_runs.append(benchmark_run)
diff --git a/crosperf/experiment_runner.py b/crosperf/experiment_runner.py
index 3da1d63..6b73f5d 100644
--- a/crosperf/experiment_runner.py
+++ b/crosperf/experiment_runner.py
@@ -8,6 +8,7 @@
 from experiment_status import ExperimentStatus
 from results_report import HTMLResultsReport
 from results_report import TextResultsReport
+from utils import command_executer
 from utils import logger
 from utils.email_sender import EmailSender
 from utils.file_utils import FileUtils
@@ -20,6 +21,7 @@
   def __init__(self, experiment):
     self._experiment = experiment
     self.l = logger.GetLogger()
+    self._ce = command_executer.GetCommandExecuter(self.l)
     self._terminated = False
 
   def _Run(self, experiment):
@@ -97,6 +99,11 @@
                                 benchmark_run.perf_results.report)
           FileUtils().WriteFile(os.path.join(benchmark_run_path, "perf.out"),
                                 benchmark_run.perf_results.output)
+          if os.path.isfile(benchmark_run.perf_processor.host_data_file):
+            self._ce.RunCommand("cp %s %s" %
+                                (benchmark_run.perf_processor.host_data_file,
+                                 os.path.join(benchmark_run_path, "perf.data")))
+
       except Exception, e:
         self.l.LogError(e)
 
diff --git a/crosperf/perf_processor.py b/crosperf/perf_processor.py
index 031f35d..8e6f1cd 100644
--- a/crosperf/perf_processor.py
+++ b/crosperf/perf_processor.py
@@ -1,11 +1,11 @@
 #!/usr/bin/python
-
+#
 # Copyright 2011 Google Inc. All Rights Reserved.
 
 import os
 import re
+
 from utils import command_executer
-from utils import utils
 
 
 class PerfProcessor(object):
@@ -14,18 +14,54 @@
       self.report = report
       self.output = output
 
-  def __init__(self, logger_to_use=None):
+  def __init__(self, results_dir, chromeos_root, board, logger_to_use=None):
     self._logger = logger_to_use
     self._ce = command_executer.GetCommandExecuter(self._logger)
+    self._results_dir = results_dir
+    self._chromeos_root = chromeos_root
+    self._board = board
+    self._perf_relative_dir = os.path.basename(self._results_dir)
+    self.host_data_file = self.FindSingleFile(
+                            "perf.data", os.path.join(
+                              chromeos_root,
+                              "chroot",
+                              self._results_dir.lstrip("/")))
+    self.perf_out = self.FindSingleFile(
+                            "perf.out", os.path.join(
+                              chromeos_root,
+                              "chroot",
+                              self._results_dir.lstrip("/")))
 
-  def GeneratePerfResults(self, results_dir, chromeos_root, board):
-    perf_location = os.path.join(results_dir,
-                                 os.path.basename(results_dir),
-                                 "profiling/iteration.1")
-    host_perf_location = os.path.join(chromeos_root, "chroot",
-                                      perf_location.lstrip("/"))
-    report = self._GeneratePerfReport(perf_location, chromeos_root, board)
-    output = self._ReadPerfOutput(host_perf_location)
+  def FindSingleFile(self, name, path):
+    find_command = ("find %s -name %s" % (path, name))
+    ret, out, err = self._ce.RunCommand(find_command, return_output=True)
+    if ret == 0:
+      data_files = out.splitlines()
+      if len(data_files) == 0:
+         # No data file, no report to generate.
+         data_file = None
+      else:
+         assert len(data_files) == 1, "More than 1 perf.out file found"
+         data_file = data_files[0]
+    return data_file
+
+
+  def GeneratePerfResults(self):
+    perf_location = os.path.join(self._results_dir,
+                                 self._perf_relative_dir)
+    if self.perf_out != None:
+      output = self._ReadPerfOutput()
+
+    if self.host_data_file != None:
+      perf_location = os.path.join(self._results_dir,
+                                   self._perf_relative_dir)
+      host_perf_location = os.path.dirname(self.host_data_file)
+      report = self._GeneratePerfReport(perf_location,
+                                        self._chromeos_root,
+                                        self._board)
+    else:
+      # lets make perf.report have output of stat...
+      report = output
     return PerfProcessor.PerfResults(report, output)
 
   def ParseStatResults(self, results):
@@ -38,16 +74,18 @@
         result[match.group(2)] = match.group(1)
     return result
 
-  def _ReadPerfOutput(self, perf_location):
-    perf_output_file = os.path.join(perf_location, "perf.out")
-    with open(perf_output_file, "rb") as f:
+  def _ReadPerfOutput(self):
+    with open(self.perf_out, "rb") as f:
       return f.read()
 
   def _GeneratePerfReport(self, perf_location, chromeos_root, board):
     perf_data_file = os.path.join(perf_location, "perf.data")
     # Attempt to build a perf report and keep it with the results.
     command = ("/usr/sbin/perf report --symfs=/build/%s"
-               " -i %s --stdio | head -n1000" % (board, perf_data_file))
+               " --vmlinux /build/%s/usr/lib/debug/boot/vmlinux"
+               " --kallsyms /build/%s/boot/System.map-*"
+               " -i %s --stdio | head -n1000" % (board, board, board,
+                                                 perf_data_file))
     _, out, _ = self._ce.ChrootRunCommand(chromeos_root,
                                           command, return_output=True)
     return out
diff --git a/crosperf/results_cache.py b/crosperf/results_cache.py
index b8b495e..0b921b0 100644
--- a/crosperf/results_cache.py
+++ b/crosperf/results_cache.py
@@ -1,5 +1,5 @@
 #!/usr/bin/python
-
+#
 # Copyright 2011 Google Inc. All Rights Reserved.
 
 import getpass
@@ -8,11 +8,12 @@
 import os
 import pickle
 import re
+
 from image_checksummer import ImageChecksummer
 from perf_processor import PerfProcessor
 from utils import command_executer
 from utils import logger
-from utils import utils
+
 
 SCRATCH_DIR = "/home/%s/cros_scratch" % getpass.getuser()
 RESULTS_FILE = "results.txt"
@@ -44,6 +45,9 @@
   # Never a cache hit.
   FALSE = 4
 
+  # Cache hit if the image path matches the cached image path.
+  IMAGE_PATH_MATCH = 5
+
 
 class ResultsCache(object):
   CACHE_VERSION = 2
@@ -92,9 +96,18 @@
       checksum = "*"
     else:
       checksum = ImageChecksummer().Checksum(self.chromeos_image)
-    return (hashlib.md5(self.chromeos_image).hexdigest(),
+
+    if read and CacheConditions.IMAGE_PATH_MATCH not in self.cache_conditions:
+      image_path_checksum = "*"
+    else:
+      image_path_checksum = hashlib.md5(self.chromeos_image).hexdigest()
+
+    autotest_args_checksum = hashlib.md5(
+                             "".join(self.autotest_args)).hexdigest()
+
+    return (image_path_checksum,
             self.autotest_name, str(self.iteration),
-            ",".join(self.autotest_args),
+            autotest_args_checksum,
             checksum,
             remote,
             str(self.CACHE_VERSION))
diff --git a/image_chromeos.py b/image_chromeos.py
index 17812d4..f1497fb 100755
--- a/image_chromeos.py
+++ b/image_chromeos.py
@@ -18,6 +18,7 @@
 import tempfile
 from utils import command_executer
 from utils import logger
+from utils import misc
 from utils.file_utils import FileUtils
 
 checksum_file = "/usr/local/osimage_checksum_file"
@@ -68,10 +69,14 @@
     board = options.board
 
   if options.image is None:
-    image = (options.chromeos_root +
-             "/src/build/images/" + board +
-             "/latest/" +
-             "/chromiumos_image.bin")
+    images_dir = misc.GetImageDir(options.chromeos_root, board)
+    image = os.path.join(images_dir,
+                         "latest",
+                         "chromiumos_test_image.bin")
+    if not os.path.exists(image):
+      image = os.path.join(images_dir,
+                           "latest",
+                           "chromiumos_image.bin")
   else:
     image = options.image
     image = os.path.expanduser(image)
diff --git a/utils/command_executer.py b/utils/command_executer.py
index 32d86c9..c9a19ff 100644
--- a/utils/command_executer.py
+++ b/utils/command_executer.py
@@ -1,14 +1,19 @@
+#!/usr/bin/python
+#
+# Copyright 2011 Google Inc. All Rights Reserved.
+#
+
 import getpass
-import logger
 import os
 import pty
 import re
 import select
 import subprocess
-import sys
 import tempfile
 import time
-import utils
+
+import logger
+import misc
 
 mock_default = False
 
@@ -155,7 +160,8 @@
 
   def CrosRunCommand(self, cmd, return_output=False, machine=None,
       username=None, command_terminator=None, chromeos_root=None,
-                     command_timeout=None):
+                     command_timeout=None,
+                     terminated_timeout=10):
     """Run a command on a chromeos box"""
     self.logger.LogCmd(cmd)
     self.logger.LogFatalIf(not machine, "No machine provided!")
@@ -176,7 +182,8 @@
     command += "\necho \"$REMOTE_OUT\""
     retval = self.RunCommand(command, return_output,
                              command_terminator=command_terminator,
-                             command_timeout=command_timeout)
+                             command_timeout=command_timeout,
+                             terminated_timeout=terminated_timeout)
     if return_output:
       connect_signature = ("Initiating first contact with remote host\n" +
                            "Connection OK\n")
@@ -189,7 +196,8 @@
     return retval
 
   def ChrootRunCommand(self, chromeos_root, command, return_output=False,
-                       command_terminator=None):
+                       command_terminator=None, command_timeout=None,
+                       terminated_timeout=10):
     self.logger.LogCmd(command)
 
     handle, command_file = tempfile.mkstemp(dir=os.path.join(chromeos_root,
@@ -205,7 +213,9 @@
     command = "cd %s; cros_sdk -- ./%s" % (chromeos_root,
                                            os.path.basename(command_file))
     ret = self.RunCommand(command, return_output,
-                          command_terminator=command_terminator)
+                          command_terminator=command_terminator,
+                          command_timeout=command_timeout,
+                          terminated_timeout=terminated_timeout)
     os.remove(command_file)
     return ret
 
@@ -237,8 +247,8 @@
         cros_machine = dest_machine
 
       command = self.RemoteAccessInitCommand(chromeos_root, cros_machine)
-      src_parent, src_child = utils.GetRoot(src)
-      dest_parent, dest_child = utils.GetRoot(dest)
+      src_parent, src_child = misc.GetRoot(src)
+      dest_parent, dest_child = misc.GetRoot(dest)
       ssh_command = ("ssh -p ${FLAGS_ssh_port}" +
                      " -o StrictHostKeyChecking=no" +
                      " -o UserKnownHostsFile=$(mktemp)" +
diff --git a/utils/logger.py b/utils/logger.py
index 6f62640..1ef996e 100644
--- a/utils/logger.py
+++ b/utils/logger.py
@@ -2,10 +2,13 @@
 #
 # Copyright 2010 Google Inc. All Rights Reserved.
 
+# System modules
 import os.path
 import sys
 import traceback
-import utils
+
+# Local modules
+import misc
 
 
 class Logger(object):
@@ -137,7 +140,7 @@
   """Initialize a global logger. To be called only once."""
   global main_logger
   assert not main_logger, "The logger has already been initialized"
-  rootdir, basefilename = utils.GetRoot(script_name)
+  rootdir, basefilename = misc.GetRoot(script_name)
   main_logger = Logger(rootdir, basefilename, print_console)
 
 
diff --git a/utils/misc.py b/utils/misc.py
new file mode 100644
index 0000000..9111c6b
--- /dev/null
+++ b/utils/misc.py
@@ -0,0 +1,158 @@
+#!/usr/bin/python2.6
+#
+# Copyright 2010 Google Inc. All Rights Reserved.
+
+"""Utilities for toolchain build."""
+
+__author__ = "asharif@google.com (Ahmad Sharif)"
+
+import hashlib
+import os
+import re
+import stat
+import command_executer
+import logger
+import tempfile
+from contextlib import contextmanager
+
+
+def ApplySubs(string, *substitutions):
+  for pattern, replacement in substitutions:
+    string = re.sub(pattern, replacement, string)
+  return string
+
+
+def GetFilenameFromString(string):
+  return ApplySubs(string,
+                   ("/", "__"),
+                   ("\s", "_"),
+                   ("=", ""),
+                   ("\"", ""))
+
+
+def GetRoot(scr_name):
+  """Break up pathname into (dir+name)."""
+  abs_path = os.path.abspath(scr_name)
+  return (os.path.dirname(abs_path), os.path.basename(abs_path))
+
+
+def FormatQuotedCommand(command):
+  return ApplySubs(command,
+                   ("\"", "\\\""))
+
+
+def FormatCommands(commands):
+  return ApplySubs(str(commands),
+                   ("&&", "&&\n"),
+                   (";", ";\n"),
+                   ("\n+\s*", "\n"))
+
+
+def GetImageDir(chromeos_root, board):
+  return os.path.join(chromeos_root,
+                      "src",
+                      "build",
+                      "images",
+                      board)
+
+
+def LabelLatestImage(chromeos_root, board, label):
+  image_dir = GetImageDir(chromeos_root, board)
+  latest_image_dir = os.path.join(image_dir, "latest")
+  latest_image_dir = os.path.realpath(latest_image_dir)
+  latest_image_dir = os.path.basename(latest_image_dir)
+  with WorkingDirectory(image_dir):
+    command = "ln -sf -T %s %s" % (latest_image_dir, label)
+    ce = command_executer.GetCommandExecuter()
+    return ce.RunCommand(command)
+
+
+def DoesLabelExist(chromeos_root, board, label):
+  image_label = os.path.join(GetImageDir(chromeos_root, board),
+                             label)
+  return os.path.exists(image_label)
+
+
+def GetBuildPackagesCommand(board, usepkg=False):
+  if usepkg:
+    usepkg_flag = "--usepkg"
+  else:
+    usepkg_flag = "--nousepkg"
+  return ("./build_packages %s --withdev --withtest --withautotest "
+          "--skip_toolchain_update --nowithdebug --board=%s" %
+          (usepkg_flag, board))
+
+
+def GetBuildImageCommand(board):
+  return "./build_image --board=%s test" % board
+
+
+def GetSetupBoardCommand(board, gcc_version=None, binutils_version=None,
+                         usepkg=None, force=None):
+  options = []
+
+  if gcc_version:
+    options.append("--gcc_version=%s" % gcc_version)
+
+  if binutils_version:
+    options.append("--binutils_version=%s" % binutils_version)
+
+  if usepkg:
+    options.append("--usepkg")
+  else:
+    options.append("--nousepkg")
+
+  if force:
+    options.append("--force")
+
+  return "./setup_board --board=%s %s" % (board, " ".join(options))
+
+
+def CanonicalizePath(path):
+  path = os.path.expanduser(path)
+  path = os.path.realpath(path)
+  return path
+
+
+def GetCtargetFromBoard(board, chromeos_root):
+  base_board = board.split("_")[0]
+  command = ("source "
+             "../platform/dev/toolchain_utils.sh; get_ctarget_from_board %s" %
+             base_board)
+  ce = command_executer.GetCommandExecuter()
+  ret, out, err = ce.ChrootRunCommand(chromeos_root,
+                                      command,
+                                      return_output=True)
+  if ret != 0:
+    raise ValueError("Board %s is invalid!" % board)
+  return out.strip()
+
+
+def GetChromeSrcDir():
+  return "var/cache/distfiles/target/chrome-src/src"
+
+
+def GetEnvStringFromDict(env_dict):
+  return " ".join(["%s=\"%s\"" % var for var in env_dict.items()])
+
+
+def GetAllImages(chromeos_root, board):
+  ce = command_executer.GetCommandExecuter()
+  command = ("find %s/src/build/images/%s -name chromiumos_test_image.bin" %
+             (chromeos_root, board))
+  ret, out, err = ce.RunCommand(command, return_output=True)
+  return out.splitlines()
+
+
+@contextmanager
+def WorkingDirectory(new_dir):
+  old_dir = os.getcwd()
+  if old_dir != new_dir:
+    msg = "cd %s" % new_dir
+    logger.GetLogger().LogCmd(msg)
+  os.chdir(new_dir)
+  yield new_dir
+  if old_dir != new_dir:
+    msg = "cd %s" % old_dir
+    logger.GetLogger().LogCmd(msg)
+  os.chdir(old_dir)
diff --git a/utils/misc_test.py b/utils/misc_test.py
new file mode 100644
index 0000000..62742e3
--- /dev/null
+++ b/utils/misc_test.py
@@ -0,0 +1,22 @@
+# Copyright 2012 Google Inc. All Rights Reserved.
+
+"""Tests for misc."""
+
+__author__ = 'asharif@google.com (Ahmad Sharif)'
+
+# System modules
+import re
+import unittest
+
+# Local modules
+import misc
+
+
+class UtilsTest(unittest.TestCase):
+  def testGetFilenameFromString(self):
+    string = 'a /b=c"d'
+    filename = misc.GetFilenameFromString(string)
+    self.assertTrue(filename == 'a___bcd')
+
+if __name__ == '__main__':
+  unittest.main()
diff --git a/utils/utils.py b/utils/utils.py
deleted file mode 100755
index c2398c5..0000000
--- a/utils/utils.py
+++ /dev/null
@@ -1,106 +0,0 @@
-#!/usr/bin/python2.6
-#
-# Copyright 2010 Google Inc. All Rights Reserved.
-
-"""Utilities for toolchain build."""
-
-__author__ = "asharif@google.com (Ahmad Sharif)"
-
-import hashlib
-import os
-import re
-import stat
-import command_executer
-import logger
-import tempfile
-from contextlib import contextmanager
-
-
-def GetRoot(scr_name):
-  """Break up pathname into (dir+name)."""
-  abs_path = os.path.abspath(scr_name)
-  return (os.path.dirname(abs_path), os.path.basename(abs_path))
-
-
-def FormatQuotedCommand(command):
-  return command.replace("\"", "\\\"")
-
-
-def FormatCommands(commands):
-  output = str(commands)
-  output = re.sub("&&", "&&\n", output)
-  output = re.sub(";", ";\n", output)
-  output = re.sub("\n+\s*", "\n", output)
-  return output
-
-
-def GetBuildPackagesCommand(board):
-  return "./build_packages --nousepkg --withdev --withtest --withautotest " \
-         "--skip_toolchain_update --nowithdebug --board=%s" % board
-
-
-def GetBuildImageCommand(board):
-  return "./build_image --withdev --board=%s" % board
-
-
-def GetModImageForTestCommand(board):
-  return "./mod_image_for_test.sh --yes --board=%s" % board
-
-
-def GetSetupBoardCommand(board, gcc_version=None, binutils_version=None,
-                         usepkg=None, force=None):
-  options = []
-
-  if gcc_version:
-    options.append("--gcc_version=%s" % gcc_version)
-
-  if binutils_version:
-    options.append("--binutils_version=%s" % binutils_version)
-
-  if usepkg:
-    options.append("--usepkg")
-  else:
-    options.append("--nousepkg")
-
-  if force:
-    options.append("--force")
-
-  return "./setup_board --board=%s %s" % (board, " ".join(options))
-
-
-def CanonicalizePath(path):
-  path = os.path.expanduser(path)
-  path = os.path.realpath(path)
-  return path
-
-
-def GetCtargetFromBoard(board, chromeos_root):
-  base_board = board.split("_")[0]
-  command = ("cat"
-             " $(cros_overlay_list --board=%s --primary_only)/toolchain.conf" %
-             (base_board))
-  ce = command_executer.GetCommandExecuter()
-  ret, out, err = ce.ChrootRunCommand(chromeos_root,
-                                      command,
-                                      return_output=True)
-  if ret != 0:
-    raise ValueError("Board %s is invalid!" % board)
-  return out.strip()
-
-
-def GetChromeSrcDir():
-  return "var/cache/chromeos-chrome/chrome-src/src"
-
-
-@contextmanager
-def WorkingDirectory(new_dir):
-  old_dir = os.getcwd()
-  if old_dir != new_dir:
-    msg = "cd %s" % new_dir
-    logger.GetLogger().LogCmd(msg)
-  os.chdir(new_dir)
-  yield new_dir
-  if old_dir != new_dir:
-    msg = "cd %s" % old_dir
-    logger.GetLogger().LogCmd(msg)
-  os.chdir(old_dir)