Skip to content

Commit

Permalink
delete build cache temporarily to avoid gleam issue gleam-lang/gleam#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TanklesXL committed May 25, 2024
1 parent c616b54 commit 118bab0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
1 change: 1 addition & 0 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gleam_erlang = "~> 0.7"
snag = "~> 0.2"
parallel_map = ">= 2.0.0 and < 3.0.0"
filepath = ">= 1.0.0 and < 2.0.0"
tom = ">= 1.0.0 and < 2.0.0"

[dev-dependencies]
gleeunit = "~> 1.0"
8 changes: 5 additions & 3 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ packages = [
{ name = "gleam_json", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9063D14D25406326C0255BDA0021541E797D8A7A12573D849462CAFED459F6EB" },
{ name = "gleam_otp", version = "0.10.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "0B04FE915ACECE539B317F9652CAADBBC0F000184D586AAAF2D94C100945D72B" },
{ name = "gleam_package_interface", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_package_interface", source = "hex", outer_checksum = "52A721BCA972C8099BB881195D821AAA64B9F2655BECC102165D5A1097731F01" },
{ name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" },
{ name = "glearray", version = "0.2.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glearray", source = "hex", outer_checksum = "908154F695D330E06A37FAB2C04119E8F315D643206F8F32B6A6C14A8709FFF4" },
{ name = "gleam_stdlib", version = "0.38.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "663CF11861179AF415A625307447775C09404E752FF99A24E2057C835319F1BE" },
{ name = "glearray", version = "0.2.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glearray", source = "hex", outer_checksum = "9C207E05F38D724F464FA921378DB3ABC2B0A2F5821116D8BC8B2CACC68930D5" },
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" },
{ name = "glint", version = "1.0.0-rc2", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "FD5C47CE237CA67121F3946ADE7C630750BB67F5E8A4717D2DF5B5EE758CCFDB" },
{ name = "parallel_map", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "parallel_map", source = "hex", outer_checksum = "653714A9FD63EACD1A9D0A6582A972B0EC109AE275CDDD2E99CFC3DFAFAB9225" },
Expand All @@ -21,11 +21,12 @@ packages = [
{ name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" },
{ name = "spinner", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_erlang", "gleam_stdlib", "glearray", "repeatedly"], otp_app = "spinner", source = "hex", outer_checksum = "200BA3D4A04D468898E63C0D316E23F526E02514BC46454091975CB5BAE41E8F" },
{ name = "thoas", version = "1.2.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "E38697EDFFD6E91BD12CEA41B155115282630075C2A727E7A6B2947F5408B86A" },
{ name = "tom", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tom", source = "hex", outer_checksum = "A5364613E3DBF77F38EFF81DA9F99324086D029EC2B2D44348762FBE38602311" },
]

[requirements]
argv = { version = "~> 1.0" }
filepath = { version = ">= 1.0.0 and < 2.0.0"}
filepath = { version = ">= 1.0.0 and < 2.0.0" }
gleam_erlang = { version = "~> 0.7" }
gleam_json = { version = "~> 1.0" }
gleam_otp = { version = "~> 0.4" }
Expand All @@ -38,3 +39,4 @@ shellout = { version = "~> 1.6" }
simplifile = { version = "~> 1.0" }
snag = { version = "~> 0.2" }
spinner = { version = "~> 1.1" }
tom = { version = ">= 1.0.0 and < 2.0.0" }
60 changes: 59 additions & 1 deletion src/gladvent/internal/runners.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import shellout
import simplifile
import snag.{type Result}
import spinner
import tom

pub type PartRunner =
fn(Dynamic) -> Dynamic
Expand All @@ -28,13 +29,33 @@ pub type DayRunner =
const package_interface_path = "build/.gladvent/pkg.json"

type PkgInterfaceErr {
FailedToGleamBuild(String)
FailedToReadGleamToml(simplifile.FileError)
FailedToDecodeGleamToml(tom.ParseError)
FailedToGetPackageName(tom.GetError)
FailedToGeneratePackageInterface(String)
FailedToReadPackageInterface(simplifile.FileError)
FailedToClearBuildCache(simplifile.FileError)
FailedToDecodePackageInterface(json.DecodeError)
}

fn package_interface_error_to_snag(e: PkgInterfaceErr) -> snag.Snag {
case e {
FailedToGleamBuild(s) ->
snag.new(s)
|> snag.layer("failed to build gleam project")
FailedToDecodeGleamToml(e) ->
snag.new(string.inspect(e))
|> snag.layer("failed to decode gleam.toml")
FailedToGetPackageName(e) ->
snag.new(string.inspect(e))
|> snag.layer("failed to get package name")
FailedToReadGleamToml(e) ->
snag.new(string.inspect(e))
|> snag.layer("failed to read gleam.toml")
FailedToClearBuildCache(e) ->
snag.new(string.inspect(e))
|> snag.layer("failed to clear build cache")
FailedToGeneratePackageInterface(s) ->
snag.new(s)
|> snag.layer("failed to generate " <> package_interface_path)
Expand All @@ -55,11 +76,48 @@ pub fn pkg_interface() -> Result(package_interface.Package) {

use <- defer(do: fn() { spinner.stop(spinner) })

let root = cmd.root()

use gleam_toml <- result.try(
simplifile.read(filepath.join(root, "gleam.toml"))
|> result.map_error(FailedToReadGleamToml),
)

use toml <- result.try(
tom.parse(gleam_toml)
|> result.map_error(FailedToDecodeGleamToml),
)

use name <- result.try(
tom.get_string(toml, ["name"])
|> result.map_error(FailedToGetPackageName),
)

use _ <- result.try(
{
use cache <- list.try_map(["build/prod/erlang", "build/dev/erlang"])
filepath.join(root, cache)
|> filepath.join(name)
|> simplifile.delete
}
|> result.try_recover(fn(e) {
case e {
simplifile.Enoent -> Ok([])
_ -> Error(FailedToClearBuildCache(e))
}
}),
)

use _ <- result.try(
shellout.command("gleam", ["build"], root, [])
|> result.map_error(fn(e) { FailedToGeneratePackageInterface(e.1) }),
)

use _ <- result.try(
shellout.command(
"gleam",
["export", "package-interface", "--out", package_interface_path],
".",
root,
[],
)
|> result.map_error(fn(e) { FailedToGeneratePackageInterface(e.1) }),
Expand Down

0 comments on commit 118bab0

Please sign in to comment.