Skip to content

Commit 31f25ab

Browse files
committed
refactor debian packager
motivation: add docker support + prepare for sharing changes: * add docker and docker compose setup to build in docker * move shared scripts and metadata into the "shared" directory * rename getsource.sh to build_source_package.sh and udpate it to handle the new directory structure * create build_deb.sh driver script to do the package building end-to-end * update readme with details
1 parent 6924ad6 commit 31f25ab

13 files changed

+203
-76
lines changed
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
set -eux
4+
5+
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
7+
# load version definitions
8+
. ${here}/versions.sh
9+
10+
# working in /tmp since docker file sharing makes this very slow to do dirctly on the share
11+
staging_dir=/tmp/swift-deb-builder
12+
pacakge_dir=${staging_dir}/swiftlang-${debversion}
13+
14+
# clean
15+
#rm -rf ${staging_dir} && mkdir -p ${staging_dir}
16+
rm -rf ${pacakge_dir} && mkdir -p ${pacakge_dir}
17+
18+
# copy control files to pakcage build directory
19+
mkdir -p ${pacakge_dir}/debian
20+
cp ${here}/changelog ${pacakge_dir}/debian/changelog
21+
cp ${here}/control.in ${pacakge_dir}/debian/control.in
22+
cp ${here}/control.in ${pacakge_dir}/debian/control
23+
cp -r ${here}/source ${pacakge_dir}/debian/source
24+
cp -r ${here}/patches ${pacakge_dir}/debian/patches
25+
cp ${here}/rules ${pacakge_dir}/debian/rules
26+
cp ${here}/swiftlang-X.Y.Z.install.in ${pacakge_dir}/debian/swiftlang-X.Y.Z.install.in
27+
cp ${here}/swiftlang.links.in ${pacakge_dir}/debian/swiftlang.links.in
28+
29+
# build the source package
30+
${here}/build_source_package.sh ${staging_dir}
31+
32+
# install the build dependencies
33+
cd ${staging_dir}
34+
mk-build-deps --install ${pacakge_dir}/debian/control.in --tool 'apt-get -y -o Debug::pkgProblemResolver=yes --no-install-recommends'
35+
36+
# build the installable package
37+
cd ${pacakge_dir}
38+
DEB_BUILD_OPTIONS=parallel=64 debuild

platforms/Linux/DEB/Ubuntu/focal/debian/getsource.sh renamed to platforms/Linux/DEB/Shared/build_source_package.sh

+24-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# Create swiftlang-X.Y.Z, unpack the debian tarball within,
1212
# proceed to adding the appropriate entry to the Debian
13-
# changelog, edit debian/source-version.sh, then run this
13+
# changelog, edit /source-version.sh, then run this
1414
# script from the directory containing swiftlang-X.Y.Z.
1515
# $ mkdir swiftlang-X.Y.Z
1616
# $ cd swiftlang-X.Y.Z
@@ -27,17 +27,22 @@
2727
# $ cd swiftlang-X.Y.Z
2828
# $ DEB_BUILD_OPTIONS=parallel=64 debuild
2929

30-
set -eu
30+
set -eux
3131

32-
. $(dirname $0)/source-versions.sh
32+
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
33+
34+
# load version definitions
35+
. ${here}/versions.sh
36+
37+
staging_dir=$1
38+
pacakge_dir=$staging_dir/swiftlang-${debversion}
3339

3440
get_component ()
3541
{
3642
component=$1
3743
url="$2"
3844

39-
dest=swiftlang_${debversion}.orig-${component}
40-
45+
dest=${staging_dir}/swiftlang_${debversion}.orig-${component}
4146
echo "Downloading ${component} from ${url}"
4247

4348
case "${url}" in
@@ -51,7 +56,10 @@ get_component ()
5156

5257
*.tar.gz)
5358
dest=${dest}.tar.gz
54-
curl -L -o ${dest} "${url}"
59+
# temp
60+
if [ ! -f ${dest} ]; then
61+
curl -L -o ${dest} "${url}"
62+
fi
5563
;;
5664

5765
*.tar.xz)
@@ -69,10 +77,12 @@ get_component ()
6977
exit 1
7078
esac
7179

72-
mkdir swiftlang-${debversion}/${component}
73-
tar -C swiftlang-${debversion}/${component} --strip-components=1 -axf ${dest}
80+
echo "Extracting ${component}"
81+
mkdir ${pacakge_dir}/${component}
82+
tar -C ${pacakge_dir}/${component} --strip-components=1 -axf ${dest}
7483
}
7584

85+
# download
7686
get_component swift https://github.com/apple/swift/archive/swift-${swift_version}.tar.gz
7787
get_component swift-corelibs-libdispatch https://github.com/apple/swift-corelibs-libdispatch/archive/swift-${swift_version}.tar.gz
7888
get_component swift-corelibs-foundation https://github.com/apple/swift-corelibs-foundation/archive/swift-${swift_version}.tar.gz
@@ -109,10 +119,10 @@ get_component swift-lmdb https://github.com/apple/swift-lmdb/archive/swift-${swi
109119
get_component swift-markdown https://github.com/apple/swift-markdown/archive/swift-${swift_version}.tar.gz
110120

111121
# Refresh patches, if any
112-
if [ -s swiftlang-${debversion}/debian/patches/series ]; then
113-
cd swiftlang-${debversion}
122+
if [ -s ${pacakge_dir}/debian/patches/series ]; then
123+
cd ${pacakge_dir}
114124

115-
export QUILT_PATCHES=debian/patches
125+
export QUILT_PATCHES=debian/patches
116126
export QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"
117127

118128
while quilt push; do quilt refresh; done
@@ -121,4 +131,6 @@ if [ -s swiftlang-${debversion}/debian/patches/series ]; then
121131
cd -
122132
fi
123133

124-
dpkg-source --create-empty-orig -b swiftlang-${debversion}
134+
# create a source package
135+
cd $staging_dir
136+
dpkg-source --create-empty-orig -b ${pacakge_dir}

platforms/Linux/DEB/Ubuntu/README.md

+70
Original file line numberDiff line numberDiff line change
@@ -1 +1,71 @@
11
## Ubuntu
2+
3+
Ubuntu uses the [Deb package format]() to install software packages.
4+
The Swift Deb package can be built either by creating a Linux container image or manually on a computer running Ubuntu.
5+
6+
There are separate directories for each version of Ubuntu.
7+
The instructions below are applicable to all versions.
8+
9+
## Importand file and directories
10+
11+
**build_deb.sh**
12+
Driver file to build the deb package
13+
14+
**build_source.sh**
15+
Driver file to build the deb source package (which is a step in `build_deb`)
16+
17+
**patches/*.patch**
18+
Any post-release patches that have not yet been merged upstream that are temporarily necessary to build Swift.
19+
20+
**control.in**
21+
Debian package metadata, including the `BuildDepends` and `Depends` definitions.
22+
23+
**changelog**
24+
Debian package changelog
25+
26+
**rules**
27+
Debian package recipe
28+
29+
**Dockerfile**
30+
Defines the base docker image to run the install scripts in.
31+
32+
**docker-compose**
33+
Defines docker compose tasks to drive the pacakge build in Docker.
34+
35+
## Importand file and directories
36+
37+
**Shared/version.sh**
38+
Shell fragment versions.sh containing version information for all source components, and the Debian package upstream version (debversion).
39+
40+
**Shared/copyright**
41+
Copyright information
42+
43+
### Building with docker-compose
44+
45+
* to run the build end-to-end
46+
47+
```
48+
docker-compose run build
49+
```
50+
51+
* to enter the docker env in shell mode
52+
53+
```
54+
docker-compose run shell
55+
```
56+
57+
then you can run `./build_deb.sh` to run the build manually inside the docker
58+
59+
60+
* to rebuild the base image
61+
62+
```
63+
docker-compose build --pull
64+
```
65+
66+
note this still uses the docker cache, so will rebuild only if the version of the underlying base image changed upstream
67+
68+
### Building locally on an Ubuntu machine
69+
70+
1. Install required development tools (see Dockerfile)
71+
2. Run `./build_deb.sh`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
FROM ubuntu:focal
10+
LABEL PURPOSE="This image is configured to build Swift for the version of Ubuntu listed above"
11+
12+
ARG DEBIAN_FRONTEND=noninteractive
13+
14+
RUN apt-get update
15+
16+
# Required deb packaging tools
17+
RUN apt-get install -y curl devscripts equivs quilt tar
18+
19+
# Optimization: Install Swift build requirements listed in the control file
20+
ADD control.in /tmp/control.in
21+
RUN mk-build-deps --install /tmp/control.in --tool 'apt-get -y -o Debug::pkgProblemResolver=yes --no-install-recommends'

platforms/Linux/DEB/Ubuntu/focal/README.md

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/build_deb.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/build_source_package.sh

platforms/Linux/DEB/Ubuntu/focal/debian/README.source

-17
This file was deleted.

platforms/Linux/DEB/Ubuntu/focal/debian/control

-46
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
# this setup is designed to build the RPM with docker
10+
# usage:
11+
# docker-compose -f platforms/Linux/DEB/ubuntu/focal/docker-compose.yaml build
12+
# to shell into the container for debugging purposes:
13+
# docker-compose -f platforms/Linux/DEB/ubuntu/focal/docker-compose.yaml run build
14+
15+
version: "2"
16+
17+
services:
18+
19+
docker-setup:
20+
image: ubuntu-focal-deb-builder
21+
build:
22+
context: .
23+
dockerfile: Dockerfile
24+
25+
common: &common
26+
image: ubuntu-focal-deb-builder
27+
depends_on: [docker-setup]
28+
volumes:
29+
- ../../Ubuntu/focal:/code/Ubuntu/focal:z
30+
- ../../Shared:/code/Shared:z
31+
- ./.output:/output:z
32+
working_dir: /code/Ubuntu/focal
33+
cap_drop:
34+
- CAP_NET_RAW
35+
- CAP_NET_BIND_SERVICE
36+
37+
build:
38+
<<: *common
39+
command: /bin/bash -cl "./build_deb.sh"
40+
41+
#createrepo:
42+
# <<: *common
43+
# command: /bin/bash -cl "./createrepo_rpm.sh"
44+
45+
shell:
46+
<<: *common
47+
entrypoint: /bin/bash -l
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/versions.sh

0 commit comments

Comments
 (0)