Revert "[SDK] Adds an SDK hash to kernels and the VM."
This reverts commit edde575dcd.
Reason for revert: Breaks the Dart to Flutter roll and golem
Original change's description:
> [SDK] Adds an SDK hash to kernels and the VM.
>
> Adds a new SDK hash to kernels and the VM which is optionally checked
> to verify kernels are built for the same SDK as the VM.
> This helps catch incompatibilities that are currently causing
> subtle bugs and (not so subtle) crashes.
>
> The SDK hash is encoded in kernels as a new field in components.
> The hash is derived from the 10 byte git short hash.
>
> This new check can be disabled via:
> tools/gn.py ... --no-verify-sdk-hash
>
> This CL bumps the min. (and max.) supported kernel format version,
> making the VM backwards incompatible from this point back.
>
> Bug: https://github.com/dart-lang/sdk/issues/41802
> Change-Id: I3cbb2d481239ee64dafdaa0e4aac36c80281931b
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150343
> Commit-Queue: Clement Skau <cskau@google.com>
> Reviewed-by: Jens Johansen <jensj@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>
TBR=kustermann@google.com,jensj@google.com,cskau@google.com
Change-Id: I34cc7d378e2babdaaca4d932d19c19d0f35422fc
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/41802
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152703
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
a558d576b7
commit
bb8d145616
@@ -512,7 +512,7 @@ deps = {
|
|||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"package": "dart/cfe/dart2js_dills",
|
"package": "dart/cfe/dart2js_dills",
|
||||||
"version": "binary_version:43_2",
|
"version": "binary_version:42",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"dep_type": "cipd",
|
"dep_type": "cipd",
|
||||||
|
|||||||
@@ -473,33 +473,31 @@ class BinaryMdDillReader {
|
|||||||
type = type.substring(0, type.indexOf("["));
|
type = type.substring(0, type.indexOf("["));
|
||||||
type = _lookupGenericType(typeNames, type, types);
|
type = _lookupGenericType(typeNames, type, types);
|
||||||
|
|
||||||
int intCount = int.tryParse(count) ?? -1;
|
int intCount = -1;
|
||||||
if (intCount == -1) {
|
if (vars[count] != null && vars[count] is int) {
|
||||||
if (vars[count] != null && vars[count] is int) {
|
intCount = vars[count];
|
||||||
intCount = vars[count];
|
} else if (count.contains(".")) {
|
||||||
} else if (count.contains(".")) {
|
List<String> countData =
|
||||||
List<String> countData =
|
count.split(regExpSplit).map((s) => s.trim()).toList();
|
||||||
count.split(regExpSplit).map((s) => s.trim()).toList();
|
if (vars[countData[0]] != null) {
|
||||||
if (vars[countData[0]] != null) {
|
dynamic v = vars[countData[0]];
|
||||||
dynamic v = vars[countData[0]];
|
if (v is Map &&
|
||||||
if (v is Map &&
|
countData[1] == "last" &&
|
||||||
countData[1] == "last" &&
|
v["items"] is List &&
|
||||||
v["items"] is List &&
|
v["items"].last is int) {
|
||||||
v["items"].last is int) {
|
intCount = v["items"].last;
|
||||||
intCount = v["items"].last;
|
} else if (v is Map && v[countData[1]] != null) {
|
||||||
} else if (v is Map && v[countData[1]] != null) {
|
v = v[countData[1]];
|
||||||
v = v[countData[1]];
|
if (v is Map && v[countData[2]] != null) {
|
||||||
if (v is Map && v[countData[2]] != null) {
|
v = v[countData[2]];
|
||||||
v = v[countData[2]];
|
if (v is int) intCount = v;
|
||||||
if (v is int) intCount = v;
|
} else if (v is int &&
|
||||||
} else if (v is int &&
|
countData.length == 4 &&
|
||||||
countData.length == 4 &&
|
countData[2] == "+") {
|
||||||
countData[2] == "+") {
|
intCount = v + int.parse(countData[3]);
|
||||||
intCount = v + int.parse(countData[3]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw "Unknown dot to int ($count)";
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw "Unknown dot to int ($count)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -313,7 +313,6 @@ disallow
|
|||||||
disambiguator
|
disambiguator
|
||||||
disjoint
|
disjoint
|
||||||
dispatched
|
dispatched
|
||||||
distribute
|
|
||||||
divided
|
divided
|
||||||
dmitryas
|
dmitryas
|
||||||
doc
|
doc
|
||||||
@@ -326,7 +325,6 @@ downloaded
|
|||||||
downloading
|
downloading
|
||||||
dq
|
dq
|
||||||
dquote
|
dquote
|
||||||
dsdk
|
|
||||||
dst
|
dst
|
||||||
dummy
|
dummy
|
||||||
dupdate
|
dupdate
|
||||||
@@ -437,14 +435,12 @@ futured
|
|||||||
futureor
|
futureor
|
||||||
g
|
g
|
||||||
gardening
|
gardening
|
||||||
gen
|
|
||||||
generation
|
generation
|
||||||
gets
|
gets
|
||||||
getter1a
|
getter1a
|
||||||
getter1b
|
getter1b
|
||||||
getting
|
getting
|
||||||
gft
|
gft
|
||||||
git
|
|
||||||
github
|
github
|
||||||
glb
|
glb
|
||||||
glob
|
glob
|
||||||
|
|||||||
@@ -143,8 +143,7 @@ type CanonicalName {
|
|||||||
|
|
||||||
type ComponentFile {
|
type ComponentFile {
|
||||||
UInt32 magic = 0x90ABCDEF;
|
UInt32 magic = 0x90ABCDEF;
|
||||||
UInt32 formatVersion = 43;
|
UInt32 formatVersion = 42;
|
||||||
Byte[10] shortSdkHash;
|
|
||||||
List<String> problemsAsJson; // Described in problems.md.
|
List<String> problemsAsJson; // Described in problems.md.
|
||||||
Library[] libraries;
|
Library[] libraries;
|
||||||
UriSource sourceMap;
|
UriSource sourceMap;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ library kernel.ast_from_binary;
|
|||||||
|
|
||||||
import 'dart:core' hide MapEntry;
|
import 'dart:core' hide MapEntry;
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import '../ast.dart';
|
import '../ast.dart';
|
||||||
@@ -29,22 +28,11 @@ class InvalidKernelVersionError {
|
|||||||
InvalidKernelVersionError(this.version);
|
InvalidKernelVersionError(this.version);
|
||||||
|
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Unexpected Kernel Format Version ${version} '
|
return 'Unexpected Kernel version ${version} '
|
||||||
'(expected ${Tag.BinaryFormatVersion}).';
|
'(expected ${Tag.BinaryFormatVersion}).';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class InvalidKernelSdkVersionError {
|
|
||||||
final String version;
|
|
||||||
|
|
||||||
InvalidKernelSdkVersionError(this.version);
|
|
||||||
|
|
||||||
String toString() {
|
|
||||||
return 'Unexpected Kernel SDK Version ${version} '
|
|
||||||
'(expected ${expectedSdkHash}).';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CompilationModeError {
|
class CompilationModeError {
|
||||||
final String message;
|
final String message;
|
||||||
|
|
||||||
@@ -496,13 +484,6 @@ class BinaryBuilder {
|
|||||||
if (_bytes.length == 0) throw new StateError("Empty input given.");
|
if (_bytes.length == 0) throw new StateError("Empty input given.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void _readAndVerifySdkHash() {
|
|
||||||
final sdkHash = ascii.decode(readBytes(sdkHashLength));
|
|
||||||
if (!isValidSdkHash(sdkHash)) {
|
|
||||||
throw InvalidKernelSdkVersionError(sdkHash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deserializes a kernel component and stores it in [component].
|
/// Deserializes a kernel component and stores it in [component].
|
||||||
///
|
///
|
||||||
/// When linking with a non-empty component, canonical names must have been
|
/// When linking with a non-empty component, canonical names must have been
|
||||||
@@ -530,9 +511,6 @@ class BinaryBuilder {
|
|||||||
if (version != Tag.BinaryFormatVersion) {
|
if (version != Tag.BinaryFormatVersion) {
|
||||||
throw InvalidKernelVersionError(version);
|
throw InvalidKernelVersionError(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
_readAndVerifySdkHash();
|
|
||||||
|
|
||||||
_byteOffset = offset;
|
_byteOffset = offset;
|
||||||
List<int> componentFileSizes = _indexComponents();
|
List<int> componentFileSizes = _indexComponents();
|
||||||
if (componentFileSizes.length > 1) {
|
if (componentFileSizes.length > 1) {
|
||||||
@@ -716,8 +694,6 @@ class BinaryBuilder {
|
|||||||
throw InvalidKernelVersionError(formatVersion);
|
throw InvalidKernelVersionError(formatVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
_readAndVerifySdkHash();
|
|
||||||
|
|
||||||
// Read component index from the end of this ComponentFiles serialized data.
|
// Read component index from the end of this ComponentFiles serialized data.
|
||||||
_ComponentIndex index = _readComponentIndex(componentFileSize);
|
_ComponentIndex index = _readComponentIndex(componentFileSize);
|
||||||
|
|
||||||
@@ -742,8 +718,6 @@ class BinaryBuilder {
|
|||||||
throw InvalidKernelVersionError(formatVersion);
|
throw InvalidKernelVersionError(formatVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
_readAndVerifySdkHash();
|
|
||||||
|
|
||||||
List<String> problemsAsJson = readListOfStrings();
|
List<String> problemsAsJson = readListOfStrings();
|
||||||
if (problemsAsJson != null) {
|
if (problemsAsJson != null) {
|
||||||
component.problemsAsJson ??= <String>[];
|
component.problemsAsJson ??= <String>[];
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
library kernel.ast_to_binary;
|
library kernel.ast_to_binary;
|
||||||
|
|
||||||
import 'dart:core' hide MapEntry;
|
import 'dart:core' hide MapEntry;
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
import 'dart:io' show BytesBuilder;
|
import 'dart:io' show BytesBuilder;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
@@ -538,7 +537,6 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
|
|||||||
final componentOffset = getBufferOffset();
|
final componentOffset = getBufferOffset();
|
||||||
writeUInt32(Tag.ComponentFile);
|
writeUInt32(Tag.ComponentFile);
|
||||||
writeUInt32(Tag.BinaryFormatVersion);
|
writeUInt32(Tag.BinaryFormatVersion);
|
||||||
writeBytes(ascii.encode(expectedSdkHash));
|
|
||||||
writeListOfStrings(component.problemsAsJson);
|
writeListOfStrings(component.problemsAsJson);
|
||||||
indexLinkTable(component);
|
indexLinkTable(component);
|
||||||
_collectMetadata(component);
|
_collectMetadata(component);
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ class Tag {
|
|||||||
/// Internal version of kernel binary format.
|
/// Internal version of kernel binary format.
|
||||||
/// Bump it when making incompatible changes in kernel binaries.
|
/// Bump it when making incompatible changes in kernel binaries.
|
||||||
/// Keep in sync with runtime/vm/kernel_binary.h, pkg/kernel/binary.md.
|
/// Keep in sync with runtime/vm/kernel_binary.h, pkg/kernel/binary.md.
|
||||||
static const int BinaryFormatVersion = 43;
|
static const int BinaryFormatVersion = 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ConstantTag {
|
abstract class ConstantTag {
|
||||||
@@ -169,27 +169,3 @@ abstract class ConstantTag {
|
|||||||
static const int UnevaluatedConstant = 12;
|
static const int UnevaluatedConstant = 12;
|
||||||
// 13 is occupied by [SetConstant]
|
// 13 is occupied by [SetConstant]
|
||||||
}
|
}
|
||||||
|
|
||||||
const int sdkHashLength = 10; // Bytes, a Git "short hash".
|
|
||||||
|
|
||||||
const String sdkHashNull = '0000000000';
|
|
||||||
|
|
||||||
// Will be correct hash for Flutter SDK / Dart SDK we distribute.
|
|
||||||
// If non-null we will validate when consuming kernel, will use when producing
|
|
||||||
// kernel.
|
|
||||||
// If null, local development setting (e.g. run gen_kernel.dart from source),
|
|
||||||
// we put 0x00..00 into when producing, do not validate when consuming.
|
|
||||||
String get expectedSdkHash {
|
|
||||||
final sdkHash =
|
|
||||||
const String.fromEnvironment('sdk_hash', defaultValue: sdkHashNull);
|
|
||||||
if (sdkHash.length != 10) {
|
|
||||||
throw '-Dsdk_hash=<hash> must be a 10 byte string!';
|
|
||||||
}
|
|
||||||
return sdkHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isValidSdkHash(String sdkHash) {
|
|
||||||
return (sdkHash == sdkHashNull ||
|
|
||||||
expectedSdkHash == sdkHashNull ||
|
|
||||||
sdkHash == expectedSdkHash);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -964,11 +964,9 @@ prebuilt_dart_action("gen_kernel_bytecode_dill") {
|
|||||||
|
|
||||||
abs_depfile = rebase_path(depfile)
|
abs_depfile = rebase_path(depfile)
|
||||||
rebased_output = rebase_path(output, root_build_dir)
|
rebased_output = rebase_path(output, root_build_dir)
|
||||||
|
|
||||||
vm_args = [
|
vm_args = [
|
||||||
"--depfile=$abs_depfile",
|
"--depfile=$abs_depfile",
|
||||||
"--depfile_output_filename=$rebased_output",
|
"--depfile_output_filename=$rebased_output",
|
||||||
"-Dsdk_hash=$sdk_hash",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
// 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:async';
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:path/path.dart' as path;
|
|
||||||
import 'package:expect/expect.dart';
|
|
||||||
|
|
||||||
import 'snapshot_test_helper.dart';
|
|
||||||
|
|
||||||
// Keep in sync with pkg/kernel/lib/binary/tag.dart:
|
|
||||||
const tagComponentFile = [0x90, 0xAB, 0xCD, 0xEF];
|
|
||||||
const tagBinaryFormatVersion = [0x00, 0x00, 0x00, 43];
|
|
||||||
|
|
||||||
Future<void> main(List<String> args) async {
|
|
||||||
if (args.length == 1 && args[0] == '--child') {
|
|
||||||
print('Hello, SDK Hash!');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String sourcePath =
|
|
||||||
path.join('runtime', 'tests', 'vm', 'dart_2', 'sdk_hash_test.dart');
|
|
||||||
|
|
||||||
await withTempDir((String tmp) async {
|
|
||||||
final String dillPath = path.join(tmp, 'test.dill');
|
|
||||||
|
|
||||||
{
|
|
||||||
final result = await Process.run(dart, [
|
|
||||||
genKernel,
|
|
||||||
'--platform',
|
|
||||||
platformDill,
|
|
||||||
'-o',
|
|
||||||
dillPath,
|
|
||||||
sourcePath,
|
|
||||||
]);
|
|
||||||
Expect.equals('', result.stderr);
|
|
||||||
Expect.equals(0, result.exitCode);
|
|
||||||
Expect.equals('', result.stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
final result = await Process.run(dart, [dillPath, '--child']);
|
|
||||||
Expect.equals('', result.stderr);
|
|
||||||
Expect.equals(0, result.exitCode);
|
|
||||||
Expect.equals('Hello, SDK Hash!', result.stdout.trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invalidate the SDK hash in the kernel dill:
|
|
||||||
{
|
|
||||||
final myFile = File(dillPath);
|
|
||||||
Uint8List bytes = myFile.readAsBytesSync();
|
|
||||||
// The SDK Hash is located after the ComponentFile and BinaryFormatVersion
|
|
||||||
// tags (both UInt32).
|
|
||||||
Expect.listEquals(tagComponentFile, bytes.sublist(0, 4));
|
|
||||||
Expect.listEquals(tagBinaryFormatVersion, bytes.sublist(4, 8));
|
|
||||||
// Flip the first byte in the hash:
|
|
||||||
bytes[8] ^= bytes[8];
|
|
||||||
myFile.writeAsBytesSync(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
final result = await Process.run(dart, [dillPath, '--child']);
|
|
||||||
Expect.equals(
|
|
||||||
'Can\'t load Kernel binary: Invalid SDK hash.', result.stderr.trim());
|
|
||||||
Expect.equals(253, result.exitCode);
|
|
||||||
Expect.equals('', result.stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Zero out the SDK hash in the kernel dill to disable the check:
|
|
||||||
{
|
|
||||||
final myFile = File(dillPath);
|
|
||||||
Uint8List bytes = myFile.readAsBytesSync();
|
|
||||||
bytes.setRange(8, 18, ascii.encode('0000000000'));
|
|
||||||
myFile.writeAsBytesSync(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
final result = await Process.run(dart, [dillPath, '--child']);
|
|
||||||
Expect.equals('', result.stderr);
|
|
||||||
Expect.equals(0, result.exitCode);
|
|
||||||
Expect.equals('Hello, SDK Hash!', result.stdout.trim());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -48,7 +48,6 @@ final String executableSuffix = Platform.isWindows ? ".exe" : "";
|
|||||||
final String buildDir = p.dirname(Platform.executable);
|
final String buildDir = p.dirname(Platform.executable);
|
||||||
final String platformDill = p.join(buildDir, "vm_platform_strong.dill");
|
final String platformDill = p.join(buildDir, "vm_platform_strong.dill");
|
||||||
final String genSnapshot = p.join(buildDir, "gen_snapshot${executableSuffix}");
|
final String genSnapshot = p.join(buildDir, "gen_snapshot${executableSuffix}");
|
||||||
final String dart = p.join(buildDir, "dart${executableSuffix}");
|
|
||||||
final String dartPrecompiledRuntime =
|
final String dartPrecompiledRuntime =
|
||||||
p.join(buildDir, "dart_precompiled_runtime${executableSuffix}");
|
p.join(buildDir, "dart_precompiled_runtime${executableSuffix}");
|
||||||
final String genKernel = p.join("pkg", "vm", "bin", "gen_kernel.dart");
|
final String genKernel = p.join("pkg", "vm", "bin", "gen_kernel.dart");
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
// 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:async';
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:path/path.dart' as path;
|
|
||||||
import 'package:expect/expect.dart';
|
|
||||||
|
|
||||||
import 'snapshot_test_helper.dart';
|
|
||||||
|
|
||||||
// Keep in sync with pkg/kernel/lib/binary/tag.dart:
|
|
||||||
const tagComponentFile = [0x90, 0xAB, 0xCD, 0xEF];
|
|
||||||
const tagBinaryFormatVersion = [0x00, 0x00, 0x00, 43];
|
|
||||||
|
|
||||||
Future<void> main(List<String> args) async {
|
|
||||||
if (args.length == 1 && args[0] == '--child') {
|
|
||||||
print('Hello, SDK Hash!');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String sourcePath =
|
|
||||||
path.join('runtime', 'tests', 'vm', 'dart_2', 'sdk_hash_test.dart');
|
|
||||||
|
|
||||||
await withTempDir((String tmp) async {
|
|
||||||
final String dillPath = path.join(tmp, 'test.dill');
|
|
||||||
|
|
||||||
{
|
|
||||||
final result = await Process.run(dart, [
|
|
||||||
genKernel,
|
|
||||||
'--platform',
|
|
||||||
platformDill,
|
|
||||||
'-o',
|
|
||||||
dillPath,
|
|
||||||
sourcePath,
|
|
||||||
]);
|
|
||||||
Expect.equals('', result.stderr);
|
|
||||||
Expect.equals(0, result.exitCode);
|
|
||||||
Expect.equals('', result.stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
final result = await Process.run(dart, [dillPath, '--child']);
|
|
||||||
Expect.equals('', result.stderr);
|
|
||||||
Expect.equals(0, result.exitCode);
|
|
||||||
Expect.equals('Hello, SDK Hash!', result.stdout.trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invalidate the SDK hash in the kernel dill:
|
|
||||||
{
|
|
||||||
final myFile = File(dillPath);
|
|
||||||
Uint8List bytes = myFile.readAsBytesSync();
|
|
||||||
// The SDK Hash is located after the ComponentFile and BinaryFormatVersion
|
|
||||||
// tags (both UInt32).
|
|
||||||
Expect.listEquals(tagComponentFile, bytes.sublist(0, 4));
|
|
||||||
Expect.listEquals(tagBinaryFormatVersion, bytes.sublist(4, 8));
|
|
||||||
// Flip the first byte in the hash:
|
|
||||||
bytes[8] ^= bytes[8];
|
|
||||||
myFile.writeAsBytesSync(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
final result = await Process.run(dart, [dillPath, '--child']);
|
|
||||||
Expect.equals(
|
|
||||||
'Can\'t load Kernel binary: Invalid SDK hash.', result.stderr.trim());
|
|
||||||
Expect.equals(253, result.exitCode);
|
|
||||||
Expect.equals('', result.stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Zero out the SDK hash in the kernel dill to disable the check:
|
|
||||||
{
|
|
||||||
final myFile = File(dillPath);
|
|
||||||
Uint8List bytes = myFile.readAsBytesSync();
|
|
||||||
bytes.setRange(8, 18, ascii.encode('0000000000'));
|
|
||||||
myFile.writeAsBytesSync(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
final result = await Process.run(dart, [dillPath, '--child']);
|
|
||||||
Expect.equals('', result.stderr);
|
|
||||||
Expect.equals(0, result.exitCode);
|
|
||||||
Expect.equals('Hello, SDK Hash!', result.stdout.trim());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -48,7 +48,6 @@ final String executableSuffix = Platform.isWindows ? ".exe" : "";
|
|||||||
final String buildDir = p.dirname(Platform.executable);
|
final String buildDir = p.dirname(Platform.executable);
|
||||||
final String platformDill = p.join(buildDir, "vm_platform_strong.dill");
|
final String platformDill = p.join(buildDir, "vm_platform_strong.dill");
|
||||||
final String genSnapshot = p.join(buildDir, "gen_snapshot${executableSuffix}");
|
final String genSnapshot = p.join(buildDir, "gen_snapshot${executableSuffix}");
|
||||||
final String dart = p.join(buildDir, "dart${executableSuffix}");
|
|
||||||
final String dartPrecompiledRuntime =
|
final String dartPrecompiledRuntime =
|
||||||
p.join(buildDir, "dart_precompiled_runtime${executableSuffix}");
|
p.join(buildDir, "dart_precompiled_runtime${executableSuffix}");
|
||||||
final String genKernel = p.join("pkg", "vm", "bin", "gen_kernel.dart");
|
final String genKernel = p.join("pkg", "vm", "bin", "gen_kernel.dart");
|
||||||
|
|||||||
@@ -2654,7 +2654,18 @@ TokenPosition KernelReaderHelper::ReadPosition() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
intptr_t KernelReaderHelper::SourceTableFieldCountFromFirstLibraryOffset() {
|
intptr_t KernelReaderHelper::SourceTableFieldCountFromFirstLibraryOffset() {
|
||||||
return SourceTableFieldCountFromFirstLibraryOffset41Plus;
|
// translation_helper_.info() might not be initialized at this point so we
|
||||||
|
// can't use translation_helper_.info().kernel_binary_version().
|
||||||
|
SetOffset(KernelFormatVersionOffset);
|
||||||
|
uint32_t formatVersion = reader_.ReadUInt32();
|
||||||
|
intptr_t count_from_first_library_offset =
|
||||||
|
SourceTableFieldCountFromFirstLibraryOffsetPre41;
|
||||||
|
static_assert(kMinSupportedKernelFormatVersion < 41, "cleanup this code");
|
||||||
|
if (formatVersion >= 41) {
|
||||||
|
count_from_first_library_offset =
|
||||||
|
SourceTableFieldCountFromFirstLibraryOffset41Plus;
|
||||||
|
}
|
||||||
|
return count_from_first_library_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
intptr_t KernelReaderHelper::SourceTableSize() {
|
intptr_t KernelReaderHelper::SourceTableSize() {
|
||||||
|
|||||||
+16
-22
@@ -15,7 +15,6 @@
|
|||||||
#include "vm/kernel.h"
|
#include "vm/kernel.h"
|
||||||
#include "vm/object.h"
|
#include "vm/object.h"
|
||||||
#include "vm/os.h"
|
#include "vm/os.h"
|
||||||
#include "vm/version.h"
|
|
||||||
|
|
||||||
namespace dart {
|
namespace dart {
|
||||||
|
|
||||||
@@ -85,14 +84,12 @@ const char* kKernelInvalidBinaryFormatVersion =
|
|||||||
"Invalid kernel binary format version";
|
"Invalid kernel binary format version";
|
||||||
const char* kKernelInvalidSizeIndicated =
|
const char* kKernelInvalidSizeIndicated =
|
||||||
"Invalid kernel binary: Indicated size is invalid";
|
"Invalid kernel binary: Indicated size is invalid";
|
||||||
const char* kKernelInvalidSdkHash = "Invalid SDK hash";
|
|
||||||
|
|
||||||
std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
|
std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
|
||||||
if (reader->size() < 70) {
|
if (reader->size() < 60) {
|
||||||
// A kernel file (v43) currently contains at least the following:
|
// A kernel file (v41) currently contains at least the following:
|
||||||
// * Magic number (32)
|
// * Magic number (32)
|
||||||
// * Kernel version (32)
|
// * Kernel version (32)
|
||||||
// * SDK Hash (10 * 8)
|
|
||||||
// * List of problems (8)
|
// * List of problems (8)
|
||||||
// * Length of source map (32)
|
// * Length of source map (32)
|
||||||
// * Length of canonical name table (8)
|
// * Length of canonical name table (8)
|
||||||
@@ -101,7 +98,7 @@ std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
|
|||||||
// * Length of constant table (8)
|
// * Length of constant table (8)
|
||||||
// * Component index (11 * 32)
|
// * Component index (11 * 32)
|
||||||
//
|
//
|
||||||
// so is at least 74 bytes.
|
// so is at least 64 bytes.
|
||||||
// (Technically it will also contain an empty entry in both source map and
|
// (Technically it will also contain an empty entry in both source map and
|
||||||
// string table, taking up another 8 bytes.)
|
// string table, taking up another 8 bytes.)
|
||||||
if (error != nullptr) {
|
if (error != nullptr) {
|
||||||
@@ -127,18 +124,6 @@ std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t sdkHash[11];
|
|
||||||
reader->ReadBytes(sdkHash, 10);
|
|
||||||
sdkHash[10] = 0; // Null terminate.
|
|
||||||
if (strcmp(Version::SdkHash(), "0000000000") != 0 &&
|
|
||||||
strcmp((const char*)sdkHash, "0000000000") != 0 &&
|
|
||||||
strcmp((const char*)sdkHash, Version::SdkHash()) != 0) {
|
|
||||||
if (error != nullptr) {
|
|
||||||
*error = kKernelInvalidSdkHash;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<Program> program(new Program());
|
std::unique_ptr<Program> program(new Program());
|
||||||
program->binary_version_ = formatVersion;
|
program->binary_version_ = formatVersion;
|
||||||
program->typed_data_ = reader->typed_data();
|
program->typed_data_ = reader->typed_data();
|
||||||
@@ -167,8 +152,13 @@ std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
|
|||||||
// Read backwards at the end.
|
// Read backwards at the end.
|
||||||
program->library_count_ = reader->ReadFromIndexNoReset(
|
program->library_count_ = reader->ReadFromIndexNoReset(
|
||||||
reader->size_, LibraryCountFieldCountFromEnd, 1, 0);
|
reader->size_, LibraryCountFieldCountFromEnd, 1, 0);
|
||||||
|
static_assert(kMinSupportedKernelFormatVersion < 41, "cleanup this code");
|
||||||
intptr_t count_from_first_library_offset =
|
intptr_t count_from_first_library_offset =
|
||||||
SourceTableFieldCountFromFirstLibraryOffset41Plus;
|
SourceTableFieldCountFromFirstLibraryOffsetPre41;
|
||||||
|
if (formatVersion >= 41) {
|
||||||
|
count_from_first_library_offset =
|
||||||
|
SourceTableFieldCountFromFirstLibraryOffset41Plus;
|
||||||
|
}
|
||||||
program->source_table_offset_ = reader->ReadFromIndexNoReset(
|
program->source_table_offset_ = reader->ReadFromIndexNoReset(
|
||||||
reader->size_,
|
reader->size_,
|
||||||
LibraryCountFieldCountFromEnd + 1 + program->library_count_ + 1 +
|
LibraryCountFieldCountFromEnd + 1 + program->library_count_ + 1 +
|
||||||
@@ -181,9 +171,13 @@ std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
|
|||||||
program->constant_table_offset_ = reader->ReadUInt32();
|
program->constant_table_offset_ = reader->ReadUInt32();
|
||||||
|
|
||||||
program->main_method_reference_ = NameIndex(reader->ReadUInt32() - 1);
|
program->main_method_reference_ = NameIndex(reader->ReadUInt32() - 1);
|
||||||
NNBDCompiledMode compilation_mode =
|
if (formatVersion >= 41) {
|
||||||
static_cast<NNBDCompiledMode>(reader->ReadUInt32());
|
NNBDCompiledMode compilation_mode =
|
||||||
program->compilation_mode_ = compilation_mode;
|
static_cast<NNBDCompiledMode>(reader->ReadUInt32());
|
||||||
|
program->compilation_mode_ = compilation_mode;
|
||||||
|
} else {
|
||||||
|
program->compilation_mode_ = NNBDCompiledMode::kDisabled;
|
||||||
|
}
|
||||||
|
|
||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ namespace kernel {
|
|||||||
static const uint32_t kMagicProgramFile = 0x90ABCDEFu;
|
static const uint32_t kMagicProgramFile = 0x90ABCDEFu;
|
||||||
|
|
||||||
// Both version numbers are inclusive.
|
// Both version numbers are inclusive.
|
||||||
static const uint32_t kMinSupportedKernelFormatVersion = 43;
|
static const uint32_t kMinSupportedKernelFormatVersion = 29;
|
||||||
static const uint32_t kMaxSupportedKernelFormatVersion = 43;
|
static const uint32_t kMaxSupportedKernelFormatVersion = 42;
|
||||||
|
|
||||||
// Keep in sync with package:kernel/lib/binary/tag.dart
|
// Keep in sync with package:kernel/lib/binary/tag.dart
|
||||||
#define KERNEL_TAG_LIST(V) \
|
#define KERNEL_TAG_LIST(V) \
|
||||||
@@ -326,12 +326,6 @@ class Reader : public ValueObject {
|
|||||||
|
|
||||||
uint8_t PeekByte() { return buffer()[offset_]; }
|
uint8_t PeekByte() { return buffer()[offset_]; }
|
||||||
|
|
||||||
void ReadBytes(uint8_t* buffer, uint8_t size) {
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
buffer[i] = ReadByte();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ReadBool() { return (ReadByte() & 1) == 1; }
|
bool ReadBool() { return (ReadByte() & 1) == 1; }
|
||||||
|
|
||||||
uint8_t ReadFlags() { return ReadByte(); }
|
uint8_t ReadFlags() { return ReadByte(); }
|
||||||
|
|||||||
@@ -297,11 +297,7 @@ Object& KernelLoader::LoadEntireProgram(Program* program,
|
|||||||
reader.set_raw_buffer(program->kernel_data() + subprogram_start);
|
reader.set_raw_buffer(program->kernel_data() + subprogram_start);
|
||||||
reader.set_size(subprogram_end - subprogram_start);
|
reader.set_size(subprogram_end - subprogram_start);
|
||||||
reader.set_offset(0);
|
reader.set_offset(0);
|
||||||
const char* error = nullptr;
|
std::unique_ptr<Program> subprogram = Program::ReadFrom(&reader);
|
||||||
std::unique_ptr<Program> subprogram = Program::ReadFrom(&reader, &error);
|
|
||||||
if (subprogram == nullptr) {
|
|
||||||
FATAL1("Failed to load kernel file: %s", error);
|
|
||||||
}
|
|
||||||
ASSERT(subprogram->is_single_program());
|
ASSERT(subprogram->is_single_program());
|
||||||
KernelLoader loader(subprogram.get(), &uri_to_source_table);
|
KernelLoader loader(subprogram.get(), &uri_to_source_table);
|
||||||
Object& load_result = Object::Handle(loader.LoadProgram(false));
|
Object& load_result = Object::Handle(loader.LoadProgram(false));
|
||||||
@@ -853,8 +849,7 @@ void KernelLoader::FindModifiedLibraries(Program* program,
|
|||||||
intptr_t* p_num_classes,
|
intptr_t* p_num_classes,
|
||||||
intptr_t* p_num_procedures) {
|
intptr_t* p_num_procedures) {
|
||||||
LongJumpScope jump;
|
LongJumpScope jump;
|
||||||
Thread* thread = Thread::Current();
|
Zone* zone = Thread::Current()->zone();
|
||||||
Zone* zone = thread->zone();
|
|
||||||
if (setjmp(*jump.Set()) == 0) {
|
if (setjmp(*jump.Set()) == 0) {
|
||||||
if (force_reload) {
|
if (force_reload) {
|
||||||
// If a reload is being forced we mark all libraries as having
|
// If a reload is being forced we mark all libraries as having
|
||||||
@@ -899,11 +894,7 @@ void KernelLoader::FindModifiedLibraries(Program* program,
|
|||||||
reader.set_raw_buffer(program->kernel_data() + subprogram_start);
|
reader.set_raw_buffer(program->kernel_data() + subprogram_start);
|
||||||
reader.set_size(subprogram_end - subprogram_start);
|
reader.set_size(subprogram_end - subprogram_start);
|
||||||
reader.set_offset(0);
|
reader.set_offset(0);
|
||||||
const char* error = nullptr;
|
std::unique_ptr<Program> subprogram = Program::ReadFrom(&reader);
|
||||||
std::unique_ptr<Program> subprogram = Program::ReadFrom(&reader, &error);
|
|
||||||
if (subprogram == nullptr) {
|
|
||||||
FATAL1("Failed to load kernel file: %s", error);
|
|
||||||
}
|
|
||||||
ASSERT(subprogram->is_single_program());
|
ASSERT(subprogram->is_single_program());
|
||||||
KernelLoader loader(subprogram.get(), /*uri_to_source_table=*/nullptr);
|
KernelLoader loader(subprogram.get(), /*uri_to_source_table=*/nullptr);
|
||||||
loader.walk_incremental_kernel(modified_libs, is_empty_program,
|
loader.walk_incremental_kernel(modified_libs, is_empty_program,
|
||||||
|
|||||||
@@ -16,13 +16,11 @@ class Version : public AllStatic {
|
|||||||
static const char* CommitString();
|
static const char* CommitString();
|
||||||
static int CurrentAbiVersion();
|
static int CurrentAbiVersion();
|
||||||
static int OldestSupportedAbiVersion();
|
static int OldestSupportedAbiVersion();
|
||||||
static const char* SdkHash();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const char* str_;
|
static const char* str_;
|
||||||
static const char* snapshot_hash_;
|
static const char* snapshot_hash_;
|
||||||
static const char* commit_;
|
static const char* commit_;
|
||||||
static const char* git_short_hash_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dart
|
} // namespace dart
|
||||||
|
|||||||
@@ -38,13 +38,8 @@ int Version::OldestSupportedAbiVersion() {
|
|||||||
return {{OLDEST_SUPPORTED_ABI_VERSION}};
|
return {{OLDEST_SUPPORTED_ABI_VERSION}};
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Version::SdkHash() {
|
|
||||||
return git_short_hash_;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* Version::snapshot_hash_ = "{{SNAPSHOT_HASH}}";
|
const char* Version::snapshot_hash_ = "{{SNAPSHOT_HASH}}";
|
||||||
const char* Version::str_ = "{{VERSION_STR}} ({{CHANNEL}}) ({{COMMIT_TIME}})";
|
const char* Version::str_ = "{{VERSION_STR}} ({{CHANNEL}}) ({{COMMIT_TIME}})";
|
||||||
const char* Version::commit_ = "{{VERSION_STR}}";
|
const char* Version::commit_ = "{{VERSION_STR}}";
|
||||||
const char* Version::git_short_hash_ = "{{GIT_HASH}}";
|
|
||||||
|
|
||||||
} // namespace dart
|
} // namespace dart
|
||||||
|
|||||||
@@ -19,22 +19,4 @@ declare_args() {
|
|||||||
# to out/ReleaseX64/args.gn. The path above can be extracted from the `.git`
|
# to out/ReleaseX64/args.gn. The path above can be extracted from the `.git`
|
||||||
# file under the git worktree folder.
|
# file under the git worktree folder.
|
||||||
default_git_folder = "$_dart_root/.git"
|
default_git_folder = "$_dart_root/.git"
|
||||||
|
|
||||||
# Whether to enable the SDK hash check that will prevent loading a kernel
|
|
||||||
# into a VM which was built with a different SDK.
|
|
||||||
verify_sdk_hash = true
|
|
||||||
}
|
|
||||||
|
|
||||||
# The SDK hash to build into VM and kernels.
|
|
||||||
# The value 0000000000 signifies no hash is set, which will disable the check.
|
|
||||||
if (verify_sdk_hash) {
|
|
||||||
sdk_hash = exec_script("$_dart_root/tools/make_version.py",
|
|
||||||
[ "--format={{GIT_HASH}}" ],
|
|
||||||
"trim string",
|
|
||||||
[
|
|
||||||
"$_dart_root/tools/VERSION",
|
|
||||||
"$_dart_root/tools/utils.py",
|
|
||||||
])
|
|
||||||
} else {
|
|
||||||
sdk_hash = "0000000000"
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-9
@@ -136,7 +136,7 @@ def UseSysroot(args, gn_args):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash):
|
def ToGnArgs(args, mode, arch, target_os, sanitizer):
|
||||||
gn_args = {}
|
gn_args = {}
|
||||||
|
|
||||||
host_os = HostOsForGn(HOST_OS)
|
host_os = HostOsForGn(HOST_OS)
|
||||||
@@ -258,8 +258,6 @@ def ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash):
|
|||||||
gn_args['dart_debug_optimization_level'] = args.debug_opt_level
|
gn_args['dart_debug_optimization_level'] = args.debug_opt_level
|
||||||
gn_args['debug_optimization_level'] = args.debug_opt_level
|
gn_args['debug_optimization_level'] = args.debug_opt_level
|
||||||
|
|
||||||
gn_args['verify_sdk_hash'] = verify_sdk_hash
|
|
||||||
|
|
||||||
return gn_args
|
return gn_args
|
||||||
|
|
||||||
|
|
||||||
@@ -468,10 +466,6 @@ def parse_args(args):
|
|||||||
default=False,
|
default=False,
|
||||||
dest='use_qemu',
|
dest='use_qemu',
|
||||||
action='store_true')
|
action='store_true')
|
||||||
other_group.add_argument('--no-verify-sdk-hash',
|
|
||||||
help='Disable SDK hash checks.',
|
|
||||||
default=False,
|
|
||||||
action='store_true')
|
|
||||||
|
|
||||||
options = parser.parse_args(args)
|
options = parser.parse_args(args)
|
||||||
if not ProcessOptions(options):
|
if not ProcessOptions(options):
|
||||||
@@ -512,8 +506,7 @@ def Main(argv):
|
|||||||
# See dartbug.com/32364
|
# See dartbug.com/32364
|
||||||
command = [gn, 'gen', out_dir]
|
command = [gn, 'gen', out_dir]
|
||||||
gn_args = ToCommandLine(
|
gn_args = ToCommandLine(
|
||||||
ToGnArgs(args, mode, arch, target_os, sanitizer,
|
ToGnArgs(args, mode, arch, target_os, sanitizer))
|
||||||
not args.no_verify_sdk_hash))
|
|
||||||
gn_args += GetGNArgs(args)
|
gn_args += GetGNArgs(args)
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print("gn gen --check in %s" % out_dir)
|
print("gn gen --check in %s" % out_dir)
|
||||||
|
|||||||
+110
-103
@@ -7,13 +7,19 @@
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
from optparse import OptionParser
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
|
|
||||||
|
def debugLog(message):
|
||||||
|
print(message, file=sys.stderr)
|
||||||
|
sys.stderr.flush()
|
||||||
|
|
||||||
|
|
||||||
# When these files change, snapshots created by the VM are potentially no longer
|
# When these files change, snapshots created by the VM are potentially no longer
|
||||||
# backwards-compatible.
|
# backwards-compatible.
|
||||||
VM_SNAPSHOT_FILES = [
|
VM_SNAPSHOT_FILES = [
|
||||||
@@ -39,141 +45,142 @@ VM_SNAPSHOT_FILES = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def MakeVersionString(quiet, no_git_hash, custom_for_pub=None):
|
||||||
|
channel = utils.GetChannel()
|
||||||
|
|
||||||
|
if custom_for_pub and channel == 'be':
|
||||||
|
latest = utils.GetLatestDevTag()
|
||||||
|
if not latest:
|
||||||
|
# If grabbing the dev tag fails, then fall back on the VERSION file.
|
||||||
|
latest = utils.GetSemanticSDKVersion(no_git_hash=True)
|
||||||
|
if no_git_hash:
|
||||||
|
version_string = ("%s.%s" % (latest, custom_for_pub))
|
||||||
|
else:
|
||||||
|
git_hash = utils.GetShortGitHash()
|
||||||
|
version_string = ("%s.%s-%s" % (latest, custom_for_pub, git_hash))
|
||||||
|
else:
|
||||||
|
version_string = utils.GetSemanticSDKVersion(no_git_hash=no_git_hash)
|
||||||
|
if not quiet:
|
||||||
|
debugLog("Returning version string: %s " % version_string)
|
||||||
|
return version_string
|
||||||
|
|
||||||
|
|
||||||
def MakeSnapshotHashString():
|
def MakeSnapshotHashString():
|
||||||
vmhash = hashlib.md5()
|
vmhash = hashlib.md5()
|
||||||
for vmfilename in VM_SNAPSHOT_FILES:
|
for vmfilename in VM_SNAPSHOT_FILES:
|
||||||
vmfilepath = os.path.join(utils.DART_DIR, 'runtime', 'vm', vmfilename)
|
vmfilepath = os.path.join(utils.DART_DIR, 'runtime', 'vm', vmfilename)
|
||||||
with open(vmfilepath, 'rb') as vmfile:
|
with open(vmfilepath) as vmfile:
|
||||||
vmhash.update(vmfile.read())
|
vmhash.update(vmfile.read().encode('utf-8'))
|
||||||
return vmhash.hexdigest()
|
return vmhash.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def GetSemanticVersionFormat(no_git_hash, custom_for_pub):
|
def MakeFile(quiet,
|
||||||
version_format = '{{SEMANTIC_SDK_VERSION}}'
|
output_file,
|
||||||
|
input_file,
|
||||||
if custom_for_pub and utils.GetChannel() == 'be':
|
no_git_hash,
|
||||||
if no_git_hash:
|
custom_for_pub,
|
||||||
version_format = '{{LATEST}}.{{PUB_CUSTOM}}'
|
version_file=None):
|
||||||
else:
|
if version_file:
|
||||||
version_format = '{{LATEST}}.{{PUB_CUSTOM}}-{{GIT_HASH}}'
|
version_string = utils.GetVersion(no_git_hash, version_file)
|
||||||
|
else:
|
||||||
return version_format
|
version_string = MakeVersionString(quiet, no_git_hash, custom_for_pub)
|
||||||
|
|
||||||
|
|
||||||
def FormatVersionString(version,
|
|
||||||
no_git_hash,
|
|
||||||
custom_for_pub,
|
|
||||||
version_file=None,
|
|
||||||
git_revision_file=None):
|
|
||||||
semantic_sdk_version = utils.GetSemanticSDKVersion(no_git_hash,
|
|
||||||
version_file,
|
|
||||||
git_revision_file)
|
|
||||||
semantic_version_format = GetSemanticVersionFormat(no_git_hash,
|
|
||||||
custom_for_pub)
|
|
||||||
version_str = (semantic_sdk_version
|
|
||||||
if version_file else semantic_version_format)
|
|
||||||
|
|
||||||
version = version.replace('{{VERSION_STR}}', version_str)
|
|
||||||
|
|
||||||
version = version.replace('{{SEMANTIC_SDK_VERSION}}', semantic_sdk_version)
|
|
||||||
|
|
||||||
# If grabbing the dev tag fails, then fall back on the default VERSION file.
|
|
||||||
latest = utils.GetLatestDevTag()
|
|
||||||
if not latest:
|
|
||||||
utils.GetSemanticSDKVersion(no_git_hash=True)
|
|
||||||
version = version.replace('{{LATEST}}', latest)
|
|
||||||
|
|
||||||
if custom_for_pub:
|
|
||||||
version = version.replace('{{PUB_CUSTOM}}', custom_for_pub)
|
|
||||||
|
|
||||||
git_hash = utils.GetShortGitHash()
|
|
||||||
if git_hash is None or len(git_hash) != 10:
|
|
||||||
git_hash = '0000000000'
|
|
||||||
version = version.replace('{{GIT_HASH}}', git_hash)
|
|
||||||
|
|
||||||
|
version_cc_text = open(input_file).read()
|
||||||
|
version_cc_text = version_cc_text.replace("{{VERSION_STR}}", version_string)
|
||||||
channel = utils.GetChannel()
|
channel = utils.GetChannel()
|
||||||
version = version.replace('{{CHANNEL}}', channel)
|
version_cc_text = version_cc_text.replace("{{CHANNEL}}", channel)
|
||||||
|
|
||||||
version_time = utils.GetGitTimestamp()
|
version_time = utils.GetGitTimestamp()
|
||||||
if no_git_hash or version_time == None:
|
if no_git_hash or version_time == None:
|
||||||
version_time = 'Unknown timestamp'
|
version_time = "Unknown timestamp"
|
||||||
version = version.replace('{{COMMIT_TIME}}', version_time.decode('utf-8'))
|
version_cc_text = version_cc_text.replace("{{COMMIT_TIME}}",
|
||||||
|
version_time.decode("utf-8"))
|
||||||
abi_version = utils.GetAbiVersion(version_file)
|
abi_version = utils.GetAbiVersion(version_file)
|
||||||
version = version.replace('{{ABI_VERSION}}', abi_version)
|
version_cc_text = version_cc_text.replace("{{ABI_VERSION}}", abi_version)
|
||||||
|
|
||||||
oldest_supported_abi_version = utils.GetOldestSupportedAbiVersion(
|
oldest_supported_abi_version = utils.GetOldestSupportedAbiVersion(
|
||||||
version_file)
|
version_file)
|
||||||
version = version.replace('{{OLDEST_SUPPORTED_ABI_VERSION}}',
|
version_cc_text = version_cc_text.replace(
|
||||||
oldest_supported_abi_version)
|
"{{OLDEST_SUPPORTED_ABI_VERSION}}", oldest_supported_abi_version)
|
||||||
|
|
||||||
snapshot_hash = MakeSnapshotHashString()
|
snapshot_hash = MakeSnapshotHashString()
|
||||||
version = version.replace('{{SNAPSHOT_HASH}}', snapshot_hash)
|
version_cc_text = version_cc_text.replace("{{SNAPSHOT_HASH}}",
|
||||||
|
snapshot_hash)
|
||||||
return version
|
open(output_file, 'w').write(version_cc_text)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main(args):
|
||||||
try:
|
try:
|
||||||
# Parse input.
|
# Parse input.
|
||||||
parser = argparse.ArgumentParser()
|
parser = OptionParser()
|
||||||
parser.add_argument(
|
parser.add_option(
|
||||||
'--custom_for_pub',
|
"--custom_for_pub",
|
||||||
help=('Generates a version string that works with pub that '
|
action="store",
|
||||||
'includes the given string. This is silently ignored on '
|
type="string",
|
||||||
'channels other than be.'))
|
help=("Generates a version string that works with pub that includes"
|
||||||
parser.add_argument('--input', help='Input template file.')
|
"the given string. This is silently ignored on channels other"
|
||||||
parser.add_argument('--no_git_hash',
|
"than be"))
|
||||||
action='store_true',
|
parser.add_option(
|
||||||
default=False,
|
"--input",
|
||||||
help='Don\'t try to determine VCS revision.')
|
action="store",
|
||||||
parser.add_argument('--output', help='output file name')
|
type="string",
|
||||||
parser.add_argument('-q',
|
help="input template file.")
|
||||||
'--quiet',
|
parser.add_option(
|
||||||
action='store_true',
|
"--no_git_hash",
|
||||||
default=False,
|
action="store_true",
|
||||||
help='DEPRECATED: Does nothing!')
|
default=False,
|
||||||
parser.add_argument('--version-file', help='Path to the VERSION file.')
|
help="Don't try to determine svn revision")
|
||||||
parser.add_argument('--git-revision-file',
|
parser.add_option(
|
||||||
help='Path to the GIT_REVISION file.')
|
"--output", action="store", type="string", help="output file name")
|
||||||
parser.add_argument(
|
parser.add_option(
|
||||||
'--format',
|
"-q",
|
||||||
default='{{VERSION_STR}}',
|
"--quiet",
|
||||||
help='Version format used if no input template is given.')
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="disable console output")
|
||||||
|
parser.add_option(
|
||||||
|
"--version-file",
|
||||||
|
action="store",
|
||||||
|
type="string",
|
||||||
|
default=None,
|
||||||
|
help="Version file")
|
||||||
|
|
||||||
args = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
# If there is no input template, then write the bare version string to
|
# If there is no input template, then write the bare version string to
|
||||||
# args.output. If there is no args.output, then write the version
|
# options.output. If there is no options.output, then write the version
|
||||||
# string to stdout.
|
# string to stdout.
|
||||||
|
if not options.input:
|
||||||
|
version_string = MakeVersionString(
|
||||||
|
options.quiet, options.no_git_hash, options.custom_for_pub)
|
||||||
|
if options.output:
|
||||||
|
open(options.output, 'w').write(version_string)
|
||||||
|
else:
|
||||||
|
print(version_string)
|
||||||
|
return 0
|
||||||
|
|
||||||
version_template = ''
|
if not options.output:
|
||||||
if args.input:
|
sys.stderr.write('--output not specified\n')
|
||||||
version_template = open(args.input).read()
|
return -1
|
||||||
elif not args.format is None:
|
if not options.input:
|
||||||
version_template = args.format
|
sys.stderr.write('--input not specified\n')
|
||||||
else:
|
return -1
|
||||||
raise 'No version template given! Set either --input or --format.'
|
|
||||||
|
|
||||||
version = FormatVersionString(version_template, args.no_git_hash,
|
files = []
|
||||||
args.custom_for_pub, args.version_file,
|
for arg in args:
|
||||||
args.git_revision_file)
|
files.append(arg)
|
||||||
|
|
||||||
if args.output:
|
if not MakeFile(options.quiet, options.output, options.input,
|
||||||
with open(args.output, 'w') as fh:
|
options.no_git_hash, options.custom_for_pub,
|
||||||
fh.write(version)
|
options.version_file):
|
||||||
else:
|
return -1
|
||||||
sys.stdout.write(version)
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
except Exception as inst:
|
except Exception as inst:
|
||||||
sys.stderr.write('make_version.py exception\n')
|
sys.stderr.write('make_version.py exception\n')
|
||||||
sys.stderr.write(str(inst))
|
sys.stderr.write(str(inst))
|
||||||
sys.stderr.write('\n')
|
sys.stderr.write('\n')
|
||||||
|
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
exit_code = main(sys.argv)
|
||||||
|
sys.exit(exit_code)
|
||||||
|
|||||||
+7
-11
@@ -350,16 +350,13 @@ def GetShortVersion():
|
|||||||
version.prerelease, version.prerelease_patch))
|
version.prerelease, version.prerelease_patch))
|
||||||
|
|
||||||
|
|
||||||
def GetSemanticSDKVersion(no_git_hash=False,
|
def GetSemanticSDKVersion(no_git_hash=False, version_file=None):
|
||||||
version_file=None,
|
|
||||||
git_revision_file=None):
|
|
||||||
version = ReadVersionFile(version_file)
|
version = ReadVersionFile(version_file)
|
||||||
if not version:
|
if not version:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if version.channel == 'be':
|
if version.channel == 'be':
|
||||||
postfix = '-edge' if no_git_hash else '-edge.%s' % GetGitRevision(
|
postfix = '-edge' if no_git_hash else '-edge.%s' % GetGitRevision()
|
||||||
git_revision_file)
|
|
||||||
elif version.channel in ('beta', 'dev'):
|
elif version.channel in ('beta', 'dev'):
|
||||||
postfix = '-%s.%s.%s' % (version.prerelease, version.prerelease_patch,
|
postfix = '-%s.%s.%s' % (version.prerelease, version.prerelease_patch,
|
||||||
version.channel)
|
version.channel)
|
||||||
@@ -370,8 +367,8 @@ def GetSemanticSDKVersion(no_git_hash=False,
|
|||||||
return '%s.%s.%s%s' % (version.major, version.minor, version.patch, postfix)
|
return '%s.%s.%s%s' % (version.major, version.minor, version.patch, postfix)
|
||||||
|
|
||||||
|
|
||||||
def GetVersion(no_git_hash=False, version_file=None, git_revision_file=None):
|
def GetVersion(no_git_hash=False, version_file=None):
|
||||||
return GetSemanticSDKVersion(no_git_hash, version_file, git_revision_file)
|
return GetSemanticSDKVersion(no_git_hash, version_file)
|
||||||
|
|
||||||
|
|
||||||
# The editor used to produce the VERSION file put on gcs. We now produce this
|
# The editor used to produce the VERSION file put on gcs. We now produce this
|
||||||
@@ -470,13 +467,12 @@ def GetArchiveVersion():
|
|||||||
return GetSemanticSDKVersion()
|
return GetSemanticSDKVersion()
|
||||||
|
|
||||||
|
|
||||||
def GetGitRevision(git_revision_file=None):
|
def GetGitRevision():
|
||||||
# When building from tarball use tools/GIT_REVISION
|
# When building from tarball use tools/GIT_REVISION
|
||||||
if git_revision_file is None:
|
git_revision_file = os.path.join(DART_DIR, 'tools', 'GIT_REVISION')
|
||||||
git_revision_file = os.path.join(DART_DIR, 'tools', 'GIT_REVISION')
|
|
||||||
try:
|
try:
|
||||||
with open(git_revision_file) as fd:
|
with open(git_revision_file) as fd:
|
||||||
return fd.read().strip()
|
return fd.read()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
p = subprocess.Popen(['git', 'rev-parse', 'HEAD'],
|
p = subprocess.Popen(['git', 'rev-parse', 'HEAD'],
|
||||||
|
|||||||
@@ -98,11 +98,9 @@ template("_application_snapshot") {
|
|||||||
depfile = "$output.d"
|
depfile = "$output.d"
|
||||||
abs_depfile = rebase_path(depfile)
|
abs_depfile = rebase_path(depfile)
|
||||||
rebased_output = rebase_path(output, root_build_dir)
|
rebased_output = rebase_path(output, root_build_dir)
|
||||||
|
|
||||||
vm_args = [
|
vm_args = [
|
||||||
"--depfile=$abs_depfile",
|
"--depfile=$abs_depfile",
|
||||||
"--depfile_output_filename=$rebased_output",
|
"--depfile_output_filename=$rebased_output",
|
||||||
"-Dsdk_hash=$sdk_hash",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
script = gen_kernel_script
|
script = gen_kernel_script
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
# BSD-style license that can be found in the LICENSE file.
|
# BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
import("../build/dart/dart_action.gni")
|
import("../build/dart/dart_action.gni")
|
||||||
import("../sdk_args.gni")
|
|
||||||
|
|
||||||
_dart_root = get_path_info("..", "abspath")
|
_dart_root = get_path_info("..", "abspath")
|
||||||
|
|
||||||
@@ -47,8 +46,6 @@ template("compile_platform") {
|
|||||||
|
|
||||||
outputs = invoker.outputs
|
outputs = invoker.outputs
|
||||||
|
|
||||||
vm_args = [ "-Dsdk_hash=$sdk_hash" ]
|
|
||||||
|
|
||||||
inputs = []
|
inputs = []
|
||||||
deps = []
|
deps = []
|
||||||
args = []
|
args = []
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ prebuilt_dart_action("generate_summary_strong") {
|
|||||||
inputs = sdk_lib_files + analyzer_files
|
inputs = sdk_lib_files + analyzer_files
|
||||||
output = "$root_gen_dir/strong.sum"
|
output = "$root_gen_dir/strong.sum"
|
||||||
outputs = [ output ]
|
outputs = [ output ]
|
||||||
vm_args = [ "-Dsdk_hash=$sdk_hash" ]
|
|
||||||
args = [
|
args = [
|
||||||
"build",
|
"build",
|
||||||
rebase_path(output),
|
rebase_path(output),
|
||||||
|
|||||||
@@ -82,8 +82,6 @@ template("dart2js_compile") {
|
|||||||
|
|
||||||
packages = "../../.packages"
|
packages = "../../.packages"
|
||||||
|
|
||||||
vm_args = [ "-Dsdk_hash=$sdk_hash" ]
|
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
"$abs_main",
|
"$abs_main",
|
||||||
"-m",
|
"-m",
|
||||||
@@ -120,8 +118,6 @@ prebuilt_dart_action("dartdevc_patch_sdk") {
|
|||||||
# TODO(rnystrom): List the outputs more precisely?
|
# TODO(rnystrom): List the outputs more precisely?
|
||||||
outputs = [ "$patched_sdk_dir/version" ]
|
outputs = [ "$patched_sdk_dir/version" ]
|
||||||
|
|
||||||
vm_args = [ "-Dsdk_hash=$sdk_hash" ]
|
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
"--libraries",
|
"--libraries",
|
||||||
rebase_path("$sdk_root/lib/libraries.json"),
|
rebase_path("$sdk_root/lib/libraries.json"),
|
||||||
@@ -234,8 +230,6 @@ template("dartdevc_kernel_compile") {
|
|||||||
"$js_gen_dir/$module.js",
|
"$js_gen_dir/$module.js",
|
||||||
]
|
]
|
||||||
|
|
||||||
vm_args = [ "-Dsdk_hash=$sdk_hash" ]
|
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
"-k",
|
"-k",
|
||||||
"--dart-sdk-summary=$sdk_path",
|
"--dart-sdk-summary=$sdk_path",
|
||||||
@@ -390,8 +384,6 @@ template("dartdevc_sdk_js") {
|
|||||||
"$js_gen_dir/legacy/dart_sdk.js.map",
|
"$js_gen_dir/legacy/dart_sdk.js.map",
|
||||||
]
|
]
|
||||||
|
|
||||||
vm_args = [ "-Dsdk_hash=$sdk_hash" ]
|
|
||||||
|
|
||||||
script = "../../pkg/dev_compiler/bin/dartdevc.dart"
|
script = "../../pkg/dev_compiler/bin/dartdevc.dart"
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
|
|||||||
@@ -85,11 +85,9 @@ template("kernel_service_dill") {
|
|||||||
depfile = "$root_gen_dir/kernel_service" + invoker.target_name + "_dill.d"
|
depfile = "$root_gen_dir/kernel_service" + invoker.target_name + "_dill.d"
|
||||||
abs_depfile = rebase_path(depfile)
|
abs_depfile = rebase_path(depfile)
|
||||||
rebased_output = rebase_path(output, root_build_dir)
|
rebased_output = rebase_path(output, root_build_dir)
|
||||||
|
|
||||||
vm_args = [
|
vm_args = [
|
||||||
"--depfile=$abs_depfile",
|
"--depfile=$abs_depfile",
|
||||||
"--depfile_output_filename=$rebased_output",
|
"--depfile_output_filename=$rebased_output",
|
||||||
"-Dsdk_hash=$sdk_hash",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
script = gen_kernel_script
|
script = gen_kernel_script
|
||||||
|
|||||||
Reference in New Issue
Block a user