Skip to content

Commit

Permalink
Revert "Fix warnings about missing imports"
Browse files Browse the repository at this point in the history
This reverts commit d770c16.
  • Loading branch information
simolus3 committed Dec 11, 2023
1 parent 633cc52 commit 8ac1260
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 76 deletions.
35 changes: 7 additions & 28 deletions drift_dev/lib/src/analysis/driver/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,40 +174,19 @@ class DriftAnalysisDriver {
}

Future<void> _warnAboutUnresolvedImportsInDriftFile(FileState known) async {
await discoverIfNecessary(known);

final state = known.discovery;
if (state is DiscoveredDriftFile) {
for (final import in state.imports) {
final file = await findLocalElements(import.importedUri);

if (file.isValidImport != true) {
var crossesPackageBoundaries = false;

if (import.importedUri.scheme == 'package' &&
known.ownUri.scheme == 'package') {
final ownPackage = known.ownUri.pathSegments.first;
final importedPackage = import.importedUri.pathSegments.first;
crossesPackageBoundaries = ownPackage != importedPackage;
}

final message = StringBuffer(
'The imported file, `${import.importedUri}`, does not exist or '
"can't be imported.",
);
if (crossesPackageBoundaries) {
message
..writeln()
..writeln(
'Note: When importing drift files across packages, the '
'imported package needs to apply a drift builder. '
'See https://github.com/simolus3/drift/issues/2719 for '
'details.',
);
}

known.errorsDuringDiscovery.add(
DriftAnalysisError.inDriftFile(import.ast, message.toString()));
DriftAnalysisError.inDriftFile(
import.ast,
'The imported file, `${import.importedUri}`, does not exist or '
"can't be imported.",
),
);
}
}
}
Expand Down Expand Up @@ -264,7 +243,7 @@ class DriftAnalysisDriver {
await _warnAboutUnresolvedImportsInDriftFile(known);

// Also make sure elements in transitive imports have been resolved.
final seen = <Uri>{};
final seen = cache.knownFiles.keys.toSet();
final pending = <Uri>[known.ownUri];

while (pending.isNotEmpty) {
Expand Down
39 changes: 2 additions & 37 deletions drift_dev/test/backends/build/build_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@ CREATE TABLE [STRING_TABLE](
Future<void> runTest(String source, expectedMessage) async {
final build = emulateDriftBuild(
inputs: {'a|lib/a.drift': source},
logger: loggerThat(emits(record(expectedMessage))),
logger: loggerThat(emits(isA<LogRecord>()
.having((e) => e.message, 'message', expectedMessage))),
modularBuild: true,
options: options,
);
Expand Down Expand Up @@ -801,40 +802,4 @@ CREATE TABLE [STRING_TABLE](
});
}
});

test('warns about missing imports', () async {
await emulateDriftBuild(
inputs: {
'a|lib/main.drift': '''
import 'package:b/b.drift';
import 'package:a/missing.drift';
CREATE TABLE users (
another INTEGER REFERENCES b(foo)
);
''',
'b|lib/b.drift': '''
CREATE TABLE b (foo INTEGER);
''',
},
logger: loggerThat(
emitsInAnyOrder(
[
record(
allOf(
contains(
"The imported file, `package:b/b.drift`, does not exist or can't be imported"),
contains('Note: When importing drift files across packages'),
),
),
record(allOf(
contains('package:a/missing.drift'),
isNot(contains('Note: When')),
)),
record(contains('`b` could not be found in any import.')),
],
),
),
);
});
}
6 changes: 3 additions & 3 deletions drift_dev/test/backends/build/drift_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void main() {
);

await emulateDriftBuild(inputs: {
'a|lib/a.dart': '''
'foo|lib/a.dart': '''
// @dart = 2.11
import 'package:drift/drift.dart';
Expand All @@ -32,7 +32,7 @@ class Database {}

test('includes version override in part file mode', () async {
final writer = await emulateDriftBuild(inputs: {
'a|lib/a.dart': '''
'foo|lib/a.dart': '''
// @dart = 2.13
import 'package:drift/drift.dart';
Expand All @@ -44,7 +44,7 @@ class Database {}

checkOutputs(
{
'a|lib/a.drift.dart': decodedMatches(contains('// @dart=2.13')),
'foo|lib/a.drift.dart': decodedMatches(contains('// @dart=2.13')),
},
writer.dartOutputs,
writer.writer,
Expand Down
8 changes: 0 additions & 8 deletions drift_dev/test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ Logger loggerThat(dynamic expectedLogs) {
return logger;
}

TypeMatcher<LogRecord> record(dynamic message) {
return isA<LogRecord>().having((e) => e.message, 'message', message);
}

final _packageConfig = Future(() async {
final uri = await Isolate.packageConfig;

Expand Down Expand Up @@ -85,10 +81,6 @@ Future<DriftBuildResult> emulateDriftBuild({
for (final input in inputs.keys) {
final inputId = makeAssetId(input);

// Assets from other packages are visible, but we're not running
// builders on them.
if (inputId.package != 'a') continue;

if (expectedOutputs(stage, inputId).isNotEmpty) {
final readerForPhase = _TrackingAssetReader(reader);

Expand Down

0 comments on commit 8ac1260

Please sign in to comment.