def _VerifyImportDeps(args, __): fileutil.EnsureDirectoryExists(args.gen_dir) for filename in args.filename: rel_path = RelativePath(filename, args.depth) tree = _UnpickleAST(_GetPicklePath(rel_path, args.gen_dir)) mojom_imports = set(parsed_imp.import_filename for parsed_imp in tree.import_list) # read the paths from the file f_deps = open(args.deps_file, 'r') deps_sources = set() for deps_path in f_deps: deps_path = deps_path.rstrip('\n') f_sources = open(deps_path, 'r') for source_file in f_sources: source_dir = deps_path.split(args.gen_dir + "/", 1)[1] full_source_path = os.path.dirname(source_dir) + "/" + \ source_file deps_sources.add(full_source_path.rstrip('\n')) if (not deps_sources.issuperset(mojom_imports)): print ">>> [%s] Missing dependencies for the following imports: %s" % ( \ args.filename[0], \ list(mojom_imports.difference(deps_sources))) sys.exit(1) source_filename, _ = os.path.splitext(rel_path.relative_path()) output_file = source_filename + '.v' output_file_path = os.path.join(args.gen_dir, output_file) WriteFile("", output_file_path) return 0
def main(): parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument( '--dependency', type=str, action='append', default=[], help=('A path to another JSON typemap to merge into the output. ' 'This may be repeated to merge multiple typemaps.')) parser.add_argument( '--cpp-typemap-config', type=str, action='append', default=[], dest='cpp_config_paths', help=('A path to a single JSON-formatted typemap config as emitted by' 'GN when processing a mojom_cpp_typemap build rule.')) parser.add_argument('--output', type=str, required=True, help='The path to which to write the generated JSON.') params, typemap_params = parser.parse_known_args() typemaps = ParseTypemapArgs(typemap_params) typemaps.update(LoadCppTypemapConfigs(params.cpp_config_paths)) missing = [path for path in params.dependency if not os.path.exists(path)] if missing: raise IOError('Missing dependencies: %s' % ', '.join(missing)) for path in params.dependency: typemaps.update(ReadTypemap(path)) WriteFile(json.dumps({'c++': typemaps}, indent=2), params.output)
def _PickleAST(ast, output_file): full_dir = os.path.dirname(output_file) fileutil.EnsureDirectoryExists(full_dir) try: WriteFile(cPickle.dumps(ast), output_file) except (IOError, cPickle.PicklingError) as e: print "%s: Error: %s" % (output_file, str(e)) sys.exit(1)
def main(): parser = OptionParser() parser.add_option('-d', '--directory', help='Read files from DIRECTORY') parser.add_option('-o', '--output', help='Write list to FILE') parser.add_option('-p', '--pattern', help='Only reads files that name matches PATTERN', default=".") (options, _) = parser.parse_args() pattern = re.compile(options.pattern) files = [f for f in os.listdir(options.directory) if pattern.match(f)] contents = '\n'.join(f for f in files) + '\n' WriteFile(contents, options.output)
def main(): parser = OptionParser() parser.add_option('-d', '--directory', help='Read files from DIRECTORY') parser.add_option('-o', '--output', help='Write list to FILE') parser.add_option('-p', '--pattern', help='Only reads files that name matches PATTERN', default=".") (options, _) = parser.parse_args() pattern = re.compile(options.pattern) files = [f for f in os.listdir(options.directory) if pattern.match(f)] stream = StringIO() for f in files: print >> stream, f WriteFile(stream.getvalue(), options.output) stream.close()
def _VerifyImportDeps(args, __): fileutil.EnsureDirectoryExists(args.gen_dir) if args.filelist: with open(args.filelist) as f: args.filename.extend(f.read().split()) for filename in args.filename: rel_path = RelativePath(filename, args.depth) tree = _UnpickleAST(_GetPicklePath(rel_path, args.gen_dir)) mojom_imports = set(parsed_imp.import_filename for parsed_imp in tree.import_list) sources = set() target_prefix = args.deps_file.split(".deps_sources_list")[0] sources = GetSourcesList(target_prefix, sources, args.gen_dir) if (not sources.issuperset(mojom_imports)): target_name = target_prefix.rsplit("/", 1)[1] target_prefix_without_gen_dir = target_prefix.split( args.gen_dir + "/", 1)[1] full_target_name = "//" + target_prefix_without_gen_dir.rsplit( "/", 1)[0] + ":" + target_name print(">>> File \"%s\"" % filename) print(">>> from target \"%s\"" % full_target_name) print( ">>> is missing dependencies for the following imports:\n%s" % list(mojom_imports.difference(sources))) sys.exit(1) source_filename, _ = os.path.splitext(rel_path.relative_path()) output_file = source_filename + '.v' output_file_path = os.path.join(args.gen_dir, output_file) WriteFile(b"", output_file_path) return 0
def main(): parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument( '--dependency', type=str, action='append', default=[], help=('A path to another JSON typemap to merge into the output. ' 'This may be repeated to merge multiple typemaps.')) parser.add_argument('--output', type=str, required=True, help='The path to which to write the generated JSON.') params, typemap_params = parser.parse_known_args() typemaps = ParseTypemapArgs(typemap_params) missing = [path for path in params.dependency if not os.path.exists(path)] if missing: raise IOError('Missing dependencies: %s' % ', '.join(missing)) for path in params.dependency: typemaps.update(ReadTypemap(path)) WriteFile(json.dumps({'c++': typemaps}, indent=2).encode(), params.output)
def Write(self, contents, filename): if self.output_dir is None: print(contents) return full_path = os.path.join(self.output_dir, filename) WriteFile(contents, full_path)
def Write(self, contents, output_dir, filename): full_path = os.path.join(output_dir, filename) WriteFile(contents, full_path)