blob: d75a87ec73a243b7eac7923ba7077d1f18c84954 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import json
import os
import xml.etree.ElementTree as ET
def sarif_from_env():
# return parsed JSON content a SARIF_PATH file
json_filename = os.environ['SARIF_PATH']
json_filename += '.sarif'
print('json_filename: %r' % json_filename)
with open(json_filename) as f:
json_data = f.read()
return json.loads(json_data)
def get_location_artifact_uri(location):
return location['physicalLocation']['artifactLocation']['uri']
def get_location_physical_region(location):
return location['physicalLocation']['region']
def get_location_snippet_text(location):
return location['physicalLocation']['contextRegion']['snippet']['text']
def get_location_relationships(location):
return location['relationships']
def get_result_by_index(sarif, idx):
runs = sarif['runs']
run = runs[0]
results = run['results']
return results[idx]
def get_state_graph(events, event_idx):
graph = events[event_idx]['properties']['gcc/diagnostics/paths/event/state_graph']
if 0:
print(graph)
assert graph is not None
return graph
def get_state_node_attr(obj, attr_name):
return obj['properties']['gcc/diagnostic_state_node/%s' % attr_name]
def get_state_node_kind(obj):
return get_state_node_attr(obj, 'kind')
def get_state_node_name(obj):
return get_state_node_attr(obj, 'name')
def get_state_node_type(obj):
return get_state_node_attr(obj, 'type')
def get_state_node_value(obj):
return get_state_node_attr(obj, 'value')
|