-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuildMac.py
59 lines (53 loc) · 2.14 KB
/
buildMac.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# buildMac.py
import os
import subprocess
import errno
import shutil
from progSpec import cdlog, cdErr
def runCMD(myCMD, myDir):
print(" COMMAND: ", myCMD, "\n")
pipe = subprocess.Popen(myCMD, cwd=myDir, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = pipe.communicate()
if out:
print(" Result: ",out)
if err:
print("\n", err)
if (err.find("ERROR")) >= 0:
exit(1)
return [out, err]
def makeDir(dirToGen):
#print "dirToGen:", dirToGen
try:
os.makedirs(dirToGen)
except OSError as exception:
if exception.errno != errno.EEXIST: raise
def writeFile(path, fileName, fileSpecs, fileExtension):
#print path
makeDir(path)
fileName += fileExtension
pathName = path + os.sep + fileName
cdlog(1, "WRITING FILE: "+pathName)
fo=open(pathName, 'w')
fo.write(fileSpecs[0][1])
fo.close()
def macBuilder(debugMode, minLangVersion, projectName, libFiles, buildName, platform, fileSpecs):
# reference https://swift.org/getting-started/#using-the-package-manager
# building without Xcode: https://theswiftdev.com/how-to-build-macos-apps-using-only-the-swift-package-manager/
fileExtension = '.swift'
fileName = "main"
currentDirectory = currentWD = os.getcwd()
buildDirectory = currentDirectory + "/" + buildName
projectDirectory = buildDirectory + "/" + projectName
packageName = 'Package.swift'
makeDir(buildName)
makeDir(buildName+"/"+projectName)
############################################################
rmPackageCmd = "rm "+packageName
packageInitCmd = "swift package init --type executable"
buildCmd = "swift build -Xswiftc -suppress-warnings"
runCmd = "swift run -Xswiftc -suppress-warnings"
############################################################
if os.path.isfile(projectDirectory+'/'+packageName): runCMD(rmPackageCmd, projectDirectory)
runCMD(packageInitCmd, projectDirectory)
writeFile(projectDirectory+"/Sources/"+projectName, fileName, fileSpecs, fileExtension)
return [projectDirectory, buildCmd, runCmd]