-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild_packages.py
executable file
·75 lines (64 loc) · 2.72 KB
/
build_packages.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
#!/usr/bin/env python3
# Copyright (c) 2015 Nuxi, https://nuxi.nl/
#
# SPDX-License-Identifier: BSD-2-Clause
import logging
import os
import sys
from src import config
from src import util
from src.catalog import (ArchLinuxCatalog, CygwinCatalog, DebianCatalog,
FreeBSDCatalog, HomebrewCatalog, NetBSDCatalog,
OpenBSDCatalog, RedHatCatalog)
from src.package import TargetPackage
from src.repository import Repository
from src.version import FullVersion
# Setup logging
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
# Locations relative to the source tree.
DIR_ROOT = os.getcwd()
DIR_DISTFILES = os.path.join(DIR_ROOT, '_obj/distfiles')
DIR_INSTALL = os.path.join(DIR_ROOT, '_obj/install')
DIR_PACKAGES_ARCHLINUX = os.path.join(DIR_ROOT, '_obj/packages/archlinux')
DIR_PACKAGES_CYGWIN = os.path.join(DIR_ROOT, '_obj/packages/cygwin')
DIR_PACKAGES_DEBIAN = os.path.join(DIR_ROOT, '_obj/packages/debian')
DIR_PACKAGES_FREEBSD = os.path.join(DIR_ROOT, '_obj/packages/freebsd')
DIR_PACKAGES_HOMEBREW = os.path.join(DIR_ROOT, '_obj/packages/homebrew')
DIR_PACKAGES_NETBSD = os.path.join(DIR_ROOT, '_obj/packages/netbsd')
DIR_PACKAGES_OPENBSD = os.path.join(DIR_ROOT, '_obj/packages/openbsd')
DIR_PACKAGES_REDHAT = os.path.join(DIR_ROOT, '_obj/packages/redhat')
DIR_REPOSITORY = os.path.join(DIR_ROOT, 'packages')
# Parse all of the BUILD rules.
repo = Repository(DIR_INSTALL)
for filename in util.walk_files(DIR_REPOSITORY):
if os.path.basename(filename) == 'BUILD':
repo.add_build_file(filename, DIR_DISTFILES)
target_packages = repo.get_target_packages()
catalogs = {
ArchLinuxCatalog(None, DIR_PACKAGES_ARCHLINUX),
CygwinCatalog(None, DIR_PACKAGES_CYGWIN),
DebianCatalog(None, DIR_PACKAGES_DEBIAN),
FreeBSDCatalog(None, DIR_PACKAGES_FREEBSD),
HomebrewCatalog(None, DIR_PACKAGES_HOMEBREW, 'http://example.com/'),
NetBSDCatalog(None, DIR_PACKAGES_NETBSD),
OpenBSDCatalog(None, DIR_PACKAGES_OPENBSD),
RedHatCatalog(None, DIR_PACKAGES_REDHAT),
}
def build_package(package: TargetPackage) -> None:
version = FullVersion(version=package.get_version())
for catalog in catalogs:
catalog.insert(package, version, catalog.package(package, version))
if len(sys.argv) > 1:
# Only build the packages provided on the command line.
for name in set(sys.argv[1:]):
for arch in config.ARCHITECTURES:
build_package(target_packages[(name, arch)])
else:
# Build all packages.
for package in target_packages.values():
build_package(package)
# When terminating successfully, remove the build directory. It will
# only contain temporary files that were used to generate the last
# package.
util.remove(config.DIR_BUILDROOT)