create script/cargo.py
[liba.git] / script / cargo.py
blob42c4cc841b80791b6c51c2d0cdf249255842b312
1 #!/usr/bin/env python
2 import sys, os, re
4 SUFFIXS = (".c", ".cc", ".cpp", ".cxx")
5 ROOT = os.path.abspath(sys.argv[0])
6 ROOT = os.path.dirname(ROOT)
7 ROOT = os.path.dirname(ROOT)
10 def main(index=0, SUFFIXS=SUFFIXS):
11 sources = []
12 for dirpath, dirnames, filenames in os.walk("src"):
13 for filename in filenames:
14 source = os.path.join(dirpath, filename)
15 prefix, suffix = os.path.splitext(source)
16 if suffix in SUFFIXS:
17 sources.append(source.replace("\\", "/"))
18 sources = sorted(sources)
20 with open("build.rs", "r") as f:
21 build = f.read()
22 cur = re.findall(r"make([^;]+)\.compile\(\"a\"\)", build)[index]
23 new = '.file("' + '")\n .file("'.join(sources) + '")\n '
24 with open("build.rs", "wb") as f:
25 build = f.write(build.replace(cur, new).encode())
28 os.chdir(ROOT)
29 main()