summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorEd tanous <ed@tanous.net>2018-03-23 00:19:20 -0700
committerEd Tanous <ed.tanous@intel.com>2018-04-24 21:19:02 +0000
commit7d95f5f6db1df37fe6438aa0e87479275c82807a (patch)
tree7c19c3ccf8e002d7abd471e7da7b0338d837d1ba /scripts
parentf4c4dcf438a43f04fe91f1350f88eda618cdb3e4 (diff)
downloadbmcweb-7d95f5f6db1df37fe6438aa0e87479275c82807a.tar.gz
bmcweb-7d95f5f6db1df37fe6438aa0e87479275c82807a.zip
Remove hunter and submodules
And use external project instead. This should make it easier to keep our systems up to date with yocto. Change-Id: Id2c9f3e474eebf2194eaf58b0c572f7a1421def6
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build_web_assets.py205
-rw-r--r--scripts/run_clang_tidy.py.bak217
2 files changed, 0 insertions, 422 deletions
diff --git a/scripts/build_web_assets.py b/scripts/build_web_assets.py
deleted file mode 100755
index f9b3f74..0000000
--- a/scripts/build_web_assets.py
+++ /dev/null
@@ -1,205 +0,0 @@
-#! /usr/bin/python3
-
-import argparse
-import os
-import gzip
-import hashlib
-from subprocess import Popen, PIPE
-from collections import defaultdict
-import re
-
-THIS_DIR = os.path.dirname(os.path.realpath(__file__))
-
-ENABLE_CACHING = False
-
-# TODO(ed) THis should really pull type and file information from webpack
-CONTENT_TYPES = {
- 'css': "text/css;charset=UTF-8",
- 'html': "text/html;charset=UTF-8",
- 'js': "text/html;charset=UTF-8",
- 'png': "image/png;charset=UTF-8",
- 'woff': "application/x-font-woff",
- 'woff2': "application/x-font-woff2",
- 'ttf': "application/x-font-ttf",
- "svg": "image/svg+xml",
- "eot": "application/vnd.ms-fontobject",
- # dev tools don't care, causes browser to show as text
- # https://stackoverflow.com/questions/19911929/what-mime-type-should-i-use-for-javascript-source-map-files
- "map": "application/json"
-}
-
-CPP_MIDDLE_BUFFER = """ CROW_ROUTE(app, "{pretty_name}")
- ([](const crow::request& req, crow::response& res) {{
- {CACHE_FOREVER_HEADER}
- std::string sha1("{sha1}");
- res.add_header(etag_string, sha1);
-
- if (req.get_header_value(if_none_match_string) == sha1) {{
- res.code = 304;
- }} else {{
- res.code = 200;
- // TODO, if you have a browser from the dark ages that doesn't support gzip,
- // unzip it before sending based on Accept-Encoding header
- res.add_header(content_encoding_string, {content_encoding});
- res.add_header(content_type_string, "{content_type}");
-
- res.write(staticassets::{relative_path_escaped});
- }}
- res.end();
- }});
-
-"""
-
-HPP_START_BUFFER = ("#pragma once\n"
- "\n"
- "#include <string>\n"
- "\n"
- "#include <crow/app.h>\n"
- "#include <crow/http_request.h>\n"
- "#include <crow/http_response.h>\n"
- "\n"
- "#include <crow/routing.h>\n"
- "\n"
- "namespace crow {\n"
- "namespace webassets {\n"
- "static const char* gzip_string = \"gzip\";\n"
- "static const char* none_string = \"none\";\n"
- "static const char* if_none_match_string = \"If-None-Match\";\n"
- "static const char* content_encoding_string = \"Content-Encoding\";\n"
- "static const char* content_type_string = \"Content-Type\";\n"
- "static const char* etag_string = \"ETag\";\n"
- )
-
-
-def twos_comp(val, bits):
- """compute the 2's compliment of int value val"""
- if (val & (1 << (bits - 1))) != 0: # if sign bit is set e.g., 8bit: 128-255
- val = val - (1 << bits) # compute negative value
- return val # return positive value as is
-
-
-def main():
- """ Main Function """
-
- parser = argparse.ArgumentParser()
- parser.add_argument('-i', '--input', type=str)
- parser.add_argument('-o', '--output', type=str)
- parser.add_argument('-d', '--debug', action='store_true')
- args = parser.parse_args()
-
- dist_dir = args.input
-
- with open(args.output.replace("cpp", "hpp"), 'w') as hpp_output:
- hpp_output.write(HPP_START_BUFFER)
- hpp_output.write("struct staticassets {\n")
-
- asset_filenames = []
-
- for root, dirnames, filenames in os.walk(dist_dir):
- for filename in filenames:
- root_file = os.path.join(root, filename)
- pretty_name = "/" + os.path.relpath(root_file, dist_dir)
- cpp_name = "file" + pretty_name
- for character in ['/', '.', '-']:
- cpp_name = cpp_name.replace(character, "_")
-
- if pretty_name.endswith(".gz"):
- pretty_name = pretty_name[:-3]
- gzip = True
- else:
- gzip = False
-
- if pretty_name.endswith("/index.html"):
- pretty_name = pretty_name[:-10]
-
- asset_filenames.append(
- (root_file, pretty_name, cpp_name, gzip))
-
- for root_file, pretty_name, cpp_name, gzip in asset_filenames:
-
- with open(root_file, 'rb') as file_handle:
- file_content = file_handle.read()
-
- hpp_output.write(
- " static const std::array<char, {}> {};\n".format(len(file_content), cpp_name))
- hpp_output.write(
- " static const std::array<const char*, {}> routes;\n".format(len(asset_filenames)))
- hpp_output.write("};\n\n")
- hpp_output.write("template <typename... Middlewares>\n")
- hpp_output.write(
- "void request_routes(Crow<Middlewares...>& app) {\n")
-
- for root_file, pretty_name, cpp_name, gzip in asset_filenames:
- os.path.basename(root_file)
- with open(root_file, 'rb') as file_handle:
- file_content = file_handle.read()
- sha = hashlib.sha1()
- sha.update(file_content)
- sha1 = sha.hexdigest()
-
- ext = os.path.split(root_file)[-1].split(".")[-1]
- if ext == "gz":
- ext = os.path.split(root_file)[-1].split(".")[-2]
-
- content_type = CONTENT_TYPES.get(ext, "")
- if content_type == "":
- print("unknown content type for {}".format(pretty_name))
-
- content_encoding = 'gzip_string' if gzip else 'none_string'
-
- environment = {
- 'relative_path': pretty_name,
- 'relative_path_escaped': cpp_name,
- 'pretty_name': pretty_name,
- 'sha1': sha1,
- 'sha1_short': sha1[:20],
- 'content_type': content_type,
- 'content_encoding': content_encoding,
- "CACHE_FOREVER_HEADER": ""
- }
-
- if ENABLE_CACHING:
- # if we have a valid sha1, and we have a unique path to the resource
- # it can be safely cached forever
- if sha1 != "" and relative_path != relative_path_sha1:
- environment["CACHE_FOREVER_HEADER"] = "res.add_header(\"Cache-Control\", \"public, max-age=31556926\");\n"
-
- content = CPP_MIDDLE_BUFFER.format(**environment)
- hpp_output.write(content)
-
- hpp_output.write(
- "} // namespace staticassets\n} // namespace webassets\n} // namespace crow")
-
- with open(args.output, 'w') as cpp_output:
- cpp_output.write("#include <webassets.hpp>\n"
- "namespace crow{\n"
- "namespace webassets{\n")
-
- for root_file, pretty_name, cpp_name, gzip in asset_filenames:
- with open(root_file, 'rb') as file_handle:
- file_content = file_handle.read()
- # compute the 2s complement for negative numbers.
- # If you don't, you get narrowing warnings from gcc/clang
- array_binary_text = ', '.join(str(twos_comp(x, 8))
- for x in file_content)
- cpp_end_buffer = " const std::array<char, {byte_length}> staticassets::{relative_path_escaped} = {{{file_bytes}}};\n"
- cpp_output.write(
- cpp_end_buffer.format(
- relative_path_escaped=cpp_name,
- byte_length=len(file_content),
- relative_path=pretty_name,
- file_bytes=array_binary_text
- )
- )
- print("{:<40} took {:>6} KB".format(
- pretty_name, int(len(array_binary_text) / 1024)))
- static_routes = ",\n".join(
- [' "' + x[1] + '"' for x in asset_filenames])
- cpp_output.write(
- "\n const std::array<const char*, {}> staticassets::routes{{\n{}}};\n".format(len(asset_filenames), static_routes))
- cpp_output.write(
- "} // namespace webassets\n} // namespace crow\n")
-
-
-if __name__ == "__main__":
- main()
diff --git a/scripts/run_clang_tidy.py.bak b/scripts/run_clang_tidy.py.bak
deleted file mode 100644
index b45d714..0000000
--- a/scripts/run_clang_tidy.py.bak
+++ /dev/null
@@ -1,217 +0,0 @@
-#!/usr/bin/env python
-#
-#===- run-clang-tidy.py - Parallel clang-tidy runner ---------*- python -*--===#
-#
-# The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-#===------------------------------------------------------------------------===#
-# FIXME: Integrate with clang-tidy-diff.py
-
-"""
-Parallel clang-tidy runner
-==========================
-
-Runs clang-tidy over all files in a compilation database. Requires clang-tidy
-and clang-apply-replacements in $PATH.
-
-Example invocations.
-- Run clang-tidy on all files in the current working directory with a default
- set of checks and show warnings in the cpp files and all project headers.
- run-clang-tidy.py $PWD
-
-- Fix all header guards.
- run-clang-tidy.py -fix -checks=-*,llvm-header-guard
-
-- Fix all header guards included from clang-tidy and header guards
- for clang-tidy headers.
- run-clang-tidy.py -fix -checks=-*,llvm-header-guard extra/clang-tidy \
- -header-filter=extra/clang-tidy
-
-Compilation database setup:
-http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
-"""
-
-import argparse
-import json
-import multiprocessing
-import os
-import Queue
-import re
-import shutil
-import subprocess
-import sys
-import tempfile
-import threading
-
-
-def find_compilation_database(path):
- """Adjusts the directory until a compilation database is found."""
- result = './'
- while not os.path.isfile(os.path.join(result, path)):
- if os.path.realpath(result) == '/':
- print 'Error: could not find compilation database.'
- sys.exit(1)
- result += '../'
- return os.path.realpath(result)
-
-
-def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
- header_filter, extra_arg, extra_arg_before, quiet):
- """Gets a command line for clang-tidy."""
- start = [clang_tidy_binary]
- if header_filter is not None:
- start.append('-header-filter=' + header_filter)
- else:
- # Show warnings in all in-project headers by default.
- start.append('-header-filter=^' + build_path + '/.*')
- if checks:
- start.append('-checks=' + checks)
- if tmpdir is not None:
- start.append('-export-fixes')
- # Get a temporary file. We immediately close the handle so clang-tidy can
- # overwrite it.
- (handle, name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir)
- os.close(handle)
- start.append(name)
- for arg in extra_arg:
- start.append('-extra-arg=%s' % arg)
- for arg in extra_arg_before:
- start.append('-extra-arg-before=%s' % arg)
- start.append('-p=' + build_path)
- if quiet:
- start.append('-quiet')
- start.append(f)
- return start
-
-
-def apply_fixes(args, tmpdir):
- """Calls clang-apply-fixes on a given directory. Deletes the dir when done."""
- invocation = [args.clang_apply_replacements_binary]
- if args.format:
- invocation.append('-format')
- invocation.append(tmpdir)
- subprocess.call(invocation)
- shutil.rmtree(tmpdir)
-
-
-def run_tidy(args, tmpdir, build_path, queue):
- """Takes filenames out of queue and runs clang-tidy on them."""
- while True:
- name = queue.get()
- invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
- tmpdir, build_path, args.header_filter,
- args.extra_arg, args.extra_arg_before,
- args.quiet)
- sys.stdout.write(' '.join(invocation) + '\n')
- subprocess.call(invocation)
- queue.task_done()
-
-
-def main():
- parser = argparse.ArgumentParser(description='Runs clang-tidy over all files '
- 'in a compilation database. Requires '
- 'clang-tidy and clang-apply-replacements in '
- '$PATH.')
- parser.add_argument('-clang-tidy-binary', metavar='PATH',
- default='clang-tidy',
- help='path to clang-tidy binary')
- parser.add_argument('-clang-apply-replacements-binary', metavar='PATH',
- default='clang-apply-replacements',
- help='path to clang-apply-replacements binary')
- parser.add_argument('-checks', default=None,
- help='checks filter, when not specified, use clang-tidy '
- 'default')
- parser.add_argument('-header-filter', default=None,
- help='regular expression matching the names of the '
- 'headers to output diagnostics from. Diagnostics from '
- 'the main file of each translation unit are always '
- 'displayed.')
- parser.add_argument('-j', type=int, default=0,
- help='number of tidy instances to be run in parallel.')
- parser.add_argument('files', nargs='*', default=['.*'],
- help='files to be processed (regex on path)')
- parser.add_argument('-fix', action='store_true', help='apply fix-its')
- parser.add_argument('-format', action='store_true', help='Reformat code '
- 'after applying fixes')
- parser.add_argument('-p', dest='build_path',
- help='Path used to read a compile command database.')
- parser.add_argument('-extra-arg', dest='extra_arg',
- action='append', default=[],
- help='Additional argument to append to the compiler '
- 'command line.')
- parser.add_argument('-extra-arg-before', dest='extra_arg_before',
- action='append', default=[],
- help='Additional argument to prepend to the compiler '
- 'command line.')
- parser.add_argument('-quiet', action='store_true',
- help='Run clang-tidy in quiet mode')
- args = parser.parse_args()
-
- db_path = 'compile_commands.json'
-
- if args.build_path is not None:
- build_path = args.build_path
- else:
- # Find our database
- build_path = find_compilation_database(db_path)
-
- try:
- invocation = [args.clang_tidy_binary, '-list-checks']
- invocation.append('-p=' + build_path)
- if args.checks:
- invocation.append('-checks=' + args.checks)
- invocation.append('-')
- print subprocess.check_output(invocation)
- except:
- print >>sys.stderr, "Unable to run clang-tidy."
- sys.exit(1)
-
- # Load the database and extract all files.
- database = json.load(open(os.path.join(build_path, db_path)))
- files = [entry['file'] for entry in database]
-
- max_task = args.j
- if max_task == 0:
- max_task = multiprocessing.cpu_count()
-
- tmpdir = None
- if args.fix:
- tmpdir = tempfile.mkdtemp()
-
- # Build up a big regexy filter from all command line arguments.
- file_name_re = re.compile('|'.join(args.files))
-
- try:
- # Spin up a bunch of tidy-launching threads.
- queue = Queue.Queue(max_task)
- for _ in range(max_task):
- t = threading.Thread(target=run_tidy,
- args=(args, tmpdir, build_path, queue))
- t.daemon = True
- t.start()
-
- # Fill the queue with files.
- for name in files:
- if file_name_re.search(name):
- queue.put(name)
-
- # Wait for all threads to be done.
- queue.join()
-
- except KeyboardInterrupt:
- # This is a sad hack. Unfortunately subprocess goes
- # bonkers with ctrl-c and we start forking merrily.
- print '\nCtrl-C detected, goodbye.'
- if args.fix:
- shutil.rmtree(tmpdir)
- os.kill(0, 9)
-
- if args.fix:
- print 'Applying fixes ...'
- apply_fixes(args, tmpdir)
-
-if __name__ == '__main__':
- main() \ No newline at end of file
OpenPOWER on IntegriCloud