1# Copyright 2022 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""A trivial tool to turn a string into a C++ constant. 15 16This is not meant to be useful. It is only to provide an example of a tool that 17generates code. 18""" 19 20import sys 21 22 23def main(argv): 24 if len(argv) != 4: 25 raise Exception('usage: constant_generator out_file var_name text') 26 with open(argv[1], 'w') as out: 27 out.write('const char* %s = "%s";\n' % (argv[2], argv[3])) 28 29 30if __name__ == '__main__': 31 main(sys.argv) 32