Merge pull request 'fix: remove duplicates correctly' (#46) from Maks1mS/ALR:fix/remove-duplicates-correctly into master

Reviewed-on: #46
This commit is contained in:
Евгений Храмов 2025-03-13 13:44:40 +00:00
commit 9cf8af08ab
6 changed files with 116 additions and 49 deletions

@ -11,7 +11,7 @@
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="33.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
<text x="33.5" y="14">coverage</text>
<text x="86" y="15" fill="#010101" fill-opacity=".3">19.5%</text>
<text x="86" y="14">19.5%</text>
<text x="86" y="15" fill="#010101" fill-opacity=".3">19.8%</text>
<text x="86" y="14">19.8%</text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 926 B

After

Width:  |  Height:  |  Size: 926 B

@ -365,69 +365,69 @@ msgstr ""
msgid "Building package"
msgstr ""
#: pkg/build/build.go:231
#: pkg/build/build.go:208
msgid "The checksums array must be the same length as sources"
msgstr ""
#: pkg/build/build.go:235
msgid "Downloading sources"
msgstr ""
#: pkg/build/build.go:253
#: pkg/build/build.go:257
msgid "Building package metadata"
msgstr ""
#: pkg/build/build.go:275
#: pkg/build/build.go:279
msgid "Compressing package"
msgstr ""
#: pkg/build/build.go:434
#: pkg/build/build.go:438
msgid ""
"Your system's CPU architecture doesn't match this package. Do you want to "
"build anyway?"
msgstr ""
#: pkg/build/build.go:448
#: pkg/build/build.go:452
msgid "This package is already installed"
msgstr ""
#: pkg/build/build.go:472
#: pkg/build/build.go:476
msgid "Installing build dependencies"
msgstr ""
#: pkg/build/build.go:513
#: pkg/build/build.go:517
msgid "Installing dependencies"
msgstr ""
#: pkg/build/build.go:548
msgid "The checksums array must be the same length as sources"
msgstr ""
#: pkg/build/build.go:599
#: pkg/build/build.go:598
msgid "Would you like to remove the build dependencies?"
msgstr ""
#: pkg/build/build.go:662
#: pkg/build/build.go:661
msgid "Executing prepare()"
msgstr ""
#: pkg/build/build.go:672
#: pkg/build/build.go:671
msgid "Executing build()"
msgstr ""
#: pkg/build/build.go:702 pkg/build/build.go:722
#: pkg/build/build.go:701 pkg/build/build.go:721
msgid "Executing %s()"
msgstr ""
#: pkg/build/build.go:781
#: pkg/build/build.go:780
msgid "Error installing native packages"
msgstr ""
#: pkg/build/build.go:805
#: pkg/build/build.go:804
msgid "Error installing package"
msgstr ""
#: pkg/build/build.go:864
#: pkg/build/build.go:863
msgid "AutoProv is not implemented for this package format, so it's skipped"
msgstr ""
#: pkg/build/build.go:875
#: pkg/build/build.go:874
msgid "AutoReq is not implemented for this package format, so it's skipped"
msgstr ""

@ -12,8 +12,8 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"X-Generator: Gtranslator 47.1\n"
#: build.go:44
@ -379,19 +379,23 @@ msgstr "Не удалось предложить пользователю про
msgid "Building package"
msgstr "Сборка пакета"
#: pkg/build/build.go:231
#: pkg/build/build.go:208
msgid "The checksums array must be the same length as sources"
msgstr "Массив контрольных сумм должен быть той же длины, что и источники"
#: pkg/build/build.go:235
msgid "Downloading sources"
msgstr "Скачивание источников"
#: pkg/build/build.go:253
#: pkg/build/build.go:257
msgid "Building package metadata"
msgstr "Сборка метаданных пакета"
#: pkg/build/build.go:275
#: pkg/build/build.go:279
msgid "Compressing package"
msgstr "Сжатие пакета"
#: pkg/build/build.go:434
#: pkg/build/build.go:438
msgid ""
"Your system's CPU architecture doesn't match this package. Do you want to "
"build anyway?"
@ -399,52 +403,48 @@ msgstr ""
"Архитектура процессора вашей системы не соответствует этому пакету. Вы все "
"равно хотите выполнить сборку?"
#: pkg/build/build.go:448
#: pkg/build/build.go:452
msgid "This package is already installed"
msgstr "Этот пакет уже установлен"
#: pkg/build/build.go:472
#: pkg/build/build.go:476
msgid "Installing build dependencies"
msgstr "Установка зависимостей сборки"
#: pkg/build/build.go:513
#: pkg/build/build.go:517
msgid "Installing dependencies"
msgstr "Установка зависимостей"
#: pkg/build/build.go:548
msgid "The checksums array must be the same length as sources"
msgstr "Массив контрольных сумм должен быть той же длины, что и источники"
#: pkg/build/build.go:599
#: pkg/build/build.go:598
msgid "Would you like to remove the build dependencies?"
msgstr "Хотели бы вы удалить зависимости сборки?"
#: pkg/build/build.go:662
#: pkg/build/build.go:661
msgid "Executing prepare()"
msgstr "Исполнение prepare()"
#: pkg/build/build.go:672
#: pkg/build/build.go:671
msgid "Executing build()"
msgstr "Исполнение build()"
#: pkg/build/build.go:702 pkg/build/build.go:722
#: pkg/build/build.go:701 pkg/build/build.go:721
msgid "Executing %s()"
msgstr "Исполнение %s()"
#: pkg/build/build.go:781
#: pkg/build/build.go:780
msgid "Error installing native packages"
msgstr "Ошибка при установке нативных пакетов"
#: pkg/build/build.go:805
#: pkg/build/build.go:804
msgid "Error installing package"
msgstr "Ошибка при установке пакета"
#: pkg/build/build.go:864
#: pkg/build/build.go:863
msgid "AutoProv is not implemented for this package format, so it's skipped"
msgstr ""
"AutoProv не реализовано для этого формата пакета, поэтому будет пропущено"
#: pkg/build/build.go:875
#: pkg/build/build.go:874
msgid "AutoReq is not implemented for this package format, so it's skipped"
msgstr ""
"AutoReq не реализовано для этого формата пакета, поэтому будет пропущено"

@ -203,8 +203,12 @@ func (b *Builder) BuildPackage(ctx context.Context) ([]string, []string, error)
buildDepends = removeDuplicates(buildDepends)
optDepends = removeDuplicates(optDepends)
depends = removeDuplicates(depends)
sources = removeDuplicates(sources)
checksums = removeDuplicates(checksums)
if len(sources) != len(checksums) {
slog.Error(gotext.Get("The checksums array must be the same length as sources"))
os.Exit(1)
}
sources, checksums = removeDuplicatesSources(sources, checksums)
mergedVars := types.BuildVars{
Sources: sources,
@ -544,11 +548,6 @@ func (b *Builder) buildALRDeps(ctx context.Context, depends []string) (builtPath
}
func (b *Builder) getSources(ctx context.Context, dirs types.Directories, bv *types.BuildVars) error {
if len(bv.Sources) != len(bv.Checksums) {
slog.Error(gotext.Get("The checksums array must be the same length as sources"))
os.Exit(1)
}
for i, src := range bv.Sources {
opts := dl.Options{
Name: fmt.Sprintf("%s[%d]", bv.Name, i),

@ -313,3 +313,24 @@ func removeDuplicates(slice []string) []string {
return result
}
func removeDuplicatesSources(sources, checksums []string) ([]string, []string) {
seen := map[string]string{}
keys := make([]string, 0)
for i, s := range sources {
if val, ok := seen[s]; !ok || strings.EqualFold(val, "SKIP") {
if !ok {
keys = append(keys, s)
}
seen[s] = checksums[i]
}
}
newSources := make([]string, len(keys))
newChecksums := make([]string, len(keys))
for i, k := range keys {
newSources[i] = k
newChecksums[i] = seen[k]
}
return newSources, newChecksums
}

@ -0,0 +1,47 @@
// ALR - Any Linux Repository
// Copyright (C) 2025 Евгений Храмов
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package build
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRemoveDuplicatesSources(t *testing.T) {
type testCase struct {
Name string
Sources []string
Checksums []string
NewSources []string
NewChecksums []string
}
for _, tc := range []testCase{{
Name: "prefer non-skip values",
Sources: []string{"a", "b", "c", "a"},
Checksums: []string{"skip", "skip", "skip", "1"},
NewSources: []string{"a", "b", "c"},
NewChecksums: []string{"1", "skip", "skip"},
}} {
t.Run(tc.Name, func(t *testing.T) {
s, c := removeDuplicatesSources(tc.Sources, tc.Checksums)
assert.Equal(t, s, tc.NewSources)
assert.Equal(t, c, tc.NewChecksums)
})
}
}