Skip to content

Commit ff8902e

Browse files
Merge pull request #88 from riscv/79-spreadsheet-form-of-norm-rules
Added xlsx output option for create_normative_rules.rb script.
2 parents c90c0bf + 5ec6aed commit ff8902e

File tree

8 files changed

+299
-157
lines changed

8 files changed

+299
-157
lines changed

Makefile

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Makefile for tests of tools/scripts in docs-resources repository.
1+
# Makefile for tests for tools/scripts in docs-resources repository.
22
# Must be run in top-level directory of docs-resources repository.
33
#
44
# This work is licensed under the Creative Commons Attribution-ShareAlike 4.0
@@ -29,16 +29,19 @@ CREATE_NORM_RULE_TOOL := create_normative_rules.rb
2929
# Input and output file names
3030
TEST_ADOC_INPUT_FNAME := test.adoc
3131
NORM_TAGS_OUTPUT_FNAME := test-norm-tags.json
32-
NORM_RULE_OUTPUT_FNAME := test-norm-rules.json
32+
NORM_RULE_JSON_OUTPUT_FNAME := test-norm-rules.json
33+
NORM_RULE_XLSX_OUTPUT_FNAME := test-norm-rules.xlsx
3334

3435
# Built output files
3536
BUILT_NORM_TAGS := $(BUILD_DIR)/$(NORM_TAGS_OUTPUT_FNAME)
36-
BUILT_NORM_RULES := $(BUILD_DIR)/$(NORM_RULE_OUTPUT_FNAME)
37+
BUILT_NORM_RULES_JSON := $(BUILD_DIR)/$(NORM_RULE_JSON_OUTPUT_FNAME)
38+
BUILT_NORM_RULES_XLSX := $(BUILD_DIR)/$(NORM_RULE_XLSX_OUTPUT_FNAME)
3739

3840
# Copies of expected output files.
3941
# Use make target "update-expected" to update from build dir contents.
4042
EXPECTED_NORM_TAGS := $(NORM_RULE_EXPECTED_DIR)/$(NORM_TAGS_OUTPUT_FNAME)
41-
EXPECTED_NORM_RULES := $(NORM_RULE_EXPECTED_DIR)/$(NORM_RULE_OUTPUT_FNAME)
43+
EXPECTED_NORM_RULES_JSON := $(NORM_RULE_EXPECTED_DIR)/$(NORM_RULE_JSON_OUTPUT_FNAME)
44+
EXPECTED_NORM_RULES_XLSX := $(NORM_RULE_EXPECTED_DIR)/$(NORM_RULE_XLSX_OUTPUT_FNAME)
4245

