Skip to content

Commit

Permalink
Add in changes from #124 - clean before testing and fix some minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
japhib authored and luk-pau-es committed Nov 23, 2022
1 parent 20e70ea commit dba7c7a
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 263 deletions.
7 changes: 0 additions & 7 deletions examples/simple_umbrella_app/apps/app_a/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ defmodule AppA.MixProject do
start_permanent: Mix.env() == :prod,
deps: deps(),

gradient: [

enabled: true,


]

]
end

Expand Down
5 changes: 0 additions & 5 deletions examples/simple_umbrella_app/apps/app_b/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ defmodule AppB.MixProject do
start_permanent: Mix.env() == :prod,
deps: deps(),

gradient: [


]

]
end

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_umbrella_app/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule SimpleUmbrellaApp.MixProject do

gradient: [

enabled: false,
enabled: true,


]
Expand Down
17 changes: 14 additions & 3 deletions lib/gradient.ex
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ defmodule Gradient do

defp maybe_specify_forms(forms, opts) do
unless opts[:no_specify] do
forms
|> AstSpecifier.specify()
AstSpecifier.specify(forms)
else
forms
end
Expand All @@ -180,7 +179,7 @@ defmodule Gradient do
{:attribute, anno, :file, {path, line}} = hd(forms)

[
{:attribute, anno, :file, {String.to_charlist(app_path) ++ '/' ++ path, line}}
{:attribute, anno, :file, {maybe_prepend_app_path(app_path, path), line}}
| tl(forms)
]
end
Expand All @@ -190,6 +189,18 @@ defmodule Gradient do
end
end

defp maybe_prepend_app_path(app_path, path) do
unless is_absolute_path(path) do
String.to_charlist(app_path) ++ '/' ++ path
else
path
end
end

# Check if the specified path (either binary or charlist) is an absolute path
defp is_absolute_path(path) when is_list(path), do: path |> to_string() |> is_absolute_path()
defp is_absolute_path(path) when is_binary(path), do: path == Path.absname(path)

defp get_first_forms(forms) do
forms
|> List.first()
Expand Down
13 changes: 9 additions & 4 deletions lib/mix/tasks/clean_examples.ex
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
defmodule Mix.Tasks.CleanExamples do
@moduledoc """
Mix task for removing compiled files under test/examples/_build and
test/examples/erlang/_build. Usefult for getting a clean build for tests.
test/examples/erlang/_build. Useful for getting a clean build for tests.
"""

use Mix.Task

@impl true
@example_dirs [
"test/examples/_build",
"test/examples/erlang/_build"
]

@impl Mix.Task
def run(_args) do
File.rm_rf!("test/examples/_build")
File.rm_rf!("test/examples/erlang/_build")
IO.puts("Cleaning compiled examples in: " <> inspect(@example_dirs))
Enum.each(@example_dirs, &File.rm_rf!/1)
end
end
4 changes: 2 additions & 2 deletions lib/mix/tasks/gradient.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ defmodule Mix.Tasks.Gradient do

options = Enum.reduce(options, [], &prepare_option/2)

# Load dependencies
maybe_load_deps(options)
# Compile the project before the analysis
maybe_compile_project(options)
# Load dependencies
maybe_load_deps(options)
# Start Gradualizer application
Application.ensure_all_started(:gradualizer)
# Get paths to files
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule Gradient.MixProject do

def aliases do
[
# Befor testing, remove compiled test/examples files for a clean build
# Before testing, remove compiled test/examples files for a clean build
test: ["clean_examples", "test"]
]
end
Expand Down
Loading

0 comments on commit dba7c7a

Please sign in to comment.