Skip to content

Commit

Permalink
Merge pull request #23 from NFIBrokerage/add-harness-to-vm-path
Browse files Browse the repository at this point in the history
Add harness to vm path
  • Loading branch information
svrdlans authored Aug 24, 2023
2 parents 04f279f + 092409d commit 448184b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ The format is based on [Keep a
Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.7.4 - 2023-08-09

### Fixed

- This version fixes warnings and errors encountered when using `harness` with
Elixir 1.15
- added harness archive ebin path to VM path list because Elixir 1.15
prunes code paths before compiling
- `EEx.eval_string/3` is now used instead of `EEx.eval_file/3` when
rendering templates with import of `Harness.Renderer.Helpers` functions
being appended to every template binary because passing `:functions` in
options is deprecated since Elixir 1.13

## 0.7.3 - 2023-04-05

### Changed

- Updated `hackney` from 1.16 to 1.18.1
- Pinned ubuntu runner to `ubuntu-20.04` in workflows because of OTP 22.3

## 0.7.2 - 2021-11-29

### Fixed
Expand Down
18 changes: 18 additions & 0 deletions lib/harness/manifest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ defmodule Harness.Manifest do
@doc false
def hash(term), do: term |> :erlang.phash2() |> to_string

@doc "gets the path of the archive itself"
def archive_path do
current_name = Mix.Local.name_for(:archives, Mix.Project.config())

current_name
|> Mix.Tasks.Archive.Install.find_previous_versions()
|> case do
[found | _] ->
found

[] ->
[Mix.path_for(:archives), Mix.Local.archive_name(current_name)]
|> Path.join()
end
|> Mix.Local.archive_ebin()
end

@doc "reads the manifest file from the path"
def read(path) do
with false <- File.dir?(path),
Expand Down Expand Up @@ -65,6 +82,7 @@ defmodule Harness.Manifest do
:ok =
deps
|> Enum.flat_map(&Mix.Dep.load_paths/1)
|> (&[archive_path() | &1]).()
|> Enum.each(&Code.append_path/1)

deps
Expand Down
12 changes: 4 additions & 8 deletions lib/harness/renderer/file.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Harness.Renderer.File do
@moduledoc false

alias Harness.Renderer.{Run, Helpers, Utils}
alias Harness.Renderer.{Run, Utils}

# a common interface for being a file

Expand Down Expand Up @@ -65,13 +65,9 @@ defmodule Harness.Renderer.File do

generated_contents =
file.source_path
|> EEx.eval_file(
[assigns: run.generator_config],
functions: [
{Helpers, Helpers.__info__(:functions)},
{Elixir.Kernel, Kernel.__info__(:functions)}
]
)
|> File.read!()
|> (&("<% import Harness.Renderer.Helpers %>" <> &1)).()
|> EEx.eval_string(assigns: run.generator_config)
# this shouldn't be necessary but it prevents a strange dialyzer warn
|> format_elixir(path, Path.extname(file.source_path))

Expand Down
2 changes: 2 additions & 0 deletions lib/mix/tasks/harness.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ defmodule Mix.Tasks.Harness do
Mix.Task.run("harness.compile", [path])
end

Harness.Manifest.load(path)

Harness.Renderer.render(path)
end
end

0 comments on commit 448184b

Please sign in to comment.