Skip to content

Commit a206981

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

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

generate_gitignore.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
if ya_make_path.startswith("yt"):
22+
continue
23+
dir_path = ya_make_path.replace("/ya.make", "")
24+
directory = dir_path.split("/")[-1]
25+
name = ""
26+
if "PROGRAM" in contents:
27+
if "PROGRAM(" not in contents:
28+
continue
29+
name = contents.split("PROGRAM(")[1].split(")")[0]
30+
if name == "":
31+
name = directory
32+
if name == "":
33+
continue
34+
dir_path = Path(dir_path)
35+
gitignore = dir_path / ".gitignore"
36+
gitignore_text = name
37+
if (gitignore).exists():
38+
if name in gitignore.read_text():
39+
continue
40+
gitignore_text = gitignore.read_text() + "\n" + name
41+
gitignore.write_text(gitignore_text)

0 commit comments

Comments
 (0)