extract-cmake-dependency-metadata.py 3.35 KB
Newer Older
1
#!/usr/bin/python3
Ben Cooksley's avatar
Ben Cooksley committed
2
import os
3 4
import sys
import argparse
5
import subprocess
6 7 8 9
from helperslib import BuildSpecs, BuildSystem, CommonUtils, EnvironmentHandler, Packages

# Parse the command line arguments we've been given
parser = argparse.ArgumentParser(description='Utility to extract CMake Dependency Metadata from a build system. Provided to assist packagers with their packages.')
10
parser.add_argument('--product', type=str, required=True)
11 12
parser.add_argument('--project', type=str, required=True)
parser.add_argument('--branchGroup', type=str, required=True)
13
parser.add_argument('--platform', type=str, required=True)
14 15 16 17
parser.add_argument('--usingInstall', type=str, required=True)
arguments = parser.parse_args()

# Load our build specification, which governs how we handle this build
Ben Cooksley's avatar
Ben Cooksley committed
18
buildSpecification = BuildSpecs.Loader( product=arguments.product, project=arguments.project, branchGroup=arguments.branchGroup, platform=arguments.platform )
19 20 21 22 23 24 25 26 27

# Determine the environment we need to provide for the compilation process
buildEnvironment = EnvironmentHandler.generateFor( installPrefix=arguments.usingInstall )

# Determine where our source code is checked out to and where we will be building it
# We'll assume that the directory we're running from is where the sources are located
sourcesLocation = os.getcwd()
buildLocation = CommonUtils.buildDirectoryForSources( sources=sourcesLocation, inSourceBuild=buildSpecification['in-source-build'] )

28 29 30 31 32 33
# Are we allowed to run?
# We only gather this metadata from the principal Linux platform, which at the moment is SUSEQt5.7 for Frameworks and SUSEQt5.9 for everyone else
if arguments.platform != 'SUSEQt5.7' and arguments.platform != 'SUSEQt5.9':
	# Then there is nothing for us to do
	sys.exit(0)

34 35 36
# Determine the name we'll use to store the results, as well as the local and remote paths it will be stored at
# We use the package name as it's pretty much guaranteed to be unique among all the builds we will be running
# As the CMake dependency metadata is only used by Linux packagers, we don't need to take platform into account here
Ben Cooksley's avatar
Ben Cooksley committed
37
dependencyFilename = Packages.nameForProject(arguments.product, arguments.project, arguments.branchGroup) + '.json'
38 39 40 41
localDependencyFilename = os.path.join( sourcesLocation, dependencyFilename )
remoteDependencyFilename = os.path.join( '/srv/dependency-metadata/', dependencyFilename )

# Build the command to run
Ben Cooksley's avatar
Ben Cooksley committed
42
commandToRun = "python3 '{0}/kde-dev-scripts/cmake-dependencies.py'"
43 44 45 46 47 48
commandToRun = commandToRun.format( CommonUtils.scriptsBaseDirectory() )

# Time to run the command - open our dependency metadata file...
with open(localDependencyFilename, 'w') as localDependencyFile:
	# Now run the command
	# We redirect stdout and stderr into the file because this program prints it's results to the console (stdout/stderr)
49
	process = subprocess.Popen( commandToRun, stdout=localDependencyFile, stderr=localDependencyFile, shell=True, env=buildEnvironment, cwd=buildLocation )
50 51 52
	process.wait()

# Now we transfer it to it's final home - establish the ssh connection
53
privateKeyFile = os.path.join( os.path.expanduser('~'), 'Keys', 'cmake-dependencies.key')
Ben Cooksley's avatar
Ben Cooksley committed
54
client = CommonUtils.establishSSHConnection( 'charlotte.kde.org', 'dependencymetadata', privateKeyFile )
55
# Bring up a SFTP session
Ben Cooksley's avatar
Ben Cooksley committed
56
sftp = client.open_sftp()
57 58 59 60 61 62

# Transfer it there
sftp.put( localDependencyFilename, remoteDependencyFilename )

# All done, cleanup
sftp.close()
Ben Cooksley's avatar
Ben Cooksley committed
63
client.close()