Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Side by Side Diff: tools/llvm/driver/pathtools.py

Issue 8395028: Move tools/llvm/driver to pnacl/driver. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/llvm/driver/ldtools.py ('k') | tools/llvm/driver/pnacl-ar.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 #
6 # IMPORTANT NOTE: If you make local mods to this file, you must run:
7 # % tools/llvm/utman.sh driver
8 # in order for them to take effect in the scons build. This command
9 # updates the copy in the toolchain/ tree.
10 #
11
12 # pathtools is meant to be a drop-in replacement for "os.path"
13 #
14 # All pathnames passed into the driver are "normalized" to
15 # a posix representation (with / as the separator). For example,
16 # on Windows, C:\foo\bar.c would become /cygdrive/c/foo/bar.c
17 # On all other platforms, pathnames are already in the correct form.
18 #
19 # This is convenient for two reasons:
20 # 1) All of the tools invoked by the driver expect this type
21 # of pathname. (since on Windows, they are compiled with cygwin)
22 # 2) Everywhere in the driver, we can assume / is the path separator.
23 #
24 # Special functions:
25 #
26 # pathtools.normalize: Convert an OS-style path into a normalized path
27 # pathtools.tosys : Convert a normalized path into an OS-style path
28 # pathtools.touser : Convert a normalized path into a representation
29 # suitable for presentation to the user.
30
31 import os
32 import platform
33 import posixpath
34
35 # This is only true when the driver is invoked on
36 # Windows, but outside of Cygwin.
37 WINDOWS_MANGLE = 'windows' in platform.system().lower()
38
39 def normalize(syspath):
40 """ Convert an input path into a normalized path. """
41
42 if WINDOWS_MANGLE:
43 # Recognize paths which are already normalized.
44 # (Should only happen during recursive driver calls)
45 if syspath.startswith('/cygdrive/'):
46 return syspath
47
48 # Leave '-' alone since it represents stdout and not a real path.
49 if syspath == '-':
50 return syspath
51
52 components = os.path.abspath(syspath).split('\\')
53 drive = components[0]
54 components = components[1:]
55 assert(len(drive) == 2 and drive[1] == ':')
56 return '/cygdrive/%s/%s' % (drive[0].lower(), '/'.join(components))
57 else:
58 return syspath
59
60 # All functions below expect a normalized path as input
61
62 def touser(npath):
63 """ Convert a unix-style path into a user-displayable format """
64 return tosys(npath)
65
66 def tosys(npath):
67 """ Convert a normalized path into a system-style path """
68 if WINDOWS_MANGLE:
69 components = npath.split('/')
70 assert(components[0] == '')
71 assert(components[1] == 'cygdrive')
72 assert(len(components[2]) == 1)
73 drive = components[2]
74 components = components[3:]
75 return '%s:\\%s' % (drive.upper(), '\\'.join(components))
76 else:
77 return npath
78
79 def join(*args):
80 return posixpath.join(*args)
81
82 def exists(npath):
83 return os.path.exists(tosys(npath))
84
85 def split(npath):
86 return posixpath.split(npath)
87
88 def splitext(npath):
89 return posixpath.splitext(npath)
90
91
92 def basename(npath):
93 return posixpath.basename(npath)
94
95 def dirname(npath):
96 return posixpath.dirname(npath)
97
98 def abspath(npath):
99 if WINDOWS_MANGLE:
100 # We always use absolute paths for (non-cygwin) windows
101 return npath
102 else:
103 return posixpath.abspath(npath)
104
105 def isdir(npath):
106 return os.path.isdir(tosys(npath))
107
108 def isfile(npath):
109 return os.path.isfile(tosys(npath))
110
111 def getsize(npath):
112 return os.path.getsize(tosys(npath))
OLDNEW
« no previous file with comments | « tools/llvm/driver/ldtools.py ('k') | tools/llvm/driver/pnacl-ar.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698