mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 14:32:24 +00:00
e9f7cab5ca
Change-Id: Ieec55a99e9020f8f3962654e07518726d9f66fc4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249540 Commit-Queue: Devon Carew <devoncarew@google.com> Reviewed-by: Alexander Thomas <athom@google.com>
125 lines
3.9 KiB
Dart
125 lines
3.9 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.
|
|
//
|
|
// Current version: ${currentVersion.join('.')}
|
|
|
|
#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.
|
|
//
|
|
// Current version: ${currentVersion.join('.')}
|
|
|
|
#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;
|
|
}
|