1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)# Copyright 2013 The Chromium Authors. All rights reserved.
2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be
3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)# found in the LICENSE file.
4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)import os
6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)from pylib import constants
8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)def GetMostRecentHostPath(file_name):
11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  """Returns the most recent existing full path for the given file name.
12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Returns: An empty string if no path could be found.
14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  """
15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  out_dir = os.path.join(
16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      constants.DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'))
17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  candidate_paths = map(
18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      lambda build_type: os.path.join(out_dir, build_type, file_name),
19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      ['Debug', 'Release'])
20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  candidate_paths = filter(os.path.exists, candidate_paths)
21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  candidate_paths = sorted(candidate_paths, key=os.path.getmtime, reverse=True)
22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  candidate_paths.append('')
23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return candidate_paths[0]
24