-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow config for the remote Libretro core repos
- Loading branch information
1 parent
535e725
commit f78bcf3
Showing
15 changed files
with
219 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package manager | ||
|
||
import "strings" | ||
|
||
type ArchInfo struct { | ||
Arch string | ||
Ext string | ||
Os string | ||
Vendor string | ||
} | ||
|
||
type Data struct { | ||
Url string | ||
Compression string | ||
} | ||
|
||
type Repository interface { | ||
CoreUrl(file string, info ArchInfo) (url string) | ||
} | ||
|
||
// Repo defines a simple zip file containing all the cores that will be extracted as is. | ||
type Repo struct { | ||
Address string | ||
Compression string | ||
} | ||
|
||
func (r Repo) CoreUrl(_ string, _ ArchInfo) string { return r.Address } | ||
|
||
type Buildbot struct{ Repo } | ||
|
||
func (r Buildbot) CoreUrl(file string, info ArchInfo) string { | ||
var sb strings.Builder | ||
sb.WriteString(r.Address + "/") | ||
if info.Vendor != "" { | ||
sb.WriteString(info.Vendor + "/") | ||
} | ||
sb.WriteString(info.Os + "/" + info.Arch + "/latest/" + file + info.Ext) | ||
if r.Compression != "" { | ||
sb.WriteString("." + r.Compression) | ||
} | ||
return sb.String() | ||
} | ||
|
||
type Github struct{ Buildbot } | ||
|
||
func (r Github) CoreUrl(file string, info ArchInfo) string { | ||
return r.Buildbot.CoreUrl(file, info) + "?raw=true" | ||
} | ||
|
||
func NewRepo(kind string, url string, compression string, defaultRepo string) Repository { | ||
var repository Repository | ||
switch kind { | ||
case "buildbot": | ||
repository = Buildbot{Repo{Address: url, Compression: compression}} | ||
case "github": | ||
repository = Github{Buildbot{Repo{Address: url, Compression: compression}}} | ||
case "raw": | ||
repository = Repo{Address: url, Compression: "zip"} | ||
default: | ||
if defaultRepo != "" { | ||
repository = NewRepo(defaultRepo, url, compression, "") | ||
} | ||
} | ||
return repository | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package manager | ||
|
||
import "testing" | ||
|
||
func TestCoreUrl(t *testing.T) { | ||
testAddress := "https://test.me" | ||
tests := []struct { | ||
arch ArchInfo | ||
compress string | ||
f string | ||
repo string | ||
result string | ||
}{ | ||
{ | ||
arch: ArchInfo{Arch: "x86_64", Ext: ".so", Os: "linux"}, | ||
f: "uber_core", | ||
repo: "buildbot", | ||
result: testAddress + "/" + "linux/x86_64/latest/uber_core.so", | ||
}, | ||
{ | ||
arch: ArchInfo{Arch: "x86_64", Ext: ".so", Os: "linux"}, | ||
compress: "zip", | ||
f: "uber_core", | ||
repo: "buildbot", | ||
result: testAddress + "/" + "linux/x86_64/latest/uber_core.so.zip", | ||
}, | ||
{ | ||
arch: ArchInfo{Arch: "x86_64", Ext: ".dylib", Os: "osx", Vendor: "apple"}, | ||
f: "uber_core", | ||
repo: "buildbot", | ||
result: testAddress + "/" + "apple/osx/x86_64/latest/uber_core.dylib", | ||
}, | ||
{ | ||
arch: ArchInfo{Os: "linux", Arch: "x86_64", Ext: ".so"}, | ||
f: "uber_core", | ||
repo: "github", | ||
result: testAddress + "/" + "linux/x86_64/latest/uber_core.so?raw=true", | ||
}, | ||
{ | ||
arch: ArchInfo{Os: "linux", Arch: "x86_64", Ext: ".so"}, | ||
compress: "zip", | ||
f: "uber_core", | ||
repo: "github", | ||
result: testAddress + "/" + "linux/x86_64/latest/uber_core.so.zip?raw=true", | ||
}, | ||
{ | ||
arch: ArchInfo{Os: "osx", Arch: "x86_64", Vendor: "apple", Ext: ".dylib"}, | ||
f: "uber_core", | ||
repo: "github", | ||
result: testAddress + "/" + "apple/osx/x86_64/latest/uber_core.dylib?raw=true", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
r := NewRepo(test.repo, testAddress, test.compress, "") | ||
url := r.CoreUrl(test.f, test.arch) | ||
if url != test.result { | ||
t.Errorf("seems that expected link address is incorrect (%v) for file %s %+v", url, test.f, test.arch) | ||
} | ||
} | ||
} |
Oops, something went wrong.