Compare commits
2 Commits
6b6eaaa7cf
...
92b6d6a12f
| Author | SHA1 | Date | |
|---|---|---|---|
| 92b6d6a12f | |||
| e0e4345a31 |
48
scripts/build_env.py
Normal file
48
scripts/build_env.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
def ghdlEnvExists(relativePath="work"):
|
||||||
|
## Check if work exists
|
||||||
|
try:
|
||||||
|
os.lstat(relativePath)
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
## Check that work is writable
|
||||||
|
if not os.access(relativePath, os.W_OK):
|
||||||
|
print(f"{relativePath} is write-protected, please acquire correct permissions")
|
||||||
|
return False
|
||||||
|
cfFileExists = False
|
||||||
|
filesInWork = os.listdir(relativePath)
|
||||||
|
for file in filesInWork:
|
||||||
|
if ".cf" in file:
|
||||||
|
cfFileExists = True
|
||||||
|
if not cfFileExists:
|
||||||
|
return False
|
||||||
|
## Nothing bad, continue
|
||||||
|
return True
|
||||||
|
|
||||||
|
def createBuildEnv():
|
||||||
|
if ghdlEnvExists():
|
||||||
|
return -1
|
||||||
|
## Create build env
|
||||||
|
os.makedirs("work",exist_ok=True)
|
||||||
|
addAllVHDLFiles(init=False)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def addAllVHDLFiles(init=False):
|
||||||
|
## Ensure everything is ready for adding files
|
||||||
|
## (init exception to avoid one if-case in ghdlEnvExists)
|
||||||
|
if not ghdlEnvExists() and not init:
|
||||||
|
return -1
|
||||||
|
## Add files
|
||||||
|
vhdlFiles = []
|
||||||
|
for file in os.listdir():
|
||||||
|
if ".vhd" in file:
|
||||||
|
vhdlFiles.append(file)
|
||||||
|
command = ["ghdl", "-i", "--workdir=work"] + vhdlFiles
|
||||||
|
subprocess.run(command)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
createBuildEnv()
|
||||||
Loading…
x
Reference in New Issue
Block a user