Skip to content

Commit bf715b1

Browse files
committed
Fix output locations
Ensure models-as-data are output to the correct location.
1 parent 057c684 commit bf715b1

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
## Generating Standard Library models
1+
## Generating C Standard Library models
22

33
This directory contains a script for generating a models-as-data file from a plain text file containing standard library definitions copied from Appendix B of the C Programming Language standard.
44

55
### How to use
66

77
1. Download a PDF of the desired C programming language standard.
88
2. Copy each page individually into a text file (avoiding copying headers and footers).
9-
3. Run `python3 generate_standard_library_models.py <lang-standard> <path-to-text-file> <output-file>`
9+
3. Run `python3 generate_c_standard_library_models.py <lang-standard> <path-to-input-text-file>`
10+
11+
After running the script, an models-as-data file will be written to the cpp/common pack including the standard library definitions.

scripts/generate_standard_library_models/c/generate_c_standard_library_models.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from argparse import ArgumentParser
2+
from pathlib import Path
23
import re
34
import yaml
45

@@ -18,14 +19,10 @@
1819
parser.add_argument(
1920
"input_file", help="the input file containing the list of APIs copied from Appendix B of the C Standard Library document")
2021

21-
parser.add_argument(
22-
"output_file", help="the output file to write the models-as-data file to")
23-
2422
args = parser.parse_args()
2523

2624
input_file = args.input_file
2725
standard = args.standard
28-
output_file = args.output_file
2926

3027
# Extract the header name from a header line
3128
header_regex = re.compile(r".*<(.+)>")
@@ -183,6 +180,11 @@ def map_size_vars(name):
183180
]
184181
}
185182

183+
generate_standard_library_home = Path(__file__).resolve().parent
184+
root = generate_standard_library_home.parent.parent.parent
185+
common_codingstandards_ext_output = root.joinpath('cpp', 'common', 'src', 'ext',f"std{ standard.lower() }.generated.names.model.yml")
186+
186187
# Write the models-as-data file to YAML
187-
with open(output_file, 'w') as file:
188-
yaml.dump(yaml_output, file, default_flow_style=None, width=3000)
188+
with open(common_codingstandards_ext_output, 'w') as file:
189+
yaml.dump(yaml_output, file, default_flow_style=None, width=3000)
190+
print("Wrote models-as-data file to " + str(common_codingstandards_ext_output) + " for " + standard + " C Standard Library.")

scripts/generate_standard_library_models/cpp/generate_cpp_standard_library_models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
from pathlib import Path
33
import yaml
44

5-
generate_modules_home = Path(__file__).resolve().parent
6-
common_codingstandards_ext_output = generate_modules_home.parent.parent.joinpath(
7-
'cpp', 'common', 'src', 'ext','stdcpp14.generated.names.model.yml')
5+
generate_standard_library_home = Path(__file__).resolve().parent
6+
root = generate_standard_library_home.parent.parent.parent
7+
common_codingstandards_ext_output = root.joinpath('cpp', 'common', 'src', 'ext','stdcpp14.generated.names.model.yml')
88

99
queries = ["libraryTypeModel", "libraryFunctionModel", "libraryObjectModel", "libraryMemberVariableModel"]
1010
def load_spec(spec_file):
@@ -21,7 +21,7 @@ def load_spec(spec_file):
2121
"pack" : "codeql/common-cpp-coding-standards",
2222
"extensible" : query
2323
},
24-
"data" : load_spec(generate_modules_home.joinpath(f"{query}.json"))["#select"]["tuples"]
24+
"data" : load_spec(generate_standard_library_home.joinpath(f"{query}.json"))["#select"]["tuples"]
2525

2626
})
2727

0 commit comments

Comments
 (0)