From efda4aff7cb5cdca3237a52e5fb6c805f4403c5a Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Mon, 13 Jan 2025 10:57:09 -0800 Subject: [PATCH] Add GN target to build Debian package from regular output. Bug: https://github.com/dart-lang/sdk/issues/26953 Cq-Include-Trybots: luci.dart.try:dart-sdk-linux-arm64-try,dart-sdk-linux-riscv64-try,dart-sdk-linux-try Change-Id: I38dfcadee836733c2e8824c2da21b9619dd2fc77 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281307 Reviewed-by: Alexander Thomas Commit-Queue: Ryan Macnak --- BUILD.gn | 3 + tools/debian_package/BUILD.gn | 47 +++++++++++++ tools/debian_package/create_debian_package.py | 69 +++++++++++++++++++ tools/debian_package/debian/compat | 1 + tools/debian_package/debian/control | 11 +++ tools/debian_package/debian/dart.install | 2 + tools/debian_package/debian/dart.links | 2 + tools/debian_package/debian/rules | 35 ++++++++++ tools/debian_package/debian/source/format | 1 + tools/debian_package/get_version.py | 20 ++++++ 10 files changed, 191 insertions(+) create mode 100644 tools/debian_package/BUILD.gn create mode 100755 tools/debian_package/create_debian_package.py create mode 100644 tools/debian_package/debian/compat create mode 100644 tools/debian_package/debian/control create mode 100644 tools/debian_package/debian/dart.install create mode 100644 tools/debian_package/debian/dart.links create mode 100755 tools/debian_package/debian/rules create mode 100644 tools/debian_package/debian/source/format create mode 100755 tools/debian_package/get_version.py diff --git a/BUILD.gn b/BUILD.gn index 133f8e43f98..59b46d4365c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -119,6 +119,9 @@ group("runtime_precompiled") { group("create_sdk") { public_deps = [ "sdk:create_sdk" ] + if (is_linux) { + public_deps += [ "tools/debian_package" ] + } } group("create_platform_sdk") { diff --git a/tools/debian_package/BUILD.gn b/tools/debian_package/BUILD.gn new file mode 100644 index 00000000000..3aeaeb02013 --- /dev/null +++ b/tools/debian_package/BUILD.gn @@ -0,0 +1,47 @@ +# Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +if (is_linux) { + action("debian_package") { + version = exec_script("get_version.py", [], "trim string") + if (target_cpu == "x86" || target_cpu == "ia32") { + debian_arch = "i386" + lib_dir = "//buildtools/sysroot/linux/lib/i386-linux-gnu" + } else if (target_cpu == "x64") { + debian_arch = "amd64" + lib_dir = "//buildtools/sysroot/linux/lib/x86_64-linux-gnu" + } else if (target_cpu == "arm") { + debian_arch = "armhf" + lib_dir = "//buildtools/sysroot/linux/lib/arm-linux-gnueabihf" + } else if (target_cpu == "arm64") { + debian_arch = "arm64" + lib_dir = "//buildtools/sysroot/linux/lib/aarch64-linux-gnu" + } else if (target_cpu == "riscv64") { + debian_arch = "riscv64" + lib_dir = "//buildtools/sysroot/focal/lib/riscv64-linux-gnu/" + } else { + assert(false, "Don't know Debian name for $target_cpu") + } + + deps = [ "../../sdk:create_sdk" ] + inputs = [ + "create_debian_package.py", + "debian/compat", + "debian/control", + "debian/dart.install", + "debian/dart.links", + "debian/rules", + "debian/source/format", + ] + outputs = [ "$root_out_dir/dart_${version}-1_${debian_arch}.deb" ] + script = "../../build/gn_run_binary.py" + args = [ + "compiled_action", + rebase_path("create_debian_package.py"), + "--version=$version", + "--arch=$debian_arch", + "--lib_dir=" + rebase_path(lib_dir), + ] + } +} diff --git a/tools/debian_package/create_debian_package.py b/tools/debian_package/create_debian_package.py new file mode 100755 index 00000000000..4c6cb9bd120 --- /dev/null +++ b/tools/debian_package/create_debian_package.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +import optparse +import os +import shutil +import subprocess +import sys +from os.path import join, split, abspath, dirname + +sys.path.append(join(dirname(__file__), '..')) +import utils + +DART_DIR = abspath(join(dirname(__file__), '..', '..')) + + +def BuildOptions(): + result = optparse.OptionParser() + result.add_option("--version", default=None) + result.add_option("--arch", default=None) + result.add_option("--lib_dir", default=None) + return result + + +def GenerateCopyright(filename): + with open(join(DART_DIR, 'LICENSE')) as lf: + license_lines = lf.readlines() + + with open(filename, 'w') as f: + f.write('Name: dart\n') + f.write('Maintainer: Dart Team \n') + f.write('Source: https://dart.googlesource.com/sdk\n') + f.write('License:\n') + for line in license_lines: + f.write(' %s' % line) # Line already contains trailing \n. + + +def GenerateChangeLog(filename, version): + with open(filename, 'w') as f: + f.write('dart (%s-1) UNRELEASED; urgency=low\n' % version) + f.write('\n') + f.write(' * Generated file.\n') + f.write('\n') + f.write(' -- Dart Team \n') + + +def Main(): + parser = BuildOptions() + (options, args) = parser.parse_args() + + version = options.version + versiondir = 'dart-%s' % version + shutil.copytree(join(DART_DIR, 'tools', 'debian_package', 'debian'), + join(versiondir, 'debian'), + dirs_exist_ok=True) + GenerateCopyright(join(versiondir, 'debian', 'copyright')) + GenerateChangeLog(join(versiondir, 'debian', 'changelog'), version) + + cmd = ['dpkg-buildpackage', '-B', '-a', options.arch, '-us', '-uc'] + env = os.environ.copy() + env["LIB_DIR"] = options.lib_dir + process = subprocess.check_call(cmd, cwd=versiondir, env=env) + + +if __name__ == '__main__': + sys.exit(Main()) diff --git a/tools/debian_package/debian/compat b/tools/debian_package/debian/compat new file mode 100644 index 00000000000..f599e28b8ab --- /dev/null +++ b/tools/debian_package/debian/compat @@ -0,0 +1 @@ +10 diff --git a/tools/debian_package/debian/control b/tools/debian_package/debian/control new file mode 100644 index 00000000000..94d45b4eaca --- /dev/null +++ b/tools/debian_package/debian/control @@ -0,0 +1,11 @@ +Source: dart +Maintainer: Dart Team +Section: misc +Priority: optional +Standards-Version: 3.9.2 +Build-Depends: python3:native + +Package: dart +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Dart SDK diff --git a/tools/debian_package/debian/dart.install b/tools/debian_package/debian/dart.install new file mode 100644 index 00000000000..0ea869a3aa6 --- /dev/null +++ b/tools/debian_package/debian/dart.install @@ -0,0 +1,2 @@ +debian/tmp/out/dart usr/lib + diff --git a/tools/debian_package/debian/dart.links b/tools/debian_package/debian/dart.links new file mode 100644 index 00000000000..30c3b93ec3f --- /dev/null +++ b/tools/debian_package/debian/dart.links @@ -0,0 +1,2 @@ +usr/lib/dart/bin/dart usr/bin/dart + diff --git a/tools/debian_package/debian/rules b/tools/debian_package/debian/rules new file mode 100755 index 00000000000..c9857cf2f87 --- /dev/null +++ b/tools/debian_package/debian/rules @@ -0,0 +1,35 @@ +#!/usr/bin/make -f +export DH_VERBOSE = 1 + +%: + dh $@ + +# Nop +override_dh_auto_clean: + +# Nop +override_dh_auto_configure: + +# Nop +override_dh_auto_build: + +# Nop +override_dh_auto_test: + +# Nop +override_dh_strip: + +# Nop +override_dh_strip_nondeterminism: + +# This override allows us to ignore spurious missing library errors when +# cross-compiling. +override_dh_shlibdeps: + dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info -l "${LIB_DIR}" + +override_dh_auto_install: + mkdir -p debian/tmp/out + cp -R ../dart-sdk debian/tmp/out + mv debian/tmp/out/dart-sdk debian/tmp/out/dart + dh_install + dh_link diff --git a/tools/debian_package/debian/source/format b/tools/debian_package/debian/source/format new file mode 100644 index 00000000000..163aaf8d82b --- /dev/null +++ b/tools/debian_package/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/tools/debian_package/get_version.py b/tools/debian_package/get_version.py new file mode 100755 index 00000000000..4a43d06c291 --- /dev/null +++ b/tools/debian_package/get_version.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +import sys +from os import listdir +from os.path import join, split, abspath, dirname + +sys.path.append(join(dirname(__file__), '..')) +import utils + + +def Main(): + print(utils.GetVersion()) + + +if __name__ == '__main__': + sys.exit(Main())