munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.75k stars 1.03k forks source link

Testing my implementation, dart can't find packages #993

Closed tato closed 3 years ago

tato commented 3 years ago

Sorry if this was pointed out in a previous issue, or if it is too unrelated to the book itself.

The readme shows a way to use the existing test suite to test our own implementation of lox, with a command like

$ dart tool/bin/test.dart clox --interpreter my_code/boblox

I installed the dart-sdk, and when I run that command, dart complains about missing packages.

C:\a\craftinginterpreters % dart .\tool\bin\test.dart clox --interpreter ..\abugabuga\target\release\abugabuga.exe
tool/bin/test.dart:297:43: Warning: Operand of null-aware operation '...?' has type 'List<String>' which excludes null.
 - 'List' is from 'dart:core'.
      if (_customInterpreter != null) ...?_customArguments else ..._suite.args,
                                          ^
tool/bin/test.dart:300:34: Warning: Operand of null-aware operation '??' has type 'String' which excludes null.
    var result = Process.runSync(_customInterpreter ?? _suite.executable, args);
                                 ^
Error: Couldn't resolve the package 'args' in 'package:args/args.dart'.
Error: Couldn't resolve the package 'glob' in 'package:glob/glob.dart'.
Error: Couldn't resolve the package 'path' in 'package:path/path.dart'.
Error: Couldn't resolve the package 'tool' in 'package:tool/src/term.dart'.
tool/bin/test.dart:4:8: Error: Not found: 'package:args/args.dart'
import 'package:args/args.dart';
       ^
tool/bin/test.dart:5:8: Error: Not found: 'package:glob/glob.dart'
import 'package:glob/glob.dart';
       ^
tool/bin/test.dart:6:8: Error: Not found: 'package:path/path.dart'
import 'package:path/path.dart' as p;
       ^
tool/bin/test.dart:8:8: Error: Not found: 'package:tool/src/term.dart'
import 'package:tool/src/term.dart' as term;
       ^
tool/bin/test.dart:92:18: Error: Type 'ArgParser' not found.
void _usageError(ArgParser parser, String message) {
                 ^^^^^^^^^
tool/bin/test.dart:25:7: Error: Field '_suite' should be initialized because its type 'Suite' doesn't allow null.
 - 'Suite' is from 'tool/bin/test.dart'.
Suite _suite;
      ^^^^^^

I'm not familiar at all with dart, so this could easily be my own mistake, but I figured I would ask in case someone else runs into the same situation. Is this caused by being on Windows? Maybe I'm using a different, incompatible dart version [1]? Or is there a step I didn't follow?

[1] Dart SDK version: 2.13.4 (stable) (Wed Jun 23 13:08:41 2021 +0200) on "windows_x64"

tato commented 3 years ago

I think I just needed to run pub get inside the tool/ directory. I'll see myself out.

Storyyeller commented 2 years ago

I'm having the same issue, except that I can't run any of the tests, even with clox/jlox. Could you elaborate on the pub get thing please? Is pub a tool you have to install?

munificent commented 2 years ago

Is pub a tool you have to install?

If you have installed the Dart SDK, it will include pub. pub used to be a separate command, but now it's baked into the main dart command line executable so you should run:

$ dart pub get

From within the tools directory.

rhodesrt commented 1 year ago

I'd like to provide a solution here as I ran into the same issue today. In my case, my Dart version was 3.0.5 (latest stable as of 06/29/23) which supports null safety. In craftinginterpreters/tool/pubspec.yaml, the SDK version constraint is set to >2.11.0 <3.0.0. What this means is that your Dart SDK must be within that version constraint. So, in short, in order for dart pub get to properly install the package dependencies defined in pubspec.yaml, you must use an archived Dart SDK version. I used 2.12.0(stable) and that has worked fine with the Makefile. In order to get 2.12.0, first remove your current Dart SDK, mine was in /usr/bin/dart but you can run which dart to find yours. Then run the following commands if you are on Linux (If not on Linux, try to find out what to do here):

$ wget https://storage.googleapis.com/dart-archive/channels/stable/release/2.12.0/sdk/dartsdk-linux-x64-release.zip
$ unzip dartsdk-linux-x64-release.zip
$ sudo mv dart-sdk /usr/bin
$ echo 'export PATH="$PATH:/usr/bin/dart-sdk/bin"' >> ~/.bashrc

Hope this helps! Side note: If anyone at Google is looking for a passionate engineer, I'd love to interview. Also @munificent thank you for this lovely book and illustrations.