forked from KDABLabs/autogen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autogen.py
115 lines (96 loc) · 4.34 KB
/
autogen.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os, sys, subprocess
if sys.version_info[0] != 2:
print ("Autogen detected that you are not using Python2.")
print ("Please make sure you have Python2 installed and run:")
print (" python2 autogen.py")
sys.exit(0)
from cpack import CPackGenerateConfiguration
from configure import ConfigureScriptGenerator
from header import ForwardHeaderGenerator
def parseSvnInfo( stdout ):
repositoryUrl = stdout.splitlines()[1].split( ':', 1 )[ 1 ]
isTagged = repositoryUrl.find( 'tags/' ) != -1
repositoryRevision = stdout.splitlines()[ 4 ].split( ':', 1 )[ 1 ].strip()
return isTagged, repositoryRevision
def checkVCS( sourceDirectory ):
repositoryType = ''
for i in xrange( 20 ):
listing = os.listdir( sourceDirectory + '/..' * i )
if '.svn' in listing:
repositoryType = 'svn'
break
elif '.git' in listing:
repositoryType = 'git'
break
isTagged = False
repositoryRevision = "unknown"
try:
if repositoryType == 'git':
p = subprocess.Popen( ["git", "describe", "--exact-match"], cwd = sourceDirectory, stdout = subprocess.PIPE, stderr = subprocess.PIPE )
stdout, stderr = p.communicate()
if p.returncode == 0:
# git tag
isTagged = True
repositoryRevision = stdout.strip()
if p.returncode != 0:
p = subprocess.Popen( ["git", "svn", "info"], cwd = sourceDirectory, stdout = subprocess.PIPE, stderr = subprocess.PIPE )
stdout, stderr = p.communicate()
if p.returncode == 0:
# git-svn revision
isTagged, repositoryRevision = parseSvnInfo( stdout )
if p.returncode != 0:
p = subprocess.Popen( ["git", "rev-parse", "HEAD"], cwd = sourceDirectory, stdout = subprocess.PIPE, stderr = subprocess.PIPE )
stdout, stderr = p.communicate()
if p.returncode == 0:
# svn revision
repositoryRevision = stdout.strip()[:8]
elif repositoryType == 'svn':
p = subprocess.Popen( ["svn", "info"], cwd = sourceDirectory, stdout = subprocess.PIPE, stderr = subprocess.PIPE )
stdout, stderr = p.communicate()
if p.returncode == 0:
isTagged, repositoryRevision = parseSvnInfo( stdout )
else:
raise Exception("Unknown repository type")
except:
print( "Error: Not a valid SVN or Git repository: {0}".format( sourceDirectory ) )
sys.exit( 1 )
return ( repositoryRevision, isTagged )
def autogen(project, version, subprojects, prefixed, forwardHeaderMap = {}, steps=["generate-cpack", "generate-configure", "generate-forward-headers"], installPrefix="$$INSTALL_PREFIX", policyVersion = 1):
global __policyVersion
__policyVersion = policyVersion
sourceDirectory = os.path.abspath( os.path.dirname( os.path.dirname( __file__ ) ) )
buildDirectory = os.getcwd()
print( "-- Using source directory: {0}".format( sourceDirectory ) )
( repositoryRevision, isTagged ) = checkVCS( sourceDirectory )
print( "-- Using repository information: revision={0} isTagged={1}".format( repositoryRevision, isTagged ) )
if "generate-cpack" in steps:
licensePath = os.path.join( sourceDirectory, "LICENSE.txt" )
cpackConfigurationGenerator = CPackGenerateConfiguration( project, version, sourceDirectory,
buildDirectory, repositoryRevision, licensePath, isTaggedRevision = isTagged )
cpackConfigurationGenerator.run()
if "generate-configure" in steps:
configureScriptGenerator = ConfigureScriptGenerator( project, sourceDirectory, version )
configureScriptGenerator.run()
includePath = os.path.join( sourceDirectory, "include" )
srcPath = os.path.join( sourceDirectory, "src" )
if subprojects and "generate-cpack" in steps:
forwardHeaderGenerator = ForwardHeaderGenerator(
copy = True, path = sourceDirectory, includepath = includePath, srcpath = srcPath,
project = project, subprojects = subprojects, prefix = installPrefix, prefixed = prefixed,
additionalHeaders = forwardHeaderMap
)
forwardHeaderGenerator.run()
print( "-- Auto-generation done." )
with file( ".license.accepted", 'a' ):
os.utime( ".license.accepted", None )
print( "-- License marked as accepted." )
print( "-- Wrote build files to: {0}".format( buildDirectory ) )
print( "-- Now running configure script." )
print( "" )
sys.stdout.flush()
configureFile = 'configure.bat' if sys.platform == 'win32' else 'configure.sh'
configurePath = os.path.join( sourceDirectory, configureFile )
os.execvp( configurePath, [configurePath] + sys.argv[1:] )
def policyVersion():
global __policyVersion
return __policyVersion