-module(builder@context). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/builder/context.gleam"). -export([new_dummy_build_context/5, new_build_context/1, modules/1, read/2, read_bits/2, write/3, write_bits/3]). -export_type([error/0, build_context/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -type error() :: {file_error, simplifile:file_error()}. -opaque build_context() :: {build_context, gleam@dict:dict(binary(), builder@module:module_()), fun((build_context(), builder@asset:build_asset()) -> {ok, binary()} | {error, error()}), fun((build_context(), builder@asset:build_asset()) -> {ok, bitstring()} | {error, error()}), fun((build_context(), builder@asset:build_asset(), binary()) -> {ok, nil} | {error, error()}), fun((build_context(), builder@asset:build_asset(), bitstring()) -> {ok, nil} | {error, error()})}. -file("src/builder/context.gleam", 40). ?DOC(false). -spec new_dummy_build_context( gleam@dict:dict(binary(), builder@module:module_()), fun((build_context(), builder@asset:build_asset()) -> {ok, binary()} | {error, error()}), fun((build_context(), builder@asset:build_asset()) -> {ok, bitstring()} | {error, error()}), fun((build_context(), builder@asset:build_asset(), binary()) -> {ok, nil} | {error, error()}), fun((build_context(), builder@asset:build_asset(), bitstring()) -> {ok, nil} | {error, error()}) ) -> build_context(). new_dummy_build_context(Modules, Read, Read_bits, Write, Write_bits) -> {build_context, Modules, Read, Read_bits, Write, Write_bits}. -file("src/builder/context.gleam", 50). -spec read_impl(build_context(), builder@asset:build_asset()) -> {ok, binary()} | {error, error()}. read_impl(_, Asset) -> _pipe = simplifile:read(erlang:element(2, Asset)), gleam@result:map_error(_pipe, fun(Err) -> {file_error, Err} end). -file("src/builder/context.gleam", 55). -spec read_bits_impl(build_context(), builder@asset:build_asset()) -> {ok, bitstring()} | {error, error()}. read_bits_impl(_, Asset) -> _pipe = simplifile_erl:read_bits(erlang:element(2, Asset)), gleam@result:map_error(_pipe, fun(Err) -> {file_error, Err} end). -file("src/builder/context.gleam", 63). -spec write_impl(build_context(), builder@asset:build_asset(), binary()) -> {ok, nil} | {error, error()}. write_impl(Ctx, Asset, Contents) -> gleam@bool:guard( read_impl(Ctx, Asset) =:= {ok, Contents}, {ok, nil}, fun() -> _pipe = simplifile:write(erlang:element(2, Asset), Contents), gleam@result:map_error(_pipe, fun(Err) -> {file_error, Err} end) end ). -file("src/builder/context.gleam", 73). -spec write_bits_impl(build_context(), builder@asset:build_asset(), bitstring()) -> {ok, nil} | {error, error()}. write_bits_impl(Ctx, Asset, Bits) -> gleam@bool:guard( read_bits_impl(Ctx, Asset) =:= {ok, Bits}, {ok, nil}, fun() -> _pipe = simplifile_erl:write_bits(erlang:element(2, Asset), Bits), gleam@result:map_error(_pipe, fun(Err) -> {file_error, Err} end) end ). -file("src/builder/context.gleam", 29). ?DOC(false). -spec new_build_context(gleam@dict:dict(binary(), builder@module:module_())) -> build_context(). new_build_context(Modules) -> {build_context, Modules, fun read_impl/2, fun read_bits_impl/2, fun write_impl/3, fun write_bits_impl/3}. -file("src/builder/context.gleam", 84). ?DOC(" Get the dictionary of all analyzed modules in the project\n"). -spec modules(build_context()) -> gleam@dict:dict(binary(), builder@module:module_()). modules(Ctx) -> erlang:element(2, Ctx). -file("src/builder/context.gleam", 89). ?DOC(" Read a file's contents as a String\n"). -spec read(build_context(), builder@asset:build_asset()) -> {ok, binary()} | {error, error()}. read(Ctx, Asset) -> (erlang:element(3, Ctx))(Ctx, Asset). -file("src/builder/context.gleam", 94). ?DOC(" Read a file's contents as a BitArray\n"). -spec read_bits(build_context(), builder@asset:build_asset()) -> {ok, bitstring()} | {error, error()}. read_bits(Ctx, Asset) -> (erlang:element(4, Ctx))(Ctx, Asset). -file("src/builder/context.gleam", 101). ?DOC( " Write a String to a file\n" "\n" " Automatically skips the write if the file already contains the exact same content.\n" ). -spec write(build_context(), builder@asset:build_asset(), binary()) -> {ok, nil} | {error, error()}. write(Ctx, Asset, Contents) -> (erlang:element(5, Ctx))(Ctx, Asset, Contents). -file("src/builder/context.gleam", 108). ?DOC( " Write a BitArray to a file\n" "\n" " Automatically skips the write if the file already contains the exact same content.\n" ). -spec write_bits(build_context(), builder@asset:build_asset(), bitstring()) -> {ok, nil} | {error, error()}. write_bits(Ctx, Asset, Bits) -> (erlang:element(6, Ctx))(Ctx, Asset, Bits).