Skip to content

Commit 7484128

Browse files
committed
buildsystem: fix race case
1 parent 84f24e1 commit 7484128

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

Makefile

+7-4
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,22 @@ validate: $(ALL_BOARDS_VALIDATION) \
5757
$(ALL_DISTROS_VALIDATION)
5858

5959
ALL_BOARDS_JSON := $(patsubst %.yml,%.json,$(addprefix $(OUTPUT_DIR)/,$(BOARDS)))
60+
# Always rebuild board level json, to satisfy imagesuite.parse
61+
.PHONY: $(ALL_BOARDS_JSON)
6062
$(ALL_BOARDS_JSON): $(OUTPUT_DIR)/%.json: %.yml
6163
$(dir_guard)
6264
./scripts/gen_board_json.py -i $^ -o $@
6365
.PHONY: per_board_info
6466
per_board_info: $(ALL_BOARDS_JSON)
6567
ALL_IMAGESUITE_PARSE := $(addsuffix .imagesuite.parse,$(IMAGESUITES))
6668
.PHONY: $(ALL_IMAGESUITE_PARSE)
67-
$(ALL_IMAGESUITE_PARSE): %.imagesuite.parse: % per_board_info
68-
./scripts/parse_imagesuite.py -i $< -j $(OUTPUT_DIR)
69+
$(ALL_IMAGESUITE_PARSE): %.imagesuite.parse : % per_board_info
70+
./scripts/parse_imagesuite.py -i $* -j $(OUTPUT_DIR)
6971
.PHONY: per_imagesuite_info
7072
per_imagesuite_info: $(ALL_IMAGESUITE_PARSE)
73+
rm -f $(addsuffix .lock,$(ALL_BOARDS_JSON))
7174
.PHONY: per_board_json
72-
per_board_json: validate per_board_info per_imagesuite_info
75+
per_board_json: per_board_info per_imagesuite_info
7376
.PHONY: per_board_json_clean
7477
per_board_json_clean:
7578
rm -f $(ALL_BOARDS_JSON)
@@ -106,4 +109,4 @@ docs_cleanup:
106109
clean: json_cleanup resource_cleanup docs_cleanup
107110

108111
.PHONY: all
109-
all: json resources docs
112+
all: json resources docs

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ source venv/bin/activate
7676
pip3 install -r requirements.txt
7777
```
7878

79+
校验 YAML:
80+
81+
```shell
82+
make -j$(nproc) validate
83+
```
84+
7985
生成 JSON:
8086

8187
```shell

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
wheel
22
PyYAML>=6
33
Cerberus>=1.3.7
4+
filelock>=3.17

scripts/parse_imagesuite.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
import argparse
33
import os.path
4+
from filelock import FileLock
45
import yml_reftag
56
import json
67

@@ -44,14 +45,16 @@ def main(args: argparse.Namespace):
4445
}
4546
distro_release['imagesuites'].append(img_json)
4647
for board_ref in img_yml[img_name]['compatible']:
47-
with open(os.path.splitext(os.path.join(args.json_tree, board_ref.category, board_ref.resc))[0] + '.json', 'r') as fp:
48-
board_json = json.load(fp)
49-
if distro_name in board_json['os']:
50-
board_json['os'][distro_name].append(distro_release)
51-
else:
52-
board_json['os'][distro_name] = [distro_release]
53-
with open(os.path.splitext(os.path.join(args.json_tree, board_ref.category, board_ref.resc))[0] + '.json', 'w') as fp:
54-
json.dump(board_json, fp, indent=2)
48+
board_json_file = os.path.splitext(os.path.join(args.json_tree, board_ref.category, board_ref.resc))[0] + '.json'
49+
with FileLock(board_json_file + ".lock", timeout=-1):
50+
with open(board_json_file, 'r') as fp:
51+
board_json = json.load(fp)
52+
if distro_name in board_json['os']:
53+
board_json['os'][distro_name].append(distro_release)
54+
else:
55+
board_json['os'][distro_name] = [distro_release]
56+
with open(board_json_file, 'w') as fp:
57+
json.dump(board_json, fp, indent=2)
5558

5659
if __name__ == "__main__":
5760
arg_parser = argparse.ArgumentParser()
@@ -67,4 +70,4 @@ def main(args: argparse.Namespace):
6770
help="Search path for YAMLs being referenced",
6871
required=False, type=str, default=''
6972
)
70-
main(arg_parser.parse_args())
73+
main(arg_parser.parse_args())

0 commit comments

Comments
 (0)