4346
# All normative rule definition input YAML files
4447
NORM_RULE_DEF_FILES := $(wildcard $(NORM_RULE_DEF_DIR)/*.yaml)
@@ -114,47 +117,61 @@ all: test
114117
test: build-tests compare-tests
115118

116119
# Build tests
117-
.PHONY: build-tests build-test-tags build-test-norm-rules
118-
build-tests: build-test-tags build-test-norm-rules
120+
.PHONY: build-tests build-test-tags build-test-norm-rules-json build-test-norm-rules-xlsx
121+
build-tests: build-test-tags build-test-norm-rules-json build-test-norm-rules-xlsx
119122
build-test-tags: $(BUILT_NORM_TAGS)
120-
build-test-norm-rules: $(BUILT_NORM_RULES)
123+
build-test-norm-rules-json: $(BUILT_NORM_RULES_JSON)
124+
build-test-norm-rules-xlsx: $(BUILT_NORM_RULES_XLSX)
121125

122126
# Compare tests against expected
123127
.PHONY: compare-tests
124-
compare-tests: compare-test-tags compare-test-norm-rules
128+
compare-tests: compare-test-tags compare-test-norm-rules-json
125129

126130
compare-test-tags: $(EXPECTED_NORM_TAGS) $(BUILT_NORM_TAGS)
127131
@echo "CHECKING BUILT TAGS AGAINST EXPECTED TAGS"
128132
diff $(EXPECTED_NORM_TAGS) $(BUILT_NORM_TAGS) && echo "diff PASSED" || (echo "diff FAILED"; exit 1)
129133

130134
compare-test-norm-rules: $(EXPECTED_NORM_RULES) $(BUILT_NORM_RULES)
131-
@echo "CHECKING BUILT NORM RULES AGAINST EXPECTED NORM RULES"
132-
diff $(EXPECTED_NORM_RULES) $(BUILT_NORM_RULES) && echo "diff PASSED" || (echo "diff FAILED"; exit 1)
135+
136+
compare-test-norm-rules-json: $(EXPECTED_NORM_RULES_JSON) $(BUILT_NORM_RULES_JSON)
137+
@echo "CHECKING JSON BUILT NORM RULES AGAINST EXPECTED NORM RULES"
138+
diff $(EXPECTED_NORM_RULES_JSON) $(BUILT_NORM_RULES_JSON) && echo "diff PASSED" || (echo "diff FAILED"; exit 1)
133139

134140
# Update expected files from built files
135141
.PHONY: update-expected
136-
update-expected: update-test-tags update-test-norm-rules
142+
update-expected: update-test-tags update-test-norm-rules-json update-test-norm-rules-xlsx
137143

138144
update-test-tags: $(BUILT_NORM_TAGS)
139145
cp -f $(BUILT_NORM_TAGS) $(EXPECTED_NORM_TAGS)
140146

141-
update-test-norm-rules: $(BUILT_NORM_RULES)
142-
cp -f $(BUILT_NORM_RULES) $(EXPECTED_NORM_RULES)
147+
update-test-norm-rules-json: $(BUILT_NORM_RULES_JSON)
148+
cp -f $(BUILT_NORM_RULES_JSON) $(EXPECTED_NORM_RULES_JSON)
149+
150+
update-test-norm-rules-xlsx: $(BUILT_NORM_RULES_XLSX)
151+
cp -f $(BUILT_NORM_RULES_XLSX) $(EXPECTED_NORM_RULES_XLSX)
143152

144153
# Build normative tags
145154
$(BUILT_NORM_TAGS): $(NORM_RULE_TESTS_DIR)/$(TEST_ADOC_INPUT_FNAME) $(CONVERTERS_DIR)/$(TAGS_BACKEND)
146155
$(WORKDIR_SETUP)
147156
$(DOCKER_CMD) $(DOCKER_QUOTE) $(ASCIIDOCTOR_TAGS) $(OPTIONS) -a tags-match-prefix='norm:' -a tags-output-suffix='-norm-tags.json' $< $(DOCKER_QUOTE)
148157
$(WORKDIR_TEARDOWN)
149158

150-
# Build normative rules
151-
$(BUILT_NORM_RULES): $(BUILT_NORM_TAGS) $(NORM_RULE_DEF_FILES)
159+
# Build normative rules with JSON output format
160+
$(BUILT_NORM_RULES_JSON): $(BUILT_NORM_TAGS) $(NORM_RULE_DEF_FILES)
152161
$(WORKDIR_SETUP)
153162
cp -f $(BUILT_NORM_TAGS) $@.workdir
154163
mkdir -p $@.workdir/build
155164
$(DOCKER_CMD) $(DOCKER_QUOTE) ruby $(TOOLS_DIR)/$(CREATE_NORM_RULE_TOOL) $(NORM_TAG_FILE_ARGS) $(NORM_RULE_DEF_ARGS) $@ $(DOCKER_QUOTE)
156165
$(WORKDIR_TEARDOWN)
157166

167+
# Build normative rules with XLSX output format
168+
$(BUILT_NORM_RULES_XLSX): $(BUILT_NORM_TAGS) $(NORM_RULE_DEF_FILES)
169+
$(WORKDIR_SETUP)
170+
cp -f $(BUILT_NORM_TAGS) $@.workdir
171+
mkdir -p $@.workdir/build
172+
$(DOCKER_CMD) $(DOCKER_QUOTE) ruby $(TOOLS_DIR)/$(CREATE_NORM_RULE_TOOL) -x $(NORM_TAG_FILE_ARGS) $(NORM_RULE_DEF_ARGS) $@ $(DOCKER_QUOTE)
173+
$(WORKDIR_TEARDOWN)
174+
158175
# Update docker image to latest
159176
docker-pull-latest:
160177
${DOCKER_BIN} pull ${DOCKER_IMG}

schemas/common-schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"isaObjectKind": {
2929
"type": "string",
30-
"enum": ["extension", "instruction", "csr", "csr_field"]
30+
"enum": ["extension", "instruction", "csr", "csr_field", "parameter"]
3131
},
3232
"ruleName": {
3333
"type": "string",

schemas/defs-schema.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
"type": "object",
55

66
"properties": {
7+
"$schema": {
8+
"type": "string"
9+
},
10+
"chapter_name": {
11+
"type": "string",
12+
"description": "Name of chapter in standards doc associated with these normative rules definitions"
13+
},
714
"normative_rule_definitions": {
815
"type": "array",
916
"items": {
@@ -58,5 +65,6 @@
5865
}
5966
}
6067
},
61-
"required": ["normative_rule_definitions"]
68+
"required": ["$schema", "chapter_name", "normative_rule_definitions"],
69+
"additionalProperties": false
6270
}

schemas/norm-rules-schema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"type": "string",
1818
"description": "Normative rule definition file that defines this rule"
1919
},
20+
"chapter_name": {
21+
"type": "string",
22+
"description": "Normative rules for specified chapter in standards document"
23+
},
2024
"summary": {
2125
"type": "string",
2226
"$ref": "common-schema.json#/summaryDesc"
@@ -39,7 +43,7 @@
3943
},
4044
"tags": {
4145
"type": "array",
42-
"description": "List of normative rule tags that reference the standard",
46+
"description": "List of normative rule tags",
4347
"items": {
4448
"type": "object",
4549
"properties": {

tests/norm-rule/expected/test-norm-rules.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
{
44
"name": "inline",
55
"def_filename": "tests/norm-rule/test.yaml",
6+
"chapter_name": "my-chapter_name",
7+
"kind": "extension",
8+
"instances": [
9+
"Zicsr",
10+
"ABC"
11+
],
612
"summary": "A few words",
713
"tags": [
814
{
@@ -15,6 +21,8 @@
1521
{
1622
"name": "paragraph",
1723
"def_filename": "tests/norm-rule/test.yaml",
24+
"chapter_name": "my-chapter_name",
25+
"description": "Here's a description.\nIt's got 2 lines.\n",
1826
"tags": [
1927
{
2028
"name": "norm:para",
@@ -26,7 +34,12 @@
2634
{
2735
"name": "note_with_2_tags",
2836
"def_filename": "tests/norm-rule/test.yaml",
29-
"description": "Here's a description.\nIt's got 2 lines.\n",
37+
"chapter_name": "my-chapter_name",
38+
"kind": "parameter",
39+
"instances": [
40+
"MY_PARAMETER"
41+
],
42+
"description": "Here's a one line description.",
3043
"tags": [
3144
{
3245
"name": "norm:note-1",
@@ -43,6 +56,7 @@
4356
{
4457
"name": "desc1",
4558
"def_filename": "tests/norm-rule/test.yaml",
59+
"chapter_name": "my-chapter_name",
4660
"tags": [
4761
{
4862
"name": "norm:description-item-1",
@@ -59,6 +73,7 @@
5973
{
6074
"name": "desc2",
6175
"def_filename": "tests/norm-rule/test.yaml",
76+
"chapter_name": "my-chapter_name",
6277
"tags": [
6378
{
6479
"name": "norm:description-item-1",
6.52 KB
Binary file not shown.

tests/norm-rule/test.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@
44
$schema: "../../schemas/defs-schema.json#"
55

66
# Used to create normative rules for test.adoc file.
7+
chapter_name: my-chapter_name
78

89
normative_rule_definitions:
910
- name: inline
1011
summary: A few words
12+
kind: extension
13+
instances: [Zicsr, ABC]
1114
tags: ["norm:inline"]
1215
- name: paragraph
13-
tags: ["norm:para"]
14-
- name: note_with_2_tags
1516
description: |
1617
Here's a description.
1718
It's got 2 lines.
19+
tags: ["norm:para"]
20+
- name: note_with_2_tags
21+
description: Here's a one line description.
22+
kind: parameter
23+
instances: [MY_PARAMETER]
1824
tags: ["norm:note-1", "norm:note-3"]
1925
- names: [desc1, desc2]
2026
tags: ["norm:description-item-1", "norm:description-item-3"]

0 commit comments

Comments
 (0)