Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions amethyst.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[amethyst]
amber-version = 0.5.1-alpha

[dependencies]
xylitol = https://github.com/zlfn/xylitol.git

[project]
entry = src/main.ab
name = amethyst
Expand Down
18 changes: 16 additions & 2 deletions lib/amber_manager.ab
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { file_exists, file_extract, file_glob } from "std/fs"
import { file_exists, file_extract, file_glob, symlink_create } from "std/fs"
import { array_contains } from "std/array"
import { file_download } from "std/http"
import { slice } from "std/text"
import { slice, text_contains } from "std/text"

import { info, fatal } from "./utils.ab"
import { get_amber_tags } from "./github.ab"
Expand Down Expand Up @@ -32,6 +32,20 @@ pub fun get_local_versions(): [Text] {
return amber_bins
}

pub fun is_system_amber_correct(version: Text): Bool {
const data_dir = get_amethyst_data_dir()
let versionString = $ amber --version $ failed {
return false
}

if text_contains(versionString, version) {
info("Found system-wide {versionString}")
return true
} else {
return false
}
}

pub fun is_available_locally(version: Text): Bool {
const data_dir = get_amethyst_data_dir()
$ mkdir -p "{data_dir}/amber" $ failed {
Expand Down
6 changes: 5 additions & 1 deletion lib/project.ab
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { array_pop } from "std/array"

import { parent_dir, basename } from "./path.ab"
import { info, warn, fatal } from "./utils.ab"
import { is_available_locally, is_available_remotely, download } from "./amber_manager.ab"
import { is_available_locally, is_available_remotely, is_system_amber_correct, download } from "./amber_manager.ab"

pub fun locate_project(): [Text] {
let cwd = trust $ pwd $
Expand Down Expand Up @@ -253,6 +253,10 @@ pub fun get_project_amber() {
}

if not is_available_locally(version) {
if is_system_amber_correct(version) {
return "system"
}

warn("Amber {version} is not available locally.")
info("Checking if it is available for download...")

Expand Down
7 changes: 6 additions & 1 deletion src/commands/build.ab
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ pub fun cmd_build(arguments: [Text]): Null {

const data_dir = get_amethyst_data_dir()
const version = get_project_amber()
let amber = ""

const amber = "{data_dir}/amber/amber.{version}.bin"
if version == "system" {
amber = "amber"
} else {
amber = "{data_dir}/amber/amber.{version}.bin"
}
trust $ exec "{amber}" build "{entry}" "{target}/{name}.sh" $

exit(0)
Expand Down