Files
sdk/pkg/kernel/test/binary/utils.dart
T
Jens Johansen bee48f6ed6 [CFE][kernel] Add more checks for NNBD settings mismatch
* When initializing from a dill in the incremental compiler check that
  the nnbd mode matches what we're asked to compile.
  If they don't, silently do not initialize from the file.
* When serializing and deserializing, assert that the individual
  libraries match the component compilation mode.
* When appending dill libraries in the CFE, assert that they match
  what we're asked to compile.
* Remove NonNullableByDefaultCompiledMode.Disabled -- it's not a thing
  anyway.

https://github.com/flutter/flutter/issues/68901

Change-Id: I2e68f17cb3a065c4352e4db7c8aee3c13747f23a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169080
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2020-10-26 15:23:56 +00:00

41 lines
1.2 KiB
Dart

// Copyright (c) 2019, 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 BytesBuilder;
import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
import 'package:kernel/kernel.dart';
export 'package:kernel/kernel.dart';
Library libRoundTrip(Library lib) {
return serializationRoundTrip([lib])[0];
}
List<Library> serializationRoundTrip(List<Library> libraries) {
Component c = new Component(libraries: libraries)
..setMainMethodAndMode(
null, false, libraries.first.nonNullableByDefaultCompiledMode);
List<int> bytes = serializeComponent(c);
Component c2 = loadComponentFromBytes(bytes);
return c2.libraries;
}
List<int> serializeComponent(Component c) {
ByteSink byteSink = new ByteSink();
BinaryPrinter printer = new BinaryPrinter(byteSink);
printer.writeComponentFile(c);
return byteSink.builder.takeBytes();
}
/// A [Sink] that directly writes data into a byte builder.
class ByteSink implements Sink<List<int>> {
final BytesBuilder builder = new BytesBuilder();
void add(List<int> data) {
builder.add(data);
}
void close() {}
}