From 130ba4d9f3f1f5e7e231cadd227828a043e43c4b Mon Sep 17 00:00:00 2001 From: Ryan Gonzalez Date: Sat, 7 Sep 2019 17:41:53 -0500 Subject: [PATCH] Use different packages and binaries for nsbox-edge --- BUILD.gn | 54 ++++++++++++++++++--------- build/BUILDCONFIG.gn | 2 + build/rpmbuild.gni | 16 +++++--- build/symlink.gni | 4 +- build/symlink.py | 2 +- internal/daemon/direct.go | 6 +-- internal/daemon/transient.go | 2 +- internal/paths/host_paths.template.go | 1 + packaging/fedora/BUILD.gn | 9 ++++- packaging/fedora/nsbox.spec | 41 +++++++++++++------- 10 files changed, 94 insertions(+), 43 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 5993b30..dfc3557 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -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") { @@ -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"] } @@ -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") { @@ -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") { diff --git a/build/BUILDCONFIG.gn b/build/BUILDCONFIG.gn index dca5374..ea768df 100644 --- a/build/BUILDCONFIG.gn +++ b/build/BUILDCONFIG.gn @@ -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" } diff --git a/build/rpmbuild.gni b/build/rpmbuild.gni index 81723f0..7fa9f89 100644 --- a/build/rpmbuild.gni +++ b/build/rpmbuild.gni @@ -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" diff --git a/build/symlink.gni b/build/symlink.gni index 91375f4..34dd7a3 100644 --- a/build/symlink.gni +++ b/build/symlink.gni @@ -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"]) } } diff --git a/build/symlink.py b/build/symlink.py index cfd5434..083e8c4 100644 --- a/build/symlink.py +++ b/build/symlink.py @@ -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) diff --git a/internal/daemon/direct.go b/internal/daemon/direct.go index 6fc7673..fe33a87 100644 --- a/internal/daemon/direct.go +++ b/internal/daemon/direct.go @@ -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") } @@ -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") } diff --git a/internal/daemon/transient.go b/internal/daemon/transient.go index 982cb3f..71a1466 100644 --- a/internal/daemon/transient.go +++ b/internal/daemon/transient.go @@ -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") } diff --git a/internal/paths/host_paths.template.go b/internal/paths/host_paths.template.go index a4cf62b..ec26d0a 100644 --- a/internal/paths/host_paths.template.go +++ b/internal/paths/host_paths.template.go @@ -6,3 +6,4 @@ package paths const State = "@STATE_DIR" const Libexec = "@LIBEXEC_DIR" const Share = "@SHARE_DIR" +const ProductName = "@PRODUCT_NAME" diff --git a/packaging/fedora/BUILD.gn b/packaging/fedora/BUILD.gn index 4b5444d..5c100d4 100644 --- a/packaging/fedora/BUILD.gn +++ b/packaging/fedora/BUILD.gn @@ -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") diff --git a/packaging/fedora/nsbox.spec b/packaging/fedora/nsbox.spec index 8f9f8b9..db1c323 100644 --- a/packaging/fedora/nsbox.spec +++ b/packaging/fedora/nsbox.spec @@ -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 @@ -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} @@ -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 @@ -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