def handleCommandLine(self, args, defaultToStdin=False): """ Parse a commandline into this parser. Uses OptionParser internally, no args mean sys.argv[1:]. """ def get_output_file(path): dir = os.path.dirname(path) if dir: try: os.makedirs(dir) except OSError as error: if error.errno != errno.EEXIST: raise return open(path, 'wb') p = self.getCommandLineParser() options, args = p.parse_args(args=args) out = self.out depfile = None includes = options.I if options.output: out = get_output_file(options.output) if defaultToStdin and len(args) == 0: args = [sys.stdin] if options.depend: raise Preprocessor.Error(self, "--depend doesn't work with stdin", None) if options.depend: if not options.output: raise Preprocessor.Error(self, "--depend doesn't work with stdout", None) try: from makeutil import Makefile except: raise Preprocessor.Error( self, "--depend requires the " "mozbuild.makeutil module", None) depfile = get_output_file(options.depend) includes.extend(args) if includes: for f in includes: with open(f, 'rU') as input: self.processFile(input=input, output=out) if depfile: mk = Makefile() mk.create_rule([options.output ]).add_dependencies(self.includes) mk.dump(depfile) depfile.close() if options.output: out.close()
def handleCommandLine(self, args, defaultToStdin = False): """ Parse a commandline into this parser. Uses OptionParser internally, no args mean sys.argv[1:]. """ def get_output_file(path): dir = os.path.dirname(path) if dir: try: os.makedirs(dir) except OSError as error: if error.errno != errno.EEXIST: raise return open(path, 'wb') p = self.getCommandLineParser() options, args = p.parse_args(args=args) out = self.out depfile = None includes = options.I if options.output: out = get_output_file(options.output) if defaultToStdin and len(args) == 0: args = [sys.stdin] if options.depend: raise Preprocessor.Error(self, "--depend doesn't work with stdin", None) if options.depend: if not options.output: raise Preprocessor.Error(self, "--depend doesn't work with stdout", None) try: from makeutil import Makefile except: raise Preprocessor.Error(self, "--depend requires the " "mozbuild.makeutil module", None) depfile = get_output_file(options.depend) includes.extend(args) if includes: for f in includes: with open(f, 'rU') as input: self.processFile(input=input, output=out) if depfile: mk = Makefile() mk.create_rule([options.output]).add_dependencies(self.includes) mk.dump(depfile) depfile.close() if options.output: out.close()
def processFile(self, input, output, depfile=None): """ Preprocesses the contents of the ``input`` stream and writes the result to the ``output`` stream. If ``depfile`` is set, the dependencies of ``output`` file are written to ``depfile`` in Makefile format. """ self.out = output self.do_include(input, False) self.failUnused(input.name) if depfile: mk = Makefile() mk.create_rule([output.name]).add_dependencies(self.includes) mk.dump(depfile)
def preprocess(self, parsed_args, cwd=None): showIncludes = ['-showIncludes'] if parsed_args['depfile'] else [] # Preprocess over a pipe. proc = subprocess.Popen([self.executable, '-E', parsed_args['input'], '-nologo'] + showIncludes + parsed_args['common_args'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) preprocessed, stderr = proc.communicate() ret = proc.wait() # Parse the output to extract dependency info. if showIncludes: from win32util import normcase from makeutil import Makefile mk = Makefile() rule = mk.create_rule([parsed_args['output']['obj']]) rule.add_dependencies([normcase(parsed_args['input'])]) filtered_stderr = '' for line in stderr.splitlines(True): if line.startswith(self._includes_prefix): dep = normcase(line[len(self._includes_prefix):].strip()) if ' ' not in dep: rule.add_dependencies([dep]) else: filtered_stderr += line depfile = parsed_args['depfile'] if cwd: depfile = os.path.join(cwd, depfile) with open(depfile, 'w') as f: mk.dump(f) stderr = filtered_stderr return ret, preprocessed, stderr
def preprocess(self, parsed_args, cwd=None): showIncludes = ['-showIncludes'] if parsed_args['depfile'] else [] # Preprocess over a pipe. proc = subprocess.Popen( [self.executable, '-E', parsed_args['input'], '-nologo'] + showIncludes + parsed_args['common_args'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) preprocessed, stderr = proc.communicate() ret = proc.wait() # Parse the output to extract dependency info. if showIncludes: from win32util import normcase from makeutil import Makefile mk = Makefile() rule = mk.create_rule([parsed_args['output']['obj']]) rule.add_dependencies([normcase(parsed_args['input'])]) filtered_stderr = '' for line in stderr.splitlines(True): if line.startswith(self._includes_prefix): dep = normcase(line[len(self._includes_prefix):].strip()) if ' ' not in dep: rule.add_dependencies([dep]) else: filtered_stderr += line depfile = parsed_args['depfile'] if cwd: depfile = os.path.join(cwd, depfile) with open(depfile, 'w') as f: mk.dump(f) stderr = filtered_stderr return ret, preprocessed, stderr