From 2621dfc59d91cbd3c1c2f5b411610c0d2e378be1 Mon Sep 17 00:00:00 2001 From: Seb M'Caw Date: Thu, 27 Mar 2025 12:50:56 +0000 Subject: [PATCH] fix: license selection ignored by `alr init` (#1923) --- src/templates/r-crate_bin_alire_toml.ads | 24 +++--- src/templates/r-crate_lib_alire_toml.ads | 20 +++-- src/templates/r.adb | 76 +++++++++---------- support/embedder/templates.hash | 2 +- templates/crate_bin/alire.toml | 2 +- templates/crate_lib/alire.toml | 2 +- testsuite/tests/init/other-licenses/test.py | 74 ++++++++++++++++++ testsuite/tests/init/other-licenses/test.yaml | 2 + 8 files changed, 137 insertions(+), 65 deletions(-) create mode 100644 testsuite/tests/init/other-licenses/test.py create mode 100644 testsuite/tests/init/other-licenses/test.yaml diff --git a/src/templates/r-crate_bin_alire_toml.ads b/src/templates/r-crate_bin_alire_toml.ads index 7115b393..020312fc 100644 --- a/src/templates/r-crate_bin_alire_toml.ads +++ b/src/templates/r-crate_bin_alire_toml.ads @@ -26,18 +26,16 @@ package r.crate_bin_alire_toml is 115, 45, 108, 111, 103, 105, 110, 115, 32, 61, 32, 91, 34, 64, 95, 76, 79, 71, 73, 78, 95, 64, 34, 93, 10, 64, 64, 69, 78, 68, 95, 73, 70, 64, 64, 10, 108, 105, 99, 101, 110, 115, - 101, 115, 32, 61, 32, 34, 77, 73, 84, 32, 79, 82, 32, 65, - 112, 97, 99, 104, 101, 45, 50, 46, 48, 32, 87, 73, 84, 72, - 32, 76, 76, 86, 77, 45, 101, 120, 99, 101, 112, 116, 105, 111, - 110, 34, 10, 119, 101, 98, 115, 105, 116, 101, 32, 61, 32, 34, - 64, 95, 87, 69, 66, 83, 73, 84, 69, 95, 64, 34, 10, 116, - 97, 103, 115, 32, 61, 32, 91, 64, 95, 84, 65, 71, 83, 95, - 64, 93, 10, 10, 101, 120, 101, 99, 117, 116, 97, 98, 108, 101, - 115, 32, 61, 32, 91, 34, 64, 95, 76, 79, 87, 69, 82, 58, - 78, 65, 77, 69, 95, 64, 34, 93, 10, 64, 64, 73, 70, 64, - 64, 32, 64, 95, 87, 73, 84, 72, 95, 84, 69, 83, 84, 95, - 64, 10, 10, 91, 116, 101, 115, 116, 93, 10, 114, 117, 110, 110, - 101, 114, 32, 61, 32, 34, 97, 108, 105, 114, 101, 34, 10, 64, - 64, 69, 78, 68, 95, 73, 70, 64, 64, 10); + 101, 115, 32, 61, 32, 34, 64, 95, 76, 73, 67, 69, 78, 83, + 69, 83, 95, 64, 34, 10, 119, 101, 98, 115, 105, 116, 101, 32, + 61, 32, 34, 64, 95, 87, 69, 66, 83, 73, 84, 69, 95, 64, + 34, 10, 116, 97, 103, 115, 32, 61, 32, 91, 64, 95, 84, 65, + 71, 83, 95, 64, 93, 10, 10, 101, 120, 101, 99, 117, 116, 97, + 98, 108, 101, 115, 32, 61, 32, 91, 34, 64, 95, 76, 79, 87, + 69, 82, 58, 78, 65, 77, 69, 95, 64, 34, 93, 10, 64, 64, + 73, 70, 64, 64, 32, 64, 95, 87, 73, 84, 72, 95, 84, 69, + 83, 84, 95, 64, 10, 10, 91, 116, 101, 115, 116, 93, 10, 114, + 117, 110, 110, 101, 114, 32, 61, 32, 34, 97, 108, 105, 114, 101, + 34, 10, 64, 64, 69, 78, 68, 95, 73, 70, 64, 64, 10); end r.crate_bin_alire_toml; diff --git a/src/templates/r-crate_lib_alire_toml.ads b/src/templates/r-crate_lib_alire_toml.ads index 029865c1..acf157ba 100644 --- a/src/templates/r-crate_lib_alire_toml.ads +++ b/src/templates/r-crate_lib_alire_toml.ads @@ -26,16 +26,14 @@ package r.crate_lib_alire_toml is 115, 45, 108, 111, 103, 105, 110, 115, 32, 61, 32, 91, 34, 64, 95, 76, 79, 71, 73, 78, 95, 64, 34, 93, 10, 64, 64, 69, 78, 68, 95, 73, 70, 64, 64, 10, 108, 105, 99, 101, 110, 115, - 101, 115, 32, 61, 32, 34, 77, 73, 84, 32, 79, 82, 32, 65, - 112, 97, 99, 104, 101, 45, 50, 46, 48, 32, 87, 73, 84, 72, - 32, 76, 76, 86, 77, 45, 101, 120, 99, 101, 112, 116, 105, 111, - 110, 34, 10, 119, 101, 98, 115, 105, 116, 101, 32, 61, 32, 34, - 64, 95, 87, 69, 66, 83, 73, 84, 69, 95, 64, 34, 10, 116, - 97, 103, 115, 32, 61, 32, 91, 64, 95, 84, 65, 71, 83, 95, - 64, 93, 10, 64, 64, 73, 70, 64, 64, 32, 64, 95, 87, 73, - 84, 72, 95, 84, 69, 83, 84, 95, 64, 10, 10, 91, 116, 101, - 115, 116, 93, 10, 114, 117, 110, 110, 101, 114, 32, 61, 32, 34, - 97, 108, 105, 114, 101, 34, 10, 64, 64, 69, 78, 68, 95, 73, - 70, 64, 64, 10); + 101, 115, 32, 61, 32, 34, 64, 95, 76, 73, 67, 69, 78, 83, + 69, 83, 95, 64, 34, 10, 119, 101, 98, 115, 105, 116, 101, 32, + 61, 32, 34, 64, 95, 87, 69, 66, 83, 73, 84, 69, 95, 64, + 34, 10, 116, 97, 103, 115, 32, 61, 32, 91, 64, 95, 84, 65, + 71, 83, 95, 64, 93, 10, 64, 64, 73, 70, 64, 64, 32, 64, + 95, 87, 73, 84, 72, 95, 84, 69, 83, 84, 95, 64, 10, 10, + 91, 116, 101, 115, 116, 93, 10, 114, 117, 110, 110, 101, 114, 32, + 61, 32, 34, 97, 108, 105, 114, 101, 34, 10, 64, 64, 69, 78, + 68, 95, 73, 70, 64, 64, 10); end r.crate_lib_alire_toml; diff --git a/src/templates/r.adb b/src/templates/r.adb index b712eb8f..bef196d5 100644 --- a/src/templates/r.adb +++ b/src/templates/r.adb @@ -4,17 +4,17 @@ pragma Warnings (Off); pragma Style_Checks (Off); -with r.crate_bin_alire_toml; +with r.crate_test_tests_alire_toml; +with r.crate_test_tests_crate_test_tests_gpr; +with r.crate_test_tests_src_name_testsxassertions_enabled_adb; +with r.crate_test_tests_common_name_tests_ads; +with r.crate_common_gitignore_hidden; with r.crate_bin_name_gpr; +with r.crate_bin_alire_toml; with r.crate_bin_src_name_adb; -with r.crate_common_gitignore_hidden; -with r.crate_lib_alire_toml; with r.crate_lib_name_gpr; +with r.crate_lib_alire_toml; with r.crate_lib_src_name_ads; -with r.crate_test_tests_alire_toml; -with r.crate_test_tests_common_name_tests_ads; -with r.crate_test_tests_crate_test_tests_gpr; -with r.crate_test_tests_src_name_testsxassertions_enabled_adb; with Alire.Templates; with GNAT.Calendar; @@ -29,50 +29,50 @@ package body r is if not Initialized then Initialized := True; Register - ("crate_bin/alire.toml", - r.crate_bin_alire_toml.Content'Access, - GNAT.Calendar.Time_Of (2025, 03, 23, 13, 44, 33, 0.0)); + ("crate_test/tests/alire.toml", + r.crate_test_tests_alire_toml.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 26, 17, 10, 47, 0.0)); + Register + ("crate_test/tests/crate_test_tests.gpr", + r.crate_test_tests_crate_test_tests_gpr.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 26, 17, 10, 47, 0.0)); + Register + ("crate_test/tests/src/name_tests-assertions_enabled." + & "adb", + r.crate_test_tests_src_name_testsxassertions_enabled_adb.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 26, 17, 10, 47, 0.0)); + Register + ("crate_test/tests/common/name_tests.ads", + r.crate_test_tests_common_name_tests_ads.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 26, 17, 10, 47, 0.0)); + Register + ("crate_common/gitignore.hidden", + r.crate_common_gitignore_hidden.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 26, 17, 10, 47, 0.0)); Register ("crate_bin/name.gpr", r.crate_bin_name_gpr.Content'Access, - GNAT.Calendar.Time_Of (2025, 03, 23, 13, 44, 33, 0.0)); + GNAT.Calendar.Time_Of (2025, 03, 26, 17, 10, 47, 0.0)); + Register + ("crate_bin/alire.toml", + r.crate_bin_alire_toml.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 26, 17, 56, 20, 0.0)); Register ("crate_bin/src/name.adb", r.crate_bin_src_name_adb.Content'Access, - GNAT.Calendar.Time_Of (2025, 03, 23, 13, 44, 33, 0.0)); + GNAT.Calendar.Time_Of (2025, 03, 26, 17, 10, 47, 0.0)); Register - ("crate_common/gitignore.hidden", - r.crate_common_gitignore_hidden.Content'Access, - GNAT.Calendar.Time_Of (2025, 03, 23, 13, 44, 33, 0.0)); + ("crate_lib/name.gpr", + r.crate_lib_name_gpr.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 26, 17, 10, 47, 0.0)); Register ("crate_lib/alire.toml", r.crate_lib_alire_toml.Content'Access, - GNAT.Calendar.Time_Of (2025, 03, 23, 13, 44, 33, 0.0)); - Register - ("crate_lib/name.gpr", - r.crate_lib_name_gpr.Content'Access, - GNAT.Calendar.Time_Of (2025, 03, 23, 13, 44, 33, 0.0)); + GNAT.Calendar.Time_Of (2025, 03, 26, 17, 56, 20, 0.0)); Register ("crate_lib/src/name.ads", r.crate_lib_src_name_ads.Content'Access, - GNAT.Calendar.Time_Of (2025, 03, 23, 13, 44, 33, 0.0)); - Register - ("crate_test/tests/alire.toml", - r.crate_test_tests_alire_toml.Content'Access, - GNAT.Calendar.Time_Of (2025, 03, 23, 13, 44, 33, 0.0)); - Register - ("crate_test/tests/common/name_tests.ads", - r.crate_test_tests_common_name_tests_ads.Content'Access, - GNAT.Calendar.Time_Of (2025, 03, 23, 13, 47, 17, 0.0)); - Register - ("crate_test/tests/crate_test_tests.gpr", - r.crate_test_tests_crate_test_tests_gpr.Content'Access, - GNAT.Calendar.Time_Of (2025, 03, 23, 13, 44, 33, 0.0)); - Register - ("crate_test/tests/src/name_tests-assertions_enabled." - & "adb", - r.crate_test_tests_src_name_testsxassertions_enabled_adb.Content'Access, - GNAT.Calendar.Time_Of (2025, 03, 23, 14, 58, 35, 0.0)); + GNAT.Calendar.Time_Of (2025, 03, 26, 17, 10, 47, 0.0)); end if; end Init; diff --git a/support/embedder/templates.hash b/support/embedder/templates.hash index 4553fdb0..e1eda064 100644 --- a/support/embedder/templates.hash +++ b/support/embedder/templates.hash @@ -1 +1 @@ -c75b12dca0d586a0869a7ab3689acc750a461e2760517ff00efda577e9f2a068 +e4fc366ad747fdc58cf8fa18f5706a6851e2e67e1a511a3c8f45440e5407b5a8 diff --git a/templates/crate_bin/alire.toml b/templates/crate_bin/alire.toml index 0efd1f29..9ac959ce 100644 --- a/templates/crate_bin/alire.toml +++ b/templates/crate_bin/alire.toml @@ -7,7 +7,7 @@ maintainers = ["@_USERNAME_@ <@_EMAIL_@>"] @@IF@@ @_LOGIN_@ /= "" maintainers-logins = ["@_LOGIN_@"] @@END_IF@@ -licenses = "MIT OR Apache-2.0 WITH LLVM-exception" +licenses = "@_LICENSES_@" website = "@_WEBSITE_@" tags = [@_TAGS_@] diff --git a/templates/crate_lib/alire.toml b/templates/crate_lib/alire.toml index 0b028d8d..4d0fb8cb 100644 --- a/templates/crate_lib/alire.toml +++ b/templates/crate_lib/alire.toml @@ -7,7 +7,7 @@ maintainers = ["@_USERNAME_@ <@_EMAIL_@>"] @@IF@@ @_LOGIN_@ /= "" maintainers-logins = ["@_LOGIN_@"] @@END_IF@@ -licenses = "MIT OR Apache-2.0 WITH LLVM-exception" +licenses = "@_LICENSES_@" website = "@_WEBSITE_@" tags = [@_TAGS_@] @@IF@@ @_WITH_TEST_@ diff --git a/testsuite/tests/init/other-licenses/test.py b/testsuite/tests/init/other-licenses/test.py new file mode 100644 index 00000000..05d93027 --- /dev/null +++ b/testsuite/tests/init/other-licenses/test.py @@ -0,0 +1,74 @@ +""" +Check that the user can specify valid SPDX license expressions +""" + + +import os +import shutil + +from drivers.alr import run_alr, run_alr_interactive +from drivers.asserts import assert_substring +from drivers.helpers import content_of + + +# License expressions which should be accepted +valid_licenses = [ + "MIT", "custom-abc", +] +for license_str in valid_licenses: + print(license_str) + # Run interactively + run_alr_interactive(["init", "--bin", "xxx"], + output=["> " for _ in range(8)], + input=["", # Description + "", # Full user name + "", # Github login + "", # Email + "9", # License (select "Other...") + license_str, # License string + "", # Tags + ""], # Website + timeout=3) + + # Check that it can be shown, which will load the manifest + os.chdir("xxx") + p = run_alr("show") + + # Check that the manifest and the output of `alr show` actually contain the + # selected license + assert_substring(f'licenses = "{license_str}"', content_of("alire.toml")) + assert_substring(f"License: {license_str}", p.out) + + # Prepare for next iteration + os.chdir("..") + shutil.rmtree("xxx") + + +# License expressions which should be rejected entirely +bad_licenses = [ + "/", "test:test", "MIT WITH test" +] +for license_str in bad_licenses: + # Run interactively + run_alr_interactive(["init", "--bin", "xxx"], + output=( + ["> " for _ in range(6)] + + ["Invalid SPDX license expression"] + + ["> " for _ in range(3)] + ), + input=["", # Description + "", # Full user name + "", # Github login + "", # Email + "9", # License (select "Other...") + license_str, # License string + "MIT", # License string (valid this time) + "", # Tags + ""], # Website + timeout=3) + + # Prepare for next iteration + shutil.rmtree("xxx") + + +print('SUCCESS') diff --git a/testsuite/tests/init/other-licenses/test.yaml b/testsuite/tests/init/other-licenses/test.yaml new file mode 100644 index 00000000..187c05aa --- /dev/null +++ b/testsuite/tests/init/other-licenses/test.yaml @@ -0,0 +1,2 @@ +driver: python-script +indexes: {} -- 2.39.5