1# Copyright (c) 2012 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5'''Item formatters for RC headers. 6''' 7 8from __future__ import print_function 9 10 11def Format(root, lang='en', output_dir='.'): 12 yield '''\ 13// This file is automatically generated by GRIT. Do not edit. 14 15#pragma once 16''' 17 # Check for emit nodes under the rc_header. If any emit node 18 # is present, we assume it means the GRD file wants to override 19 # the default header, with no includes. 20 default_includes = ['#include <atlres.h>', ''] 21 emit_lines = [] 22 for output_node in root.GetOutputFiles(): 23 if output_node.GetType() == 'rc_header': 24 for child in output_node.children: 25 if child.name == 'emit' and child.attrs['emit_type'] == 'prepend': 26 emit_lines.append(child.GetCdata()) 27 for line in emit_lines or default_includes: 28 yield line + '\n' 29 if root.IsAllowlistSupportEnabled(): 30 yield '#include "ui/base/resource/allowlist.h"\n' 31 for line in FormatDefines(root): 32 yield line 33 34 35def FormatDefines(root): 36 '''Yields #define SYMBOL 1234 lines. 37 38 Args: 39 root: A GritNode. 40 ''' 41 tids = root.GetIdMap() 42 rc_header_format = '#define {0} {1}\n' 43 if root.IsAllowlistSupportEnabled(): 44 rc_header_format = '#define {0} (::ui::AllowlistedResource<{1}>(), {1})\n' 45 for item in root.ActiveDescendants(): 46 with item: 47 for tid in item.GetTextualIds(): 48 yield rc_header_format.format(tid, tids[tid]) 49