Skip to content

Context.registerModuleDependency/getBuildFields behavior change #12846

Description

@RblSb
import sys.io.File;
import haxe.macro.Context;
import haxe.macro.Expr;

class Macro {
	macro static public function build(): Array<Field> {
		final fields = Context.getBuildFields();
		if (fields.length > 0) return fields;
		trace("invalidate", fields.map(struct -> struct.name));

		final resPath = "./files.txt";
		final content = File.getContent(resPath);
		final lines = content.split("\n");
		Context.registerModuleDependency(Context.getLocalModule(), resPath);
		for (name in lines) {
			if (name.length == 0) continue;
			fields.push({
				name: name,
				access: [APublic, AStatic],
				kind: FVar(macro :Int),
				pos: Context.currentPos()
			});
		}
		return fields;
	}
}

In vscode, after i change files.txt on latest stable release, invalidate triggers once after i focus on Main file where i use generated Module with this build macro.
On development, invalidate triggers on every Main save/focus now, because getBuildFields stops returning already builded fields after prev build.

Project: regdep.zip

And let me know if my macro is bad and i should use @:persistent there for simple file cache or something else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions