|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +# Tool to regenerate existing framework CSV models. |
| 4 | + |
| 5 | +from pathlib import Path |
| 6 | +import json |
| 7 | +import os |
| 8 | +import requests |
| 9 | +import shutil |
| 10 | +import subprocess |
| 11 | +import tempfile |
| 12 | +import sys |
| 13 | + |
| 14 | + |
| 15 | +defaultModelPath = "java/ql/lib/semmle/code/java/frameworks" |
| 16 | +lgtmSlugToModelFile = { |
| 17 | + # "apache/commons-beanutils": "apache/BeanUtilsGenerated.qll", |
| 18 | + # "apache/commons-codec": "apache/CodecGenerated.qll", |
| 19 | + # "apache/commons-lang": "apache/Lang3Generated.qll", |
| 20 | + "apache/commons-io": "apache/IOGenerated.qll", |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +def findGitRoot(): |
| 25 | + return subprocess.check_output( |
| 26 | + ["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip() |
| 27 | + |
| 28 | + |
| 29 | +def regenerateModel(lgtmSlug, extractedDb): |
| 30 | + tmpDir = tempfile.mkdtemp() |
| 31 | + print("============================================================") |
| 32 | + print("Generating models for " + lgtmSlug) |
| 33 | + print("============================================================") |
| 34 | + # check if lgtmSlug exists as key |
| 35 | + if lgtmSlug not in lgtmSlugToModelFile: |
| 36 | + print("ERROR: slug " + lgtmSlug + |
| 37 | + " is not mapped to a model file in script " + sys.argv[0]) |
| 38 | + sys.exit(1) |
| 39 | + modelFile = defaultModelPath + "/" + lgtmSlugToModelFile[lgtmSlug] |
| 40 | + codeQlRoot = findGitRoot() |
| 41 | + targetModel = codeQlRoot + "/" + modelFile |
| 42 | + subprocess.check_call([codeQlRoot + "/java/ql/src/utils/model-generator/GenerateFlowModel.py", extractedDb, |
| 43 | + targetModel]) |
| 44 | + print("Regenerated " + targetModel) |
| 45 | + shutil.rmtree(tmpDir) |
| 46 | + |
| 47 | + |
| 48 | +if len(sys.argv) == 3: |
| 49 | + lgtmSlug = sys.argv[1] |
| 50 | + db = sys.argv[2] |
| 51 | + regenerateModel(lgtmSlug, db) |
| 52 | +else: |
| 53 | + print('error') |
0 commit comments