this repo has no description

Add erlang.application_start_argument configuration

+100 -9
+6
CHANGELOG.md
··· 226 226 227 227 ([sobolevn](https://github.com/sobolevn)) 228 228 229 + - The `erlang.application_start_argument` parameter has been added to 230 + `gleam.toml`. This is a string containing an Erlang term that will be written 231 + into the package's Erlang `.app` file if `erlang.application_start_module` 232 + has been set, replacing the default argument of `[]`. 233 + ([Louis Pilfold](https://github.com/lpil)) 234 + 229 235 - Generated code for the JavaScript target now includes a public API which can 230 236 be used for FFI interacting with Gleam custom types. For example, if you have 231 237 this Gleam code:
+1
compiler-cli/src/dependencies/tests.rs
··· 1180 1180 links: vec![], 1181 1181 erlang: ErlangConfig { 1182 1182 application_start_module: None, 1183 + application_start_argument: None, 1183 1184 extra_applications: vec![], 1184 1185 }, 1185 1186 javascript: JavaScriptConfig {
+11 -6
compiler-core/src/codegen.rs
··· 104 104 105 105 let path = self.output_directory.join(format!("{}.app", &config.name)); 106 106 107 - let start_module = config 108 - .erlang 109 - .application_start_module 110 - .as_ref() 111 - .map(|module| tuple("mod", &format!("{{'{}', []}}", module_erlang_name(module)))) 112 - .unwrap_or_default(); 107 + let start_module = match config.erlang.application_start_module.as_ref() { 108 + None => "".into(), 109 + Some(module) => { 110 + let module = module_erlang_name(module); 111 + let argument = match config.erlang.application_start_argument.as_ref() { 112 + Some(argument) => argument.as_str(), 113 + None => "[]", 114 + }; 115 + tuple("mod", &format!("{{'{module}', {argument}}}")) 116 + } 117 + }; 113 118 114 119 let modules = modules 115 120 .iter()
+8
compiler-core/src/config.rs
··· 708 708 709 709 #[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Default, Clone)] 710 710 pub struct ErlangConfig { 711 + /// An module that can be set in the `.app` file as the entrypoint for a stateful application 712 + /// that defines a singleton supervision tree. 713 + /// Erlang syntax. 711 714 #[serde(default)] 712 715 pub application_start_module: Option<EcoString>, 716 + /// The argument for the start module start function. If not set then `[]` is used as the 717 + /// default argument. 718 + /// Erlang syntax. 719 + #[serde(default)] 720 + pub application_start_argument: Option<EcoString>, 713 721 #[serde(default)] 714 722 pub extra_applications: Vec<EcoString>, 715 723 }
+2 -1
compiler-core/src/snapshots/gleam_core__config__barebones_package_config_to_json.snap
··· 1 1 --- 2 2 source: compiler-core/src/config.rs 3 - assertion_line: 1116 3 + assertion_line: 1187 4 4 expression: output 5 5 snapshot_kind: text 6 6 --- ··· 27 27 "links": [], 28 28 "erlang": { 29 29 "application_start_module": null, 30 + "application_start_argument": null, 30 31 "extra_applications": [] 31 32 }, 32 33 "javascript": {
+2 -1
compiler-core/src/snapshots/gleam_core__config__package_config_to_json.snap
··· 1 1 --- 2 2 source: compiler-core/src/config.rs 3 - assertion_line: 1106 3 + assertion_line: 1171 4 4 expression: output 5 5 snapshot_kind: text 6 6 --- ··· 90 90 ], 91 91 "erlang": { 92 92 "application_start_module": "my_app/application", 93 + "application_start_argument": null, 93 94 "extra_applications": [ 94 95 "inets", 95 96 "ssl"
+1
compiler-core/src/snapshots/gleam_core__docs__barebones_package_config_to_json.snap
··· 28 28 "links": [], 29 29 "erlang": { 30 30 "application_start_module": null, 31 + "application_start_argument": null, 31 32 "extra_applications": [] 32 33 }, 33 34 "javascript": {
+2 -1
compiler-core/src/snapshots/gleam_core__docs__package_config_to_json.snap
··· 1 1 --- 2 2 source: compiler-core/src/docs.rs 3 - assertion_line: 765 3 + assertion_line: 769 4 4 expression: output 5 5 snapshot_kind: text 6 6 --- ··· 91 91 ], 92 92 "erlang": { 93 93 "application_start_module": "my_app/application", 94 + "application_start_argument": null, 94 95 "extra_applications": [ 95 96 "inets", 96 97 "ssl"
+22
test-package-compiler/cases/erlang_app_generation_with_argument/gleam.toml
··· 1 + # This config file has a bunch of properties that will be entered into the 2 + # Erlang .app file 3 + 4 + name = "my_erlang_application" # <- 5 + version = "0.1.0" # <- 6 + description = "It's very cool" # <- 7 + 8 + target = "erlang" 9 + 10 + [erlang] 11 + extra_applications = ["inets", "ssl"] # <- 12 + application_start_module = "my_erlang_application_sup" # <- 13 + application_start_argument = "[1, two]" # <- 14 + 15 + [dependencies] # <- 16 + gleam_stdlib = "~> 1337.0" 17 + gleam_otp = "~> 1337.0" 18 + 19 + [dev-dependencies] # <- 20 + midas = "~> 1337.0" 21 + simple_json = "~> 1337.0" 22 +
+1
test-package-compiler/cases/erlang_app_generation_with_argument/src/main.gleam
··· 1 +
+11
test-package-compiler/src/generated_tests.rs
··· 69 69 70 70 #[rustfmt::skip] 71 71 #[test] 72 + fn erlang_app_generation_with_argument() { 73 + let output = crate::prepare("./cases/erlang_app_generation_with_argument"); 74 + insta::assert_snapshot!( 75 + "erlang_app_generation_with_argument", 76 + output, 77 + "./cases/erlang_app_generation_with_argument", 78 + ); 79 + } 80 + 81 + #[rustfmt::skip] 82 + #[test] 72 83 fn erlang_bug_752() { 73 84 let output = crate::prepare("./cases/erlang_bug_752"); 74 85 insta::assert_snapshot!(
+33
test-package-compiler/src/snapshots/test_package_compiler__generated_tests__erlang_app_generation_with_argument.snap
··· 1 + --- 2 + source: test-package-compiler/src/generated_tests.rs 3 + assertion_line: 74 4 + expression: "./cases/erlang_app_generation_with_argument" 5 + snapshot_kind: text 6 + --- 7 + //// /out/lib/the_package/_gleam_artefacts/main.cache 8 + <.cache binary> 9 + 10 + //// /out/lib/the_package/_gleam_artefacts/main.cache_inline 11 + <8 byte binary> 12 + 13 + //// /out/lib/the_package/_gleam_artefacts/main.cache_meta 14 + <57 byte binary> 15 + 16 + //// /out/lib/the_package/_gleam_artefacts/main.erl 17 + -module(main). 18 + 19 + 20 + //// /out/lib/the_package/ebin/my_erlang_application.app 21 + {application, my_erlang_application, [ 22 + {mod, {'my_erlang_application_sup', [1, two]}}, 23 + {vsn, "0.1.0"}, 24 + {applications, [gleam_otp, 25 + gleam_stdlib, 26 + inets, 27 + midas, 28 + simple_json, 29 + ssl]}, 30 + {description, "It's very cool"}, 31 + {modules, [main]}, 32 + {registered, []} 33 + ]}.