2017-12-06 23:52:36 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2017 Google Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
2017-11-27 21:24:43 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
2017-12-04 22:12:36 +00:00
|
|
|
import apt
|
2017-11-27 21:24:43 +00:00
|
|
|
|
2017-12-04 22:12:36 +00:00
|
|
|
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
2017-11-27 21:24:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
def ApplyPatch(source_directory, patch_name):
|
|
|
|
"""Apply custom patch."""
|
|
|
|
subprocess.check_call(['patch', '-p1', '-i',
|
|
|
|
os.path.join(SCRIPT_DIR, patch_name)],
|
|
|
|
cwd=source_directory)
|
|
|
|
|
|
|
|
|
|
|
|
class PackageException(Exception):
|
|
|
|
"""Base package exception."""
|
|
|
|
|
|
|
|
|
|
|
|
class Package(object):
|
|
|
|
"""Base package."""
|
|
|
|
|
2017-12-06 23:52:36 +00:00
|
|
|
def __init__(self, name, apt_version):
|
2017-11-27 21:24:43 +00:00
|
|
|
self.name = name
|
2017-12-06 23:52:36 +00:00
|
|
|
self.apt_version = apt_version
|
2017-11-27 21:24:43 +00:00
|
|
|
|
2017-12-06 23:52:36 +00:00
|
|
|
def PreBuild(self, source_directory, env, custom_bin_dir):
|
2017-11-27 21:24:43 +00:00
|
|
|
return
|
|
|
|
|
2017-12-06 23:52:36 +00:00
|
|
|
def PostBuild(self, source_directory, env, custom_bin_dir):
|
2017-11-27 21:24:43 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def PreDownload(self, download_directory):
|
|
|
|
return
|
|
|
|
|
|
|
|
def PostDownload(self, source_directory):
|
|
|
|
return
|
|
|
|
|
|
|
|
def InstallBuildDeps(self):
|
|
|
|
"""Install build dependencies for a package."""
|
2017-12-07 02:20:01 +00:00
|
|
|
subprocess.check_call(['apt-get', 'update'])
|
2017-11-27 21:24:43 +00:00
|
|
|
subprocess.check_call(['apt-get', 'build-dep', '-y', self.name])
|
|
|
|
|
|
|
|
def DownloadSource(self, download_directory):
|
|
|
|
"""Download the source for a package."""
|
|
|
|
self.PreDownload(download_directory)
|
|
|
|
|
2017-12-06 23:52:36 +00:00
|
|
|
source_directory = self.apt_version.fetch_source(download_directory)
|
2017-11-27 21:24:43 +00:00
|
|
|
|
|
|
|
self.PostDownload(source_directory)
|
|
|
|
return source_directory
|
|
|
|
|
2017-12-06 23:52:36 +00:00
|
|
|
def Build(self, source_directory, env, custom_bin_dir):
|
2017-11-27 21:24:43 +00:00
|
|
|
"""Build .deb packages."""
|
2017-12-06 23:52:36 +00:00
|
|
|
self.PreBuild(source_directory, env, custom_bin_dir)
|
2017-11-27 21:24:43 +00:00
|
|
|
subprocess.check_call(
|
|
|
|
['dpkg-buildpackage', '-us', '-uc', '-b'],
|
|
|
|
cwd=source_directory, env=env)
|
2017-12-06 23:52:36 +00:00
|
|
|
self.PostBuild(source_directory, env, custom_bin_dir)
|
2017-11-27 21:24:43 +00:00
|
|
|
|
|
|
|
|