From 7933a3970cd8c38b85aeabb2af431534b6de99cd Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Tue, 8 Mar 2022 15:59:53 +0000 Subject: [PATCH] Add a post-sync hook to generate the package_config.json file. Change-Id: I19967e8ae7eaa4e3071e335e43932e27128d8173 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/235764 Reviewed-by: Alexander Thomas Commit-Queue: Devon Carew --- DEPS | 6 ++++ tools/generate_package_config.py | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tools/generate_package_config.py diff --git a/DEPS b/DEPS index ea1fd320881..3da1ec86e07 100644 --- a/DEPS +++ b/DEPS @@ -697,6 +697,12 @@ deps_os = { } hooks = [ + { + # Generate the .dart_tool/package_confg.json file. + 'name': 'Generate .dart_tool/package_confg.json', + 'pattern': '.', + 'action': ['python3', 'sdk/tools/generate_package_config.py'], + }, { # Pull Debian sysroot for i386 Linux 'name': 'sysroot_i386', diff --git a/tools/generate_package_config.py b/tools/generate_package_config.py new file mode 100644 index 00000000000..b763b3d714c --- /dev/null +++ b/tools/generate_package_config.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# Copyright (c) 2022, 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. + +# Invoke the `tools/generate_package_config.dart` script. + +import os +import os.path +import platform +import subprocess +import sys + +USE_PYTHON3 = True + + +def is_windows(): + os_id = platform.system() + return os_id == 'Windows' + + +def checked_in_sdk_path(): + tools_dir = os.path.dirname(os.path.realpath(__file__)) + return os.path.join(tools_dir, 'sdks', 'dart-sdk') + + +def checked_in_sdk_executable(): + name = 'dart' + if is_windows(): + name = 'dart.exe' + return os.path.join(checked_in_sdk_path(), 'bin', name) + + +def generate_package_config(): + tools_dir = os.path.dirname(os.path.realpath(__file__)) + process = subprocess.run([ + checked_in_sdk_executable(), + os.path.join(tools_dir, 'generate_package_config.dart') + ]) + return process.returncode + + +def Main(): + sys.exit(generate_package_config()) + + +if __name__ == '__main__': + Main()