felangel / mason

Tools which allow developers to create and consume reusable templates called bricks.
https://docs.brickhub.dev
932 stars 93 forks source link

fix: `Isolate.spawnUri()` does not contain a valid AOT snapshot on script compiled with `dart compile exe` #1329

Closed KernelPanic92 closed 3 weeks ago

KernelPanic92 commented 1 month ago

Description

I have created a CLI where each command fetches a brick from a git URL and executes it. When I run the CLI with dart tools or installing it via dart pub global activate --source git https://github.com/acadevmy/devmy_cli, everything works smoothly. However, when I compile it using the command dart compile exe -o dist/devmy bin/devmy.dart and try to use any command linked to a brick from compiled application, for example devmy new I receive the following error:

An exception occurred while executing hook: /Users/iacopociao/.mason-cache/bundled/scaffold_0.1.1_292ec6ed4e584bc759e67be06280ee7a937538b9/hooks/pre_gen.dart.
Error: Unable to spawn isolate: The uri(file:///Users/iacopociao/.mason-cache/bundled/scaffold_0.1.1_292ec6ed4e584bc759e67be06280ee7a937538b9/hooks/build/hooks/pre_gen/pre_gen_5ab7fea9a1c3a2e2c03da257c19045d7566abab7.dill) provided to `Isolate.spawnUri()` does not contain a valid AOT snapshot.

Steps To Reproduce

  1. Create a Dart Console Project:

    • Use the Dart SDK to create a new console project.
  2. Insert the Following Code in the Pre-Generated Dart File in the bin Directory:

    import 'dart:io';
    import 'package:mason/mason.dart';
    
    void main() async {
     final target = DirectoryGeneratorTarget(Directory.current);
    
     final brick = await BricksJson.temp().add(
       Brick.git(GitPath('https://github.com/acadevmy/scaffold-brick')),
     );
    
     final path = brick.path;
     final bundle = createBundle(Directory(path));
    
     MasonGenerator generator = await MasonGenerator.fromBundle(bundle);
     generator.hooks.preGen(
       workingDirectory: Directory.current.path,
     );
    
     generator.generate(
       target,
     );
    
     await generator.hooks.postGen(
       workingDirectory: Directory.current.path,
     );
    }
  3. Compile the Project:

    dart compile exe -o "dist/compiled" "bin/{your-dart-file-name}.dart"
  4. Run the Compiled Executable:

    cd dist && ./compiled

Expected Behavior

I expect it to be able to successfully execute the preGen and postGen hooks. Clearly, the brick I'm using requires additional parameters to avoid failing in the postGen hook, so if you want to use something else that can still replicate the error, that's fine.

Additional Context

Running on MacOS 13.4.1 dart: 3.4.1 (stable)

felangel commented 1 month ago

Description

I have created a CLI where each command fetches a brick from a git URL and executes it. When I run the CLI with dart tools or installing it via dart pub global activate --source git https://github.com/acadevmy/devmy_cli, everything works smoothly. However, when I compile it using the command dart compile exe -o dist/devmy bin/devmy.dart and try to use any command linked to a brick from compiled application, for example devmy new I receive the following error:

An exception occurred while executing hook: /Users/iacopociao/.mason-cache/bundled/scaffold_0.1.1_292ec6ed4e584bc759e67be06280ee7a937538b9/hooks/pre_gen.dart.
Error: Unable to spawn isolate: The uri(file:///Users/iacopociao/.mason-cache/bundled/scaffold_0.1.1_292ec6ed4e584bc759e67be06280ee7a937538b9/hooks/build/hooks/pre_gen/pre_gen_5ab7fea9a1c3a2e2c03da257c19045d7566abab7.dill) provided to `Isolate.spawnUri()` does not contain a valid AOT snapshot.

Steps To Reproduce

  1. Create a Dart Console Project:

    • Use the Dart SDK to create a new console project.
  2. Insert the Following Code in the Pre-Generated Dart File in the bin Directory:

    import 'dart:io';
    import 'package:mason/mason.dart';
    
    void main() async {
     final target = DirectoryGeneratorTarget(Directory.current);
    
     final brick = await BricksJson.temp().add(
       Brick.git(GitPath('https://github.com/acadevmy/scaffold-brick')),
     );
    
     final path = brick.path;
     final bundle = createBundle(Directory(path));
    
     MasonGenerator generator = await MasonGenerator.fromBundle(bundle);
     generator.hooks.preGen(
       workingDirectory: Directory.current.path,
     );
    
     generator.generate(
       target,
     );
    
     await generator.hooks.postGen(
       workingDirectory: Directory.current.path,
     );
    }
  3. Compile the Project:
    dart compile exe -o "dist/compiled" "bin/{your-dart-file-name}.dart"
  4. Run the Compiled Executable:
    cd dist && ./compiled

Expected Behavior

I expect it to be able to successfully execute the preGen and postGen hooks. Clearly, the brick I'm using requires additional parameters to avoid failing in the postGen hook, so if you want to use something else that can still replicate the error, that's fine.

Additional Context

Running on MacOS 13.4.1 dart: 3.4.1 (stable)

Hi @KernelPanic92 👋 Thanks for opening an issue!

I have a fix for this at #1331. Can you re-test using that branch and let me know if it resolves the issue?

felangel commented 1 month ago

This should be fixed in v0.1.0-dev.54 of package:mason. Let me know if you encounter any issues!

felangel commented 1 month ago

Reverted the fix because it broke hook execution in JIT mode in some situations. I'll spend some more time on this in the next few days. In the meantime, you should be able to use v0.1.0-dev.54 of package:mason (but keep in mind that version contains a bug which causes hooks execution to fail in JIT mode).

KernelPanic92 commented 1 month ago

Hi @felangel ! Thank you for the quick response! I did some testing and now it works again 🚀 For the moment, I'll stick with v0.1.0-dev.54 and leave the issue open so I can stay updated on the fix development and provide you with further checks if there are any updates 🤟 Thanks a lot!

felangel commented 3 weeks ago

@KernelPanic92 this is now fixed in the latest published version (v0.1.0-dev.57) 🎉