1
0
mirror of https://github.com/dart-lang/sdk synced 2024-07-01 07:14:29 +00:00
dart-sdk/tools/generate_experimental_flags.dart
Jonas Termansen e743910b18 Reland "Bump version to 3.3."
Please prefer not to revert this change. Any tests that fail are release
blockers and need to be approved and urgently fixed forward. Dart 3.2
has already been cut and the version number must be updated. It is
acceptable for rolls to be blocked until the release blockers have been
resolved as P0 issues.

Remove needless version number comment from experimental_features to
remove duplicated information and simplify version updates.

Update dartdoc to a version that supports 3.3.

Change-Id: I1a19aa86e185c99e61374665f18cf24c498935a5
Tested: CQ
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329588
Commit-Queue: Slava Egorov <vegorov@google.com>
Auto-Submit: Jonas Termansen <sortie@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2023-10-06 19:00:58 +00:00

122 lines
3.8 KiB
Dart

// Copyright (c) 2020, 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 'dart:io' show File, Platform;
import 'package:yaml/yaml.dart' show YamlMap, loadYaml;
void main() {
YamlMap yaml = loadYaml(File.fromUri(computeYamlFile()).readAsStringSync());
final currentVersion = getAsVersionNumber(yaml['current-version'])!;
final enumNames = StringBuffer();
final featureValues = StringBuffer();
final featureNames = StringBuffer();
YamlMap features = yaml['features'];
for (var entry in features.entries) {
final category = (entry.value as YamlMap)['category'];
if (category == null || category == "vm" || category == "language") {
final version = getAsVersionNumber((entry.value as YamlMap)['enabledIn']);
if (version != null) {
final value = isGreaterOrEqualVersion(currentVersion, version);
final name = entry.key.replaceAll('-', '_');
enumNames.write(' $name,\n');
featureValues.write(' $value,\n');
featureNames.write(' "${entry.key}",\n');
}
}
}
final h = '''
// Copyright (c) 2020, 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.
// NOTE: THIS FILE IS GENERATED. DO NOT EDIT.
//
// Instead modify 'tools/experimental_features.yaml' and run
// 'dart tools/generate_experimental_flags.dart' to update.
#ifndef RUNTIME_VM_EXPERIMENTAL_FEATURES_H_
#define RUNTIME_VM_EXPERIMENTAL_FEATURES_H_
namespace dart {
enum class ExperimentalFeature {
$enumNames};
bool GetExperimentalFeatureDefault(ExperimentalFeature feature);
const char* GetExperimentalFeatureName(ExperimentalFeature feature);
} // namespace dart
#endif // RUNTIME_VM_EXPERIMENTAL_FEATURES_H_
''';
final cc = '''
// Copyright (c) 2020, 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.
// NOTE: THIS FILE IS GENERATED. DO NOT EDIT.
//
// Instead modify 'tools/experimental_features.yaml' and run
// 'dart tools/generate_experimental_flags.dart' to update.
#include "vm/experimental_features.h"
#include <cstring>
#include "platform/assert.h"
#include "vm/globals.h"
namespace dart {
bool GetExperimentalFeatureDefault(ExperimentalFeature feature) {
constexpr bool kFeatureValues[] = {
$featureValues };
ASSERT(static_cast<size_t>(feature) < ARRAY_SIZE(kFeatureValues));
return kFeatureValues[static_cast<int>(feature)];
}
const char* GetExperimentalFeatureName(ExperimentalFeature feature) {
constexpr const char* kFeatureNames[] = {
$featureNames };
ASSERT(static_cast<size_t>(feature) < ARRAY_SIZE(kFeatureNames));
return kFeatureNames[static_cast<int>(feature)];
}
} // namespace dart
''';
File.fromUri(computeHFile()).writeAsStringSync(h);
File.fromUri(computeCcFile()).writeAsStringSync(cc);
}
Uri computeYamlFile() {
return Platform.script.resolve("experimental_features.yaml");
}
Uri computeCcFile() {
return Platform.script.resolve("../runtime/vm/experimental_features.cc");
}
Uri computeHFile() {
return Platform.script.resolve("../runtime/vm/experimental_features.h");
}
List<num>? getAsVersionNumber(dynamic value) {
if (value == null) return null;
final version = List.of("$value".split(".").map(int.parse));
while (version.length < 3) {
version.add(0);
}
return version;
}
bool isGreaterOrEqualVersion(List<num> left, List<num> right) {
assert(left.length == right.length);
for (var i = 0; i < left.length; ++i) {
if (left[i] != right[i]) return left[i] > right[i];
}
return true;
}