Skip to content

Commit

Permalink
Use different packages and binaries for nsbox-edge
Browse files Browse the repository at this point in the history
  • Loading branch information
refi64 committed Sep 8, 2019
1 parent 3027940 commit 130ba4d
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 43 deletions.
54 changes: 37 additions & 17 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ action("release_files") {

symlink("vendor_symlink") {
name = "$go_target_dir/vendor"
value = rebase_path("//vendor", root_build_dir)
value = rebase_path("//vendor")
}

substitute_file("host_paths") {
source = "internal/paths/host_paths.template.go"
output = "$go_target_dir/internal/paths/host_paths.go"
vars = substitute_config_vars

vars = substitute_config_vars + [
["PRODUCT_NAME", product_name]
]
}

substitute_file("nsbox_profile") {
Expand Down Expand Up @@ -94,34 +97,47 @@ action("nsbox-varlink-interface") {
deps = [":gofiles", ":varlink-go-interface-generator"]
}

binaries = ["nsbox", "nsboxd", "nsbox-host"]
go_deps = [":gofiles", ":nsbox-varlink-interface"]

foreach(binary, binaries) {
go_binary(binary) {
package = "github.com/refi64/nsbox/cmd/$binary"
deps = [":gofiles", ":nsbox-varlink-interface"]
go_binary(product_name) {
package = "github.com/refi64/nsbox/cmd/nsbox"
deps = [":gofiles", ":nsbox-varlink-interface"]
}

if (binary == "nsbox-host") {
static = true
}
}
go_binary("nsboxd") {
package = "github.com/refi64/nsbox/cmd/nsboxd"
deps = go_deps
}

go_binary("nsbox-host") {
package = "github.com/refi64/nsbox/cmd/nsbox-host"
deps = go_deps
static = true
}

copy("install-bin") {
sources = get_target_outputs(":nsbox")
sources = get_target_outputs(":$product_name")
outputs = ["$install_dir/$bin_dir/{{source_file_part}}"]
deps = [":nsbox"]
deps = [":$product_name"]
}

if (!is_stable_build) {
symlink("install-bin-edge-alias") {
name = "$install_dir/$bin_dir/nsbox"
value = "./nsbox-edge"
deps = [":nsbox-edge"]
}
}

copy("install-etc") {
sources = get_target_outputs(":nsbox_profile")
outputs = ["$install_dir/$config_dir/profile.d/nsbox.sh"]
outputs = ["$install_dir/$config_dir/profile.d/$product_name.sh"]
deps = [":nsbox_profile"]
}

copy("install-private-exec") {
sources = get_target_outputs(":nsboxd") + get_target_outputs(":nsbox-host")
outputs = ["$install_dir/$libexec_dir/nsbox/{{source_file_part}}"]
outputs = ["$install_dir/$libexec_dir/$product_name/{{source_file_part}}"]
deps = [":nsboxd", ":nsbox-host"]
}

Expand All @@ -135,13 +151,13 @@ copy("install-share-data") {
"data/scripts/nsbox-enter-setup.sh",
"data/scripts/nsbox-init.sh",
]
outputs = ["$install_dir/$share_dir/nsbox/{{source}}"]
outputs = ["$install_dir/$share_dir/$product_name/{{source}}"]
}

copy("install-share-release") {
sources = get_target_outputs(":release_files")
deps = [":release_files"]
outputs = ["$install_dir/$share_dir/nsbox/release/{{source_file_part}}"]
outputs = ["$install_dir/$share_dir/$product_name/release/{{source_file_part}}"]
}

group("nsbox-install-root") {
Expand All @@ -152,6 +168,10 @@ group("nsbox-install-root") {
":install-share-data",
":install-share-release",
]

if (!is_stable_build) {
deps += [":install-bin-edge-alias"]
}
}

group("default") {
Expand Down
2 changes: 2 additions & 0 deletions build/BUILDCONFIG.gn
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ if (override_release_version != "") {

if (is_stable_build) {
release_branch = "stable"
product_name = "nsbox"
} else {
release_branch = "edge"
product_name = "nsbox-edge"
}
16 changes: 11 additions & 5 deletions build/rpmbuild.gni
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ template("rpmbuild") {
sources += get_target_outputs(":${target_name}_sources")
}

outputs = ["$topdir/RPMS/$arch/$package_name-$version-$release.$fc.$arch.rpm",
"$topdir/SRPMS/$package_name-$version-$release.$fc.src.rpm"]

binary_packages = [package_name]
if (defined(invoker.has_debug) && invoker.has_debug) {
outputs += ["$topdir/RPMS/$arch/$package_name-debuginfo-$version-$release.$fc.$arch.rpm",
"$topdir/RPMS/$arch/$package_name-debugsource-$version-$release.$fc.$arch.rpm"]
binary_packages += ["$package_name-debuginfo", "$package_name-debugsource"]
}

if (defined(invoker.extra_packages)) {
binary_packages += invoker.extra_packages
}

outputs = ["$topdir/SRPMS/$package_name-$version-$release.$fc.src.rpm"]
foreach(pkg, binary_packages) {
outputs += ["$topdir/RPMS/$arch/$pkg-$version-$release.$fc.$arch.rpm"]
}

script = "//build/bin_proxy.py"
Expand Down
4 changes: 3 additions & 1 deletion build/symlink.gni
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ template("symlink") {
stamp = "$target_gen_dir/$target_name.stamp"

script = "//build/symlink.py"
args = [rebase_path(invoker.value, root_build_dir),
args = [invoker.value,
rebase_path(invoker.name, root_build_dir),
rebase_path(stamp, root_build_dir)]
sources = []
outputs = [stamp]

forward_variables_from(invoker, ["deps"])
}
}
2 changes: 1 addition & 1 deletion build/symlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

_, source, dest, stamp = sys.argv

if os.path.exists(dest):
if os.path.islink(dest):
os.unlink(dest)

os.makedirs(os.path.dirname(dest), exist_ok=True)
Expand Down
6 changes: 3 additions & 3 deletions internal/daemon/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ func RunContainerDirectNspawn(ct *container.Container, usrdata *userdata.Userdat

builder.AddBindTo(hostPrivPath, "/run/host/nsbox")

scripts, err := paths.GetPathRelativeToInstallRoot(paths.Share, "nsbox", "data", "scripts")
scripts, err := paths.GetPathRelativeToInstallRoot(paths.Share, paths.ProductName, "data", "scripts")
if err != nil {
return errors.Wrap(err, "failed to locate scripts")
}

builder.AddBindTo(scripts, filepath.Join(paths.InContainerPrivPath, "scripts"))

nsboxHost, err := paths.GetPathRelativeToInstallRoot(paths.Libexec, "nsbox", "nsbox-host")
nsboxHost, err := paths.GetPathRelativeToInstallRoot(paths.Libexec, paths.ProductName, "nsbox-host")
if err != nil {
return errors.Wrap(err, "failed to locate nsbox-host")
}
Expand All @@ -238,7 +238,7 @@ func RunContainerDirectNspawn(ct *container.Container, usrdata *userdata.Userdat
// stuff into the in-container runtime directory as needed.
builder.AddBindTo(xdgRuntimeDir, filepath.Join(paths.InContainerPrivPath, "usr-run"))

dataDir, err := paths.GetPathRelativeToInstallRoot(paths.Share, "nsbox", "data")
dataDir, err := paths.GetPathRelativeToInstallRoot(paths.Share, paths.ProductName, "data")
if err != nil {
return errors.Wrap(err, "failed to locate nsbox-init.service")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/daemon/transient.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func RunContainerViaTransientUnit(ct *container.Container, usrdata *userdata.Use
}

if _, err := machined.GetMachine(ct.Name); err != nil {
nsboxd, err := paths.GetPathRelativeToInstallRoot(paths.Libexec, "nsbox", "nsboxd")
nsboxd, err := paths.GetPathRelativeToInstallRoot(paths.Libexec, paths.ProductName, "nsboxd")
if err != nil {
return errors.Wrap(err, "cannot locate nsboxd")
}
Expand Down
1 change: 1 addition & 0 deletions internal/paths/host_paths.template.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ package paths
const State = "@STATE_DIR"
const Libexec = "@LIBEXEC_DIR"
const Share = "@SHARE_DIR"
const ProductName = "@PRODUCT_NAME"
9 changes: 7 additions & 2 deletions packaging/fedora/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,26 @@ substitute_file("nsbox.spec") {

vars = [
["GN", package_gn],
["PRODUCT_NAME", product_name],
]

file_vars = [
["VERSION", release_files[0]],
["BRANCH", release_files[1]],
["SPECDEFS", rpm_deps_spec[0]],
]
}

rpmbuild("rpm") {
package_name = "nsbox"
package_name = product_name

version = release_version
release = "1"
has_debug = true

if (!is_stable_build) {
extra_packages = ["nsbox-edge-alias"]
}

archive_source = get_target_outputs(":archive")
substituted_spec = get_target_outputs(":nsbox.spec")

Expand Down
41 changes: 28 additions & 13 deletions packaging/fedora/nsbox.spec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# nsbox-host has missing build-ids due to being static.
%global _missing_build_ids_terminate_build 0

Name: nsbox
Name: @PRODUCT_NAME
Version: @VERSION
Release: 1%{?dist}
Summary: A multi-purpose, nspawn-powered container manager
Expand All @@ -35,6 +35,13 @@ Source1: https://gn.googlesource.com/gn/+archive/@GN.tar.gz#/gn.tar.gz
%description
nsbox is a multi-purpose, nspawn-powered container manager.

%if "%{name}" == "nsbox-edge"
%package alias
Summary: Alias for nsbox-edge
%description alias
Installs the nsbox alias for nsbox-edge.
%endif

%prep
rm -rf %{name}-%{version}

Expand Down Expand Up @@ -81,6 +88,9 @@ share_dir = "%{reldatadir}"
state_dir = "%{_sharedstatedir}"
config_dir = "%{_sysconfdir}"
override_release_version = "@VERSION"
%if "%{name}" != "nsbox-edge"
is_stable_build = true
%endif
EOF
gn/out/gn gen out
ninja -C out
Expand All @@ -92,16 +102,21 @@ cp -r out/install/{%{relbindir},%{rellibexecdir},%{reldatadir}} %{buildroot}/%{_
chmod -R g-w %{buildroot}

%files
%{_bindir}/%{name}
%{_sysconfdir}/profile.d/%{name}.sh
%{_libexecdir}/%{name}/nsbox-host
%{_libexecdir}/%{name}/nsboxd
%{_datadir}/%{name}/data/getty-override.conf
%{_datadir}/%{name}/data/nsbox-container.target
%{_datadir}/%{name}/data/nsbox-init.service
%{_datadir}/%{name}/data/scripts/nsbox-apply-env.sh
%{_datadir}/%{name}/data/scripts/nsbox-enter-run.sh
%{_datadir}/%{name}/data/scripts/nsbox-enter-setup.sh
%{_datadir}/%{name}/data/scripts/nsbox-init.sh
%{_datadir}/%{name}/release/VERSION
%{_datadir}/%{name}/release/BRANCH

%if "%{name}" == "nsbox-edge"
%files alias
%{_bindir}/nsbox
%{_sysconfdir}/profile.d/nsbox.sh
%{_libexecdir}/nsbox/nsbox-host
%{_libexecdir}/nsbox/nsboxd
%{_datadir}/nsbox/data/getty-override.conf
%{_datadir}/nsbox/data/nsbox-container.target
%{_datadir}/nsbox/data/nsbox-init.service
%{_datadir}/nsbox/data/scripts/nsbox-apply-env.sh
%{_datadir}/nsbox/data/scripts/nsbox-enter-run.sh
%{_datadir}/nsbox/data/scripts/nsbox-enter-setup.sh
%{_datadir}/nsbox/data/scripts/nsbox-init.sh
%{_datadir}/nsbox/release/VERSION
%{_datadir}/nsbox/release/BRANCH
%endif

0 comments on commit 130ba4d

Please sign in to comment.