Skip to content

Commit 711236f

Browse files
committed
Clean up --output flag for "mix sentry.package_source_code"
1 parent 4f111f6 commit 711236f

File tree

4 files changed

+24
-50
lines changed

4 files changed

+24
-50
lines changed

lib/mix/tasks/sentry.package_source_code.ex

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,18 @@ defmodule Mix.Tasks.Sentry.PackageSourceCode do
4343
> source-context-related options in compile-time config files (like `config/config.exs`
4444
> or `config/prod.exs`).
4545
46-
> #### Building with Nix {: .tip}
47-
>
48-
> If you build your application using nixpkgs' `mixRelease`,
49-
> `mix sentry.package_source_code` will fail, because Sentry's source is read-only.
50-
>
51-
> To fix this, you can use the `--output` option to write the map file to a writable location,
52-
> then copy it to Sentry's `priv` in the final OTP release.
53-
>
54-
> Example:
55-
>
56-
> ```nix
57-
> mixRelease {
58-
> preBuild = ''
59-
> mix sentry.package_source_code --output sentry.map
60-
> '';
61-
>
62-
> postInstall = ''
63-
> sentryPrivDir="$(find $out/lib -maxdepth 1 -name "sentry-*")/priv"
64-
> mkdir "$sentryPrivDir"
65-
> cp -a sentry.map "$sentryPrivDir"
66-
> '';
67-
> }
68-
> ```
69-
7046
## Options
7147
7248
* `--debug` - print more information about collecting and encoding source code
73-
* `--output path` - write file to the given path. Example: `path/to/sentry.map`
49+
* `--output PATH` - write source map file to the given `PATH`. If you don't specify
50+
this option, the file will be written to the default path, which is inside the `priv`
51+
directory of the `:sentry` application. If you use this option, remember to also
52+
**configure the `:source_code_map_path` option**, otherwise Sentry will try to
53+
*read* the file from the default location. See `Sentry` for more information.
54+
This option can be useful when the source
55+
`priv` directory is read-only, such as with [NixOS](https://github.com/NixOS/nixpkgs)
56+
and similar tools.
57+
*Available since v10.2.0*.
7458
7559
"""
7660

lib/sentry/config.ex

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ defmodule Sentry.Config do
6161
The name of the server running the application. Not used by default.
6262
"""
6363
],
64-
source_code_map_path: [
65-
type: {:custom, __MODULE__, :__validate_path__, []},
66-
default: nil,
67-
type_doc: "`t:Path.t/0` or `nil`",
68-
doc: """
69-
The path to the map file when mix task `sentry.package_source_code` was invoked with
70-
`--output path/to/file.map`
71-
"""
72-
],
7364
sample_rate: [
7465
type: {:custom, __MODULE__, :__validate_sample_rate__, []},
7566
default: 1.0,
@@ -254,6 +245,15 @@ defmodule Sentry.Config do
254245
exclude from source code context.
255246
"""
256247
],
248+
source_code_map_path: [
249+
type: :string,
250+
type_doc: "`t:Path.t/0`",
251+
doc: """
252+
The path to the source code map file. See
253+
[`mix sentry.package_source_code`](`Mix.Tasks.Sentry.PackageSourceCode`).
254+
Defaults to a private path inside Sentry's `priv` directory. *Available since v10.2.0*.
255+
"""
256+
],
257257
context_lines: [
258258
type: :pos_integer,
259259
default: 3,

lib/sentry/sources.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ defmodule Sentry.Sources do
1414

1515
# Default argument is here for testing.
1616
@spec load_source_code_map_if_present(Path.t()) :: {:loaded, source_map()} | {:error, term()}
17-
def load_source_code_map_if_present(
18-
path \\ Config.source_code_map_path() || path_of_packaged_source_code()
19-
) do
17+
def load_source_code_map_if_present(path_for_tests \\ nil) do
18+
path = path_for_tests || Config.source_code_map_path() || path_of_packaged_source_code()
2019
path = Path.relative_to_cwd(path)
2120

2221
with {:ok, contents} <- File.read(path),

test/sentry/config_test.exs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,11 @@ defmodule Sentry.ConfigTest do
5050
end
5151
end
5252

53-
@tag :tmp_dir
54-
test ":source_code_map_path from option", %{tmp_dir: tmp_dir} do
55-
source_code_map_path = Path.join([tmp_dir, "test.map"])
53+
test ":source_code_map_path from option" do
54+
assert Config.validate!()[:source_code_map_path] == nil
5655

57-
assert Config.validate!(source_code_map_path: nil)[:source_code_map_path] == nil
58-
59-
assert_raise ArgumentError, ~r/path does not exist/, fn ->
60-
assert Config.validate!(source_code_map_path: source_code_map_path)
61-
end
62-
63-
File.touch!(source_code_map_path)
64-
65-
assert Config.validate!(source_code_map_path: source_code_map_path)[:source_code_map_path] ==
66-
source_code_map_path
56+
assert Config.validate!(source_code_map_path: "test.map")[:source_code_map_path] ==
57+
"test.map"
6758
end
6859

6960
test ":release from option" do

0 commit comments

Comments
 (0)