brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 66871fb Raw
30 lines · python
1#!/usr/bin/env python32 3# ===- bundle_resources.py - Generate string constants with file contents. ===4#5# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.6# See https://llvm.org/LICENSE.txt for license information.7# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception8#9# ===----------------------------------------------------------------------===10 11# Usage: bundle-resources.py foo.inc a.js path/b.css ...12# Produces foo.inc containing:13#   const char a_js[] = "...";14#   const char b_css[] = "...";15import os16import sys17 18outfile = sys.argv[1]19infiles = sys.argv[2:]20 21with open(outfile, "w") as out:22    for filename in infiles:23        varname = os.path.basename(filename).replace(".", "_")24        out.write("const char " + varname + "[] = \n")25        # MSVC limits each chunk of string to 2k, so split by lines.26        # The overall limit is 64k, which ought to be enough for anyone.27        for line in open(filename).read().split("\n"):28            out.write('  R"x(' + line + ')x" "\\n"\n')29        out.write("  ;\n")30