2 from subprocess import check_output, check_call
8 def which(command, paths=None):
9 """which(command, [paths]) - Look up the given command in the paths string
10 (or the PATH environment variable, if unspecified)."""
13 paths = os.environ.get('PATH', '')
15 # Check for absolute match first.
16 if os.path.exists(command):
19 # Would be nice if Python had a lib function for this.
23 # Get suffixes to search.
24 # On Cygwin, 'PATHEXT' may exist but it should not be used.
26 pathext = os.environ.get('PATHEXT', '').split(';')
31 for path in paths.split(os.pathsep):
33 p = os.path.join(path, command + ext)
40 def hasNoExtension(FileName):
41 (Root, Ext) = os.path.splitext(FileName)
45 def isValidSingleInputFile(FileName):
46 (Root, Ext) = os.path.splitext(FileName)
47 return Ext in (".i", ".ii", ".c", ".cpp", ".m", "")
50 def getSDKPath(SDKName):
52 Get the path to the SDK for the given SDK name. Returns None if
53 the path cannot be determined.
55 if which("xcrun") is None:
58 Cmd = "xcrun --sdk " + SDKName + " --show-sdk-path"
59 return check_output(Cmd, shell=True).rstrip()
62 def runScript(ScriptPath, PBuildLogFile, Cwd, Stdout=sys.stdout,
65 Run the provided script if it exists.
67 if os.path.exists(ScriptPath):
70 Stdout.write(" Executing: %s\n" % (ScriptPath,))
71 check_call("chmod +x '%s'" % ScriptPath, cwd=Cwd,
75 check_call("'%s'" % ScriptPath, cwd=Cwd,
80 Stderr.write("Error: Running %s failed. See %s for details.\n" % (
81 ScriptPath, PBuildLogFile.name))
85 def isCommentCSVLine(Entries):
87 Treat CSV lines starting with a '#' as a comment.
89 return len(Entries) > 0 and Entries[0].startswith("#")