Skip to content

Commit c1c581d

Browse files
committed
[Repo] Add gitignore generator for ya.make
1 parent b44d312 commit c1c581d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

generate_gitignore.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import subprocess
2+
from pathlib import Path
3+
4+
5+
for path in subprocess.check_output(
6+
["grep", "-r", "--include", "ya.make", "PROGRAM"]
7+
).decode().splitlines():
8+
[ya_make_path, contents] = path.split(":")
9+
if not ya_make_path.endswith("ya.make"):
10+
continue
11+
if "contrib" in ya_make_path:
12+
continue
13+
if ya_make_path.startswith("build"):
14+
continue
15+
if ya_make_path.startswith("library"):
16+
continue
17+
if ya_make_path.startswith("vendor"):
18+
continue
19+
if ya_make_path.startswith("tools"):
20+
continue
21+
dir_path = ya_make_path.replace("/ya.make", "")
22+
directory = dir_path.split("/")[-1]
23+
name = ""
24+
# print(f"Processing {dir_path}")
25+
if "PROGRAM" in contents:
26+
if "PROGRAM(" not in contents:
27+
continue
28+
name = contents.split("PROGRAM(")[1].split(")")[0]
29+
if name == "":
30+
name = directory
31+
if name == "":
32+
continue
33+
dir_path = Path(dir_path)
34+
gitignore = dir_path / ".gitignore"
35+
gitignore_text = name
36+
if (gitignore).exists():
37+
if name in gitignore.read_text():
38+
continue
39+
gitignore_text = gitignore.read_text() + "\n" + name
40+
gitignore.write_text(gitignore_text)

0 commit comments

Comments
 (0)