Merge pull request 'update to V 0.3.3' (#347) from Chewing_Bever/vieter:v-0.3.3 into dev

Reviewed-on: vieter-v/vieter#347
dev
Jef Roosens 2023-02-19 16:03:02 +01:00
commit 69cc2404db
63 changed files with 267 additions and 261 deletions

View File

@ -10,6 +10,7 @@ skip_clone: true
pipeline:
build:
image: 'git.rustybever.be/vieter-v/vieter-builder'
pull: true
commands:
# Add the vieter repository so we can use the compiler
- echo -e '[vieter]\nServer = https://arch.r8r.be/$repo/$arch\nSigLevel = Optional' >> /etc/pacman.conf

View File

@ -10,6 +10,7 @@ skip_clone: true
pipeline:
build:
image: 'git.rustybever.be/vieter-v/vieter-builder'
pull: true
commands:
# Add the vieter repository so we can use the compiler
- echo -e '[vieter]\nServer = https://arch.r8r.be/$repo/$arch\nSigLevel = Optional' >> /etc/pacman.conf

View File

@ -1,5 +1,5 @@
variables:
- &vlang_image 'git.rustybever.be/chewing_bever/vlang:0.3.2-alpine3.17'
- &vlang_image 'git.rustybever.be/vieter/vlang:5d4c9dc9fc11bf8648541c934adb64f27cb94e37-alpine3.17'
matrix:
PLATFORM:

View File

@ -1,5 +1,5 @@
variables:
- &vlang_image 'git.rustybever.be/chewing_bever/vlang:0.3.2-alpine3.17'
- &vlang_image 'git.rustybever.be/vieter/vlang:5d4c9dc9fc11bf8648541c934adb64f27cb94e37-alpine3.17'
platform: 'linux/amd64'
branches:
@ -21,8 +21,9 @@ pipeline:
- make api-docs
slate-docs:
image: 'slatedocs/slate'
image: 'slatedocs/slate:v2.13.0'
group: 'generate'
# Slate requires a specific directory to run in
commands:
- cd docs/api
- bundle exec middleman build --clean

View File

@ -1,5 +1,5 @@
variables:
- &vlang_image 'git.rustybever.be/chewing_bever/vlang:0.3.2-alpine3.17'
- &vlang_image 'git.rustybever.be/vieter/vlang:5d4c9dc9fc11bf8648541c934adb64f27cb94e37-alpine3.17'
platform: 'linux/amd64'
branches: [ 'main' ]

View File

@ -1,5 +1,5 @@
variables:
- &vlang_image 'git.rustybever.be/chewing_bever/vlang:0.3.2-alpine3.17'
- &vlang_image 'git.rustybever.be/vieter/vlang:5d4c9dc9fc11bf8648541c934adb64f27cb94e37-alpine3.17'
# These checks already get performed on the feature branches
branches:

View File

@ -1,5 +1,5 @@
variables:
- &vlang_image 'git.rustybever.be/chewing_bever/vlang:0.3.2-alpine3.17'
- &vlang_image 'git.rustybever.be/vieter/vlang:5d4c9dc9fc11bf8648541c934adb64f27cb94e37-alpine3.17'
platform: 'linux/amd64'
branches:

View File

@ -1,5 +1,5 @@
variables:
- &vlang_image 'git.rustybever.be/chewing_bever/vlang:0.3.2-alpine3.17'
- &vlang_image 'git.rustybever.be/vieter/vlang:5d4c9dc9fc11bf8648541c934adb64f27cb94e37-alpine3.17'
matrix:
PLATFORM:

View File

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
* Rewrote cron expression logic in C
* Updated codebase to V commit after 0.3.3
### Removed

View File

@ -3,7 +3,7 @@ SRC_DIR := src
SRCS != find '$(SRC_DIR)' -iname '*.v'
V_PATH ?= v
V := $(V_PATH) -showcc -gc boehm -W -d use_openssl -skip-unused
V := $(V_PATH) -showcc -gc boehm -d use_openssl -skip-unused
all: vieter

View File

@ -7,7 +7,7 @@ pkgver='0.5.0'
pkgrel=1
pkgdesc="Lightweight Arch repository server & package build system"
depends=('glibc' 'openssl' 'libarchive' 'sqlite')
makedepends=('git' 'vlang')
makedepends=('git' 'vieter-vlang')
arch=('x86_64' 'aarch64')
url='https://git.rustybever.be/vieter-v/vieter'
license=('AGPL3')

View File

@ -7,7 +7,7 @@ pkgver=0.2.0.r25.g20112b8
pkgrel=1
pkgdesc="Lightweight Arch repository server & package build system (development version)"
depends=('glibc' 'openssl' 'libarchive' 'sqlite')
makedepends=('git' 'vlang')
makedepends=('git' 'vieter-vlang')
arch=('x86_64' 'aarch64')
url='https://git.rustybever.be/vieter-v/vieter'
license=('AGPL3')

View File

@ -48,9 +48,9 @@ update`.
### Compiler
I used to maintain a mirror that tracked the latest master, but nowadays, I
maintain a Docker image containing the specific compiler version that Vieter
builds with. Currently, this is V 0.3.2.
V is developed using a specific compiler commit that is usually updated
whenever a new version is released. Information on this can be found in the
[tools](https://git.rustybever.be/vieter-v/tools) repository.
## Contributing

View File

@ -23,9 +23,9 @@ pub fn cmd() cli.Command {
description: 'Start an agent daemon.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
agent(conf)!
agent(conf_)!
}
}
}

View File

@ -51,7 +51,7 @@ pub fn (mut d AgentDaemon) run() {
for {
if sleep_time > 0 {
d.ldebug('Sleeping for $sleep_time')
d.ldebug('Sleeping for ${sleep_time}')
time.sleep(sleep_time)
}
@ -80,14 +80,14 @@ pub fn (mut d AgentDaemon) run() {
d.ldebug('Polling for new jobs')
new_configs := d.client.poll_jobs(d.conf.arch, finished + empty) or {
d.lerror('Failed to poll jobs: $err.msg()')
d.lerror('Failed to poll jobs: ${err.msg()}')
// TODO pick a better delay here
sleep_time = 5 * time.second
continue
}
d.ldebug('Received $new_configs.len jobs')
d.ldebug('Received ${new_configs.len} jobs')
last_poll_time = time.now()
@ -95,7 +95,7 @@ pub fn (mut d AgentDaemon) run() {
// Make sure a recent build base image is available for
// building the config
if !d.images.up_to_date(config.base_image) {
d.linfo('Building builder image from base image $config.base_image')
d.linfo('Building builder image from base image ${config.base_image}')
// TODO handle this better than to just skip the config
d.images.refresh_image(config.base_image) or {
@ -154,7 +154,7 @@ fn (mut d AgentDaemon) start_build(config BuildConfig) bool {
stdatomic.store_u64(&d.atomics[i], agent.build_running)
d.builds[i] = config
go d.run_build(i, config)
spawn d.run_build(i, config)
return true
}
@ -165,7 +165,7 @@ fn (mut d AgentDaemon) start_build(config BuildConfig) bool {
// run_build actually starts the build process for a given target.
fn (mut d AgentDaemon) run_build(build_index int, config BuildConfig) {
d.linfo('started build: $config')
d.linfo('started build: ${config}')
// 0 means success, 1 means failure
mut status := 0
@ -176,21 +176,21 @@ fn (mut d AgentDaemon) run_build(build_index int, config BuildConfig) {
}
res := build.build_config(d.client.address, d.client.api_key, new_config) or {
d.ldebug('build_config error: $err.msg()')
d.ldebug('build_config error: ${err.msg()}')
status = 1
build.BuildResult{}
}
if status == 0 {
d.linfo('Uploading build logs for $config')
d.linfo('Uploading build logs for ${config}')
// TODO use the arch value here
build_arch := os.uname().machine
d.client.add_build_log(config.target_id, res.start_time, res.end_time, build_arch,
res.exit_code, res.logs) or { d.lerror('Failed to upload logs for $config') }
res.exit_code, res.logs) or { d.lerror('Failed to upload logs for ${config}') }
} else {
d.lwarn('an error occurred during build: $config')
d.lwarn('an error occurred during build: ${config}')
}
stdatomic.store_u64(&d.atomics[build_index], agent.build_done)

View File

@ -71,7 +71,7 @@ pub fn (mut m ImageManager) up_to_date(base_image string) bool {
fn (mut m ImageManager) refresh_image(base_image string) ! {
// TODO use better image tags for built images
new_image := build.create_build_image(base_image) or {
return error('Failed to build builder image from base image $base_image')
return error('Failed to build builder image from base image ${base_image}')
}
m.images[base_image] << new_image

View File

@ -45,7 +45,7 @@ pub fn create_build_image(base_image string) !string {
c := docker.NewContainer{
image: base_image
env: ['BUILD_SCRIPT=$cmds_str']
env: ['BUILD_SCRIPT=${cmds_str}']
entrypoint: ['/bin/sh', '-c']
cmd: ['echo \$BUILD_SCRIPT | base64 -d | /bin/sh -e']
}
@ -118,10 +118,10 @@ pub fn build_config(address string, api_key string, config BuildConfig) !BuildRe
base64_script := base64.encode_str(build_script)
c := docker.NewContainer{
image: '$config.base_image'
image: '${config.base_image}'
env: [
'BUILD_SCRIPT=$base64_script',
'API_KEY=$api_key',
'BUILD_SCRIPT=${base64_script}',
'API_KEY=${api_key}',
// `archlinux:base-devel` does not correctly set the path variable,
// causing certain builds to fail. This fixes it.
'PATH=${build.path_dirs.join(':')}',

View File

@ -36,7 +36,7 @@ pub struct BuildJobQueue {
mut:
mutex shared util.Dummy
// For each architecture, a priority queue is tracked
queues map[string]MinHeap<BuildJob>
queues map[string]MinHeap[BuildJob]
// When a target is removed from the server or edited, its previous build
// configs will be invalid. This map allows for those to be simply skipped
// by ignoring any build configs created before this timestamp.
@ -74,7 +74,7 @@ pub struct InsertConfig {
pub fn (mut q BuildJobQueue) insert(input InsertConfig) ! {
lock q.mutex {
if input.arch !in q.queues {
q.queues[input.arch] = MinHeap<BuildJob>{}
q.queues[input.arch] = MinHeap[BuildJob]{}
}
mut job := BuildJob{
@ -86,7 +86,7 @@ pub fn (mut q BuildJobQueue) insert(input InsertConfig) ! {
if !input.now {
ce := if input.target.schedule != '' {
cron.parse_expression(input.target.schedule) or {
return error("Error while parsing cron expression '$input.target.schedule' (id $input.target.id): $err.msg()")
return error("Error while parsing cron expression '${input.target.schedule}' (id ${input.target.id}): ${err.msg()}")
}
} else {
q.default_schedule
@ -143,7 +143,7 @@ pub fn (mut q BuildJobQueue) peek(arch string) ?BuildJob {
}
q.pop_invalid(arch)
job := q.queues[arch].peek()?
job := q.queues[arch].peek() or { return none }
if job.timestamp < time.now() {
return job
@ -162,10 +162,10 @@ pub fn (mut q BuildJobQueue) pop(arch string) ?BuildJob {
}
q.pop_invalid(arch)
mut job := q.queues[arch].peek()?
mut job := q.queues[arch].peek() or { return none }
if job.timestamp < time.now() {
job = q.queues[arch].pop()?
job = q.queues[arch].pop() or { return none }
if !job.single {
q.reschedule(job, arch)

View File

@ -24,12 +24,12 @@ pub fn echo_commands(cmds []string) []string {
// create_build_script generates a shell script that builds a given Target.
fn create_build_script(address string, config BuildConfig, build_arch string) string {
repo_url := '$address/$config.repo'
repo_url := '${address}/${config.repo}'
mut commands := [
// This will later be replaced by a proper setting for changing the
// mirrorlist
"echo -e '[$config.repo]\\nServer = $address/\$repo/\$arch\\nSigLevel = Optional' >> /etc/pacman.conf"
"echo -e '[${config.repo}]\\nServer = ${address}/\$repo/\$arch\\nSigLevel = Optional' >> /etc/pacman.conf"
// We need to update the package list of the repo we just added above.
// This should however not pull in a lot of packages as long as the
// builder image is rebuilt frequently.
@ -42,18 +42,18 @@ fn create_build_script(address string, config BuildConfig, build_arch string) st
'git' {
if config.branch == '' {
[
"git clone --single-branch --depth 1 '$config.url' repo",
"git clone --single-branch --depth 1 '${config.url}' repo",
]
} else {
[
"git clone --single-branch --depth 1 --branch $config.branch '$config.url' repo",
"git clone --single-branch --depth 1 --branch ${config.branch} '${config.url}' repo",
]
}
}
'url' {
[
'mkdir repo',
"curl -o repo/PKGBUILD -L '$config.url'",
"curl -o repo/PKGBUILD -L '${config.url}'",
]
}
else {
@ -62,7 +62,7 @@ fn create_build_script(address string, config BuildConfig, build_arch string) st
}
commands << if config.path != '' {
"cd 'repo/$config.path'"
"cd 'repo/${config.path}'"
} else {
'cd repo'
}
@ -76,7 +76,7 @@ fn create_build_script(address string, config BuildConfig, build_arch string) st
// The build container checks whether the package is already present on
// the server.
commands << [
'curl -s --head --fail $repo_url/$build_arch/\$pkgname-\$pkgver-\$pkgrel && exit 0',
'curl -s --head --fail ${repo_url}/${build_arch}/\$pkgname-\$pkgver-\$pkgrel && exit 0',
// If the above curl command succeeds, we don't need to rebuild the
// package. However, because we're in a su shell, the exit command will
// drop us back into the root shell. Therefore, we must check whether
@ -86,7 +86,7 @@ fn create_build_script(address string, config BuildConfig, build_arch string) st
}
commands << [
'MAKEFLAGS="-j\$(nproc)" makepkg -s --noconfirm --needed --noextract && for pkg in \$(ls -1 *.pkg*); do curl -XPOST -T "\$pkg" -H "X-API-KEY: \$API_KEY" $repo_url/publish; done',
'MAKEFLAGS="-j\$(nproc)" makepkg -s --noconfirm --needed --noextract && for pkg in \$(ls -1 *.pkg*); do curl -XPOST -T "\$pkg" -H "X-API-KEY: \$API_KEY" ${repo_url}/publish; done',
]
return echo_commands(commands).join('\n')

View File

@ -22,7 +22,7 @@ pub fn new(address string, api_key string) Client {
// send_request_raw sends an HTTP request, returning the http.Response object.
// It encodes the params so that they're safe to pass as HTTP query parameters.
fn (c &Client) send_request_raw(method Method, url string, params map[string]string, body string) !http.Response {
mut full_url := '$c.address$url'
mut full_url := '${c.address}${url}'
if params.len > 0 {
mut params_escaped := map[string]string{}
@ -33,9 +33,9 @@ fn (c &Client) send_request_raw(method Method, url string, params map[string]str
params_escaped[k] = urllib.query_escape(v)
}
params_str := params_escaped.keys().map('$it=${params_escaped[it]}').join('&')
params_str := params_escaped.keys().map('${it}=${params_escaped[it]}').join('&')
full_url = '$full_url?$params_str'
full_url = '${full_url}?${params_str}'
}
// Looking at the source code, this function doesn't actually fail, so I'm
@ -49,13 +49,13 @@ fn (c &Client) send_request_raw(method Method, url string, params map[string]str
}
// send_request<T> just calls send_request_with_body<T> with an empty body.
fn (c &Client) send_request<T>(method Method, url string, params map[string]string) !Response<T> {
return c.send_request_with_body<T>(method, url, params, '')
fn (c &Client) send_request[T](method Method, url string, params map[string]string) !Response[T] {
return c.send_request_with_body[T](method, url, params, '')
}
// send_request_with_body<T> calls send_request_raw_response & parses its
// output as a Response<T> object.
fn (c &Client) send_request_with_body<T>(method Method, url string, params map[string]string, body string) !Response<T> {
fn (c &Client) send_request_with_body[T](method Method, url string, params map[string]string, body string) !Response[T] {
res := c.send_request_raw(method, url, params, body)!
status := res.status()
@ -64,12 +64,12 @@ fn (c &Client) send_request_with_body<T>(method Method, url string, params map[s
if status.is_error() {
// A non-successful status call will have an empty body
if res.body == '' {
return error('Error $res.status_code ($status.str()): (empty response)')
return error('Error ${res.status_code} (${status.str()}): (empty response)')
}
data := json.decode(Response<string>, res.body)!
data := json.decode(Response[string], res.body)!
return error('Status $res.status_code ($status.str()): $data.message')
return error('Status ${res.status_code} (${status.str()}): ${data.message}')
}
// Just return an empty successful response
@ -77,7 +77,7 @@ fn (c &Client) send_request_with_body<T>(method Method, url string, params map[s
return new_data_response(T{})
}
data := json.decode(Response<T>, res.body)!
data := json.decode(Response[T], res.body)!
return data
}

View File

@ -4,7 +4,7 @@ import models { BuildConfig }
// poll_jobs requests a list of new build jobs from the server.
pub fn (c &Client) poll_jobs(arch string, max int) ![]BuildConfig {
data := c.send_request<[]BuildConfig>(.get, '/api/v1/jobs/poll', {
data := c.send_request[[]BuildConfig](.get, '/api/v1/jobs/poll', {
'arch': arch
'max': max.str()
})!
@ -15,7 +15,7 @@ pub fn (c &Client) poll_jobs(arch string, max int) ![]BuildConfig {
// queue_job adds a new one-time build job for the given target to the job
// queue.
pub fn (c &Client) queue_job(target_id int, arch string, force bool) ! {
c.send_request<string>(.post, '/api/v1/jobs/queue', {
c.send_request[string](.post, '/api/v1/jobs/queue', {
'target': target_id.str()
'arch': arch
'force': force.str()

View File

@ -7,27 +7,27 @@ import time
// get_build_logs returns all build logs.
pub fn (c &Client) get_build_logs(filter BuildLogFilter) ![]BuildLog {
params := models.params_from(filter)
data := c.send_request<[]BuildLog>(.get, '/api/v1/logs', params)!
data := c.send_request[[]BuildLog](.get, '/api/v1/logs', params)!
return data.data
}
// get_build_log returns a specific build log.
pub fn (c &Client) get_build_log(id int) !BuildLog {
data := c.send_request<BuildLog>(.get, '/api/v1/logs/$id', {})!
data := c.send_request[BuildLog](.get, '/api/v1/logs/${id}', {})!
return data.data
}
// get_build_log_content returns the contents of the build log file.
pub fn (c &Client) get_build_log_content(id int) !string {
data := c.send_request_raw_response(.get, '/api/v1/logs/$id/content', {}, '')!
data := c.send_request_raw_response(.get, '/api/v1/logs/${id}/content', {}, '')!
return data
}
// add_build_log adds a new build log to the server.
pub fn (c &Client) add_build_log(target_id int, start_time time.Time, end_time time.Time, arch string, exit_code int, content string) !Response<int> {
pub fn (c &Client) add_build_log(target_id int, start_time time.Time, end_time time.Time, arch string, exit_code int, content string) !Response[int] {
params := {
'target': target_id.str()
'startTime': start_time.unix_time().str()
@ -36,12 +36,12 @@ pub fn (c &Client) add_build_log(target_id int, start_time time.Time, end_time t
'exitCode': exit_code.str()
}
data := c.send_request_with_body<int>(.post, '/api/v1/logs', params, content)!
data := c.send_request_with_body[int](.post, '/api/v1/logs', params, content)!
return data
}
// remove_build_log removes the build log with the given id from the server.
pub fn (c &Client) remove_build_log(id int) ! {
c.send_request<string>(.delete, '/api/v1/logs/$id', {})!
c.send_request[string](.delete, '/api/v1/logs/${id}', {})!
}

View File

@ -2,15 +2,15 @@ module client
// remove_repo removes an entire repository.
pub fn (c &Client) remove_repo(repo string) ! {
c.send_request<string>(.delete, '/$repo', {})!
c.send_request[string](.delete, '/${repo}', {})!
}
// remove_arch_repo removes an entire arch-repo.
pub fn (c &Client) remove_arch_repo(repo string, arch string) ! {
c.send_request<string>(.delete, '/$repo/$arch', {})!
c.send_request[string](.delete, '/${repo}/${arch}', {})!
}
// remove_package removes a single package from the given arch-repo.
pub fn (c &Client) remove_package(repo string, arch string, pkgname string) ! {
c.send_request<string>(.delete, '/$repo/$arch/$pkgname', {})!
c.send_request[string](.delete, '/${repo}/${arch}/${pkgname}', {})!
}

View File

@ -5,7 +5,7 @@ import models { Target, TargetFilter }
// get_targets returns a list of targets, given a filter object.
pub fn (c &Client) get_targets(filter TargetFilter) ![]Target {
params := models.params_from(filter)
data := c.send_request<[]Target>(.get, '/api/v1/targets', params)!
data := c.send_request[[]Target](.get, '/api/v1/targets', params)!
return data.data
}
@ -33,7 +33,7 @@ pub fn (c &Client) get_all_targets() ![]Target {
// get_target returns the target for a specific id.
pub fn (c &Client) get_target(id int) !Target {
data := c.send_request<Target>(.get, '/api/v1/targets/$id', {})!
data := c.send_request[Target](.get, '/api/v1/targets/${id}', {})!
return data.data
}
@ -49,15 +49,15 @@ pub struct NewTarget {
// add_target adds a new target to the server.
pub fn (c &Client) add_target(t NewTarget) !int {
params := models.params_from<NewTarget>(t)
data := c.send_request<int>(.post, '/api/v1/targets', params)!
params := models.params_from[NewTarget](t)
data := c.send_request[int](.post, '/api/v1/targets', params)!
return data.data
}
// remove_target removes the target with the given id from the server.
pub fn (c &Client) remove_target(id int) !string {
data := c.send_request<string>(.delete, '/api/v1/targets/$id', {})!
data := c.send_request[string](.delete, '/api/v1/targets/${id}', {})!
return data.data
}
@ -65,7 +65,7 @@ pub fn (c &Client) remove_target(id int) !string {
// patch_target sends a PATCH request to the given target with the params as
// payload.
pub fn (c &Client) patch_target(id int, params map[string]string) !string {
data := c.send_request<string>(.patch, '/api/v1/targets/$id', params)!
data := c.send_request[string](.patch, '/api/v1/targets/${id}', params)!
return data.data
}

View File

@ -36,24 +36,24 @@ pub fn cmd() cli.Command {
required_args: 2
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
c := aur.new()
pkgs := c.info(cmd.args[1..])!
vc := client.new(conf.address, conf.api_key)
vc := client.new(conf_.address, conf_.api_key)
for pkg in pkgs {
vc.add_target(
kind: 'git'
url: 'https://aur.archlinux.org/$pkg.package_base' + '.git'
url: 'https://aur.archlinux.org/${pkg.package_base}' + '.git'
repo: cmd.args[0]
) or {
println('Failed to add $pkg.name: $err.msg()')
println('Failed to add ${pkg.name}: ${err.msg()}')
continue
}
println('Added $pkg.name' + '.')
println('Added ${pkg.name}' + '.')
}
}
},

View File

@ -74,7 +74,7 @@ pub fn cmd() cli.Command {
]
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
mut filter := BuildLogFilter{}
@ -146,7 +146,7 @@ pub fn cmd() cli.Command {
raw := cmd.flags.get_bool('raw')!
list(conf, filter, raw)!
list(conf_, filter, raw)!
}
},
cli.Command{
@ -156,9 +156,9 @@ pub fn cmd() cli.Command {
description: 'Remove a build log that matches the given id.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
remove(conf, cmd.args[0])!
remove(conf_, cmd.args[0])!
}
},
cli.Command{
@ -168,10 +168,10 @@ pub fn cmd() cli.Command {
description: 'Show all info for a specific build log.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
id := cmd.args[0].int()
info(conf, id)!
info(conf_, id)!
}
},
cli.Command{
@ -181,10 +181,10 @@ pub fn cmd() cli.Command {
description: 'Output the content of a build log to stdout.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
id := cmd.args[0].int()
content(conf, id)!
content(conf_, id)!
}
},
]
@ -204,16 +204,16 @@ fn print_log_list(logs []BuildLog, raw bool) ! {
}
// list prints a list of all build logs.
fn list(conf Config, filter BuildLogFilter, raw bool) ! {
c := client.new(conf.address, conf.api_key)
fn list(conf_ Config, filter BuildLogFilter, raw bool) ! {
c := client.new(conf_.address, conf_.api_key)
logs := c.get_build_logs(filter)!
print_log_list(logs, raw)!
}
// info print the detailed info for a given build log.
fn info(conf Config, id int) ! {
c := client.new(conf.address, conf.api_key)
fn info(conf_ Config, id int) ! {
c := client.new(conf_.address, conf_.api_key)
log := c.get_build_log(id)!
print(log)
@ -221,15 +221,15 @@ fn info(conf Config, id int) ! {
// content outputs the contents of the log file for a given build log to
// stdout.
fn content(conf Config, id int) ! {
c := client.new(conf.address, conf.api_key)
fn content(conf_ Config, id int) ! {
c := client.new(conf_.address, conf_.api_key)
content := c.get_build_log_content(id)!
println(content)
}
// remove removes a build log from the server's list.
fn remove(conf Config, id string) ! {
c := client.new(conf.address, conf.api_key)
fn remove(conf_ Config, id string) ! {
c := client.new(conf_.address, conf_.api_key)
c.remove_build_log(id.int())!
}

View File

@ -28,7 +28,7 @@ pub fn cmd() cli.Command {
]
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
if cmd.args.len < 3 {
if !cmd.flags.get_bool('force')! {
@ -36,14 +36,14 @@ pub fn cmd() cli.Command {
}
}
client := client.new(conf.address, conf.api_key)
client_ := client.new(conf_.address, conf_.api_key)
if cmd.args.len == 1 {
client.remove_repo(cmd.args[0])!
client_.remove_repo(cmd.args[0])!
} else if cmd.args.len == 2 {
client.remove_arch_repo(cmd.args[0], cmd.args[1])!
client_.remove_arch_repo(cmd.args[0], cmd.args[1])!
} else {
client.remove_package(cmd.args[0], cmd.args[1], cmd.args[2])!
client_.remove_package(cmd.args[0], cmd.args[1], cmd.args[2])!
}
}
},

View File

@ -6,7 +6,7 @@ import os
import build
// build locally builds the target with the given id.
fn build(conf Config, target_id int, force bool) ! {
fn build_target(conf Config, target_id int, force bool) ! {
c := client.new(conf.address, conf.api_key)
target := c.get_target(target_id)!

View File

@ -54,7 +54,7 @@ pub fn cmd() cli.Command {
]
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
mut filter := TargetFilter{}
@ -85,7 +85,7 @@ pub fn cmd() cli.Command {
raw := cmd.flags.get_bool('raw')!
list(conf, filter, raw)!
list(conf_, filter, raw)!
}
},
cli.Command{
@ -113,7 +113,7 @@ pub fn cmd() cli.Command {
]
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
t := NewTarget{
kind: cmd.flags.get_string('kind')!
@ -125,7 +125,7 @@ pub fn cmd() cli.Command {
raw := cmd.flags.get_bool('raw')!
add(conf, t, raw)!
add(conf_, t, raw)!
}
},
cli.Command{
@ -135,9 +135,9 @@ pub fn cmd() cli.Command {
description: 'Remove a target that matches the given id.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
remove(conf, cmd.args[0])!
remove(conf_, cmd.args[0])!
}
},
cli.Command{
@ -147,9 +147,9 @@ pub fn cmd() cli.Command {
description: 'Show detailed information for the target matching the id.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
info(conf, cmd.args[0])!
info(conf_, cmd.args[0])!
}
},
cli.Command{
@ -196,7 +196,7 @@ pub fn cmd() cli.Command {
]
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
found := cmd.flags.get_all_found()
@ -208,7 +208,7 @@ pub fn cmd() cli.Command {
}
}
patch(conf, cmd.args[0], params)!
patch(conf_, cmd.args[0], params)!
}
},
cli.Command{
@ -235,7 +235,7 @@ pub fn cmd() cli.Command {
]
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
remote := cmd.flags.get_bool('remote')!
force := cmd.flags.get_bool('force')!
@ -248,10 +248,10 @@ pub fn cmd() cli.Command {
return error('When scheduling the build remotely, you have to specify an architecture.')
}
c := client.new(conf.address, conf.api_key)
c := client.new(conf_.address, conf_.api_key)
c.queue_job(target_id, arch, force)!
} else {
build(conf, target_id, force)!
build_target(conf_, target_id, force)!
}
}
},
@ -260,8 +260,8 @@ pub fn cmd() cli.Command {
}
// list prints out a list of all repositories.
fn list(conf Config, filter TargetFilter, raw bool) ! {
c := client.new(conf.address, conf.api_key)
fn list(conf_ Config, filter TargetFilter, raw bool) ! {
c := client.new(conf_.address, conf_.api_key)
targets := c.get_targets(filter)!
data := targets.map([it.id.str(), it.kind, it.url, it.repo])
@ -273,40 +273,40 @@ fn list(conf Config, filter TargetFilter, raw bool) ! {
}
// add adds a new target to the server's list.
fn add(conf Config, t &NewTarget, raw bool) ! {
c := client.new(conf.address, conf.api_key)
fn add(conf_ Config, t &NewTarget, raw bool) ! {
c := client.new(conf_.address, conf_.api_key)
target_id := c.add_target(t)!
if raw {
println(target_id)
} else {
println('Target added with id $target_id')
println('Target added with id ${target_id}')
}
}
// remove removes a target from the server's list.
fn remove(conf Config, id string) ! {
c := client.new(conf.address, conf.api_key)
fn remove(conf_ Config, id string) ! {
c := client.new(conf_.address, conf_.api_key)
c.remove_target(id.int())!
}
// patch patches a given target with the provided params.
fn patch(conf Config, id string, params map[string]string) ! {
fn patch(conf_ Config, id string, params map[string]string) ! {
// We check the cron expression first because it's useless to send an
// invalid one to the server.
if 'schedule' in params && params['schedule'] != '' {
cron.parse_expression(params['schedule']) or {
return error('Invalid cron expression: $err.msg()')
return error('Invalid cron expression: ${err.msg()}')
}
}
c := client.new(conf.address, conf.api_key)
c := client.new(conf_.address, conf_.api_key)
c.patch_target(id.int(), params)!
}
// info shows detailed information for a given target.
fn info(conf Config, id string) ! {
c := client.new(conf.address, conf.api_key)
fn info(conf_ Config, id string) ! {
c := client.new(conf_.address, conf_.api_key)
target := c.get_target(id.int())!
println(target)
}

View File

@ -25,7 +25,7 @@ fn test_not_allowed() {
for exp in illegal_expressions {
res = false
parse_expression(exp) or { res = true }
assert res, "'$exp' should produce an error"
assert res, "'${exp}' should produce an error"
}
}

View File

@ -1,6 +1,6 @@
module db
module dbms
import sqlite
import db.sqlite
import time
pub struct VieterDb {
@ -49,13 +49,13 @@ pub fn init(db_path string) !VieterDb {
}
// Apply each migration in order
for i in cur_version.version .. db.migrations_up.len {
migration := db.migrations_up[i].to_string()
for i in cur_version.version .. dbms.migrations_up.len {
migration := dbms.migrations_up[i].to_string()
version_num := i + 1
// vfmt does not like these dots
println('Applying migration $version_num' + '...')
println('Applying migration ${version_num}' + '...')
// The sqlite library seems to not like it when multiple statements are
// passed in a single exec. Therefore, we split them & run them all
@ -64,7 +64,7 @@ pub fn init(db_path string) !VieterDb {
res := conn.exec_none(part)
if res != sqlite.sqlite_done {
return error('An error occurred while applying migration $version_num: SQLite error code $res')
return error('An error occurred while applying migration ${version_num}: SQLite error code ${res}')
}
}
@ -80,9 +80,9 @@ pub fn init(db_path string) !VieterDb {
}
}
// row_into<T> converts an sqlite.Row into a given type T by parsing each field
// row_into[T] converts an sqlite.Row into a given type T by parsing each field
// from a string according to its type.
pub fn row_into<T>(row sqlite.Row) T {
pub fn row_into[T](row sqlite.Row) T {
mut i := 0
mut out := T{}

View File

@ -1,4 +1,4 @@
module db
module dbms
import models { BuildLog, BuildLogFilter }
import time
@ -8,20 +8,20 @@ pub fn (db &VieterDb) get_build_logs(filter BuildLogFilter) []BuildLog {
mut where_parts := []string{}
if filter.target != 0 {
where_parts << 'target_id == $filter.target'
where_parts << 'target_id == ${filter.target}'
}
if filter.before != time.Time{} {
where_parts << 'start_time < $filter.before.unix_time()'
where_parts << 'start_time < ${filter.before.unix_time()}'
}
if filter.after != time.Time{} {
where_parts << 'start_time > $filter.after.unix_time()'
where_parts << 'start_time > ${filter.after.unix_time()}'
}
// NOTE: possible SQL injection
if filter.arch != '' {
where_parts << "arch == '$filter.arch'"
where_parts << "arch == '${filter.arch}'"
}
mut parts := []string{}
@ -30,27 +30,27 @@ pub fn (db &VieterDb) get_build_logs(filter BuildLogFilter) []BuildLog {
if exp[0] == `!` {
code := exp[1..].int()
parts << 'exit_code != $code'
parts << 'exit_code != ${code}'
} else {
code := exp.int()
parts << 'exit_code == $code'
parts << 'exit_code == ${code}'
}
}
if parts.len > 0 {
where_parts << parts.map('($it)').join(' or ')
where_parts << parts.map('(${it})').join(' or ')
}
mut where_str := ''
if where_parts.len > 0 {
where_str = 'where ' + where_parts.map('($it)').join(' and ')
where_str = 'where ' + where_parts.map('(${it})').join(' and ')
}
query := 'select * from BuildLog $where_str limit $filter.limit offset $filter.offset'
query := 'select * from BuildLog ${where_str} limit ${filter.limit} offset ${filter.offset}'
rows, _ := db.conn.exec(query)
res := rows.map(row_into<BuildLog>(it))
res := rows.map(row_into[BuildLog](it))
return res
}

View File

@ -1,4 +1,4 @@
module db
module dbms
import models { Target, TargetArch }
@ -49,13 +49,13 @@ pub fn (db &VieterDb) update_target(target_id int, params map[string]string) {
if field.name in params {
// Any fields that are array types require their own update method
$if field.typ is string {
values << "$field.name = '${params[field.name]}'"
values << "${field.name} = '${params[field.name]}'"
}
}
}
values_str := values.join(', ')
// I think this is actual SQL & not the ORM language
query := 'update Target set $values_str where id == $target_id'
query := 'update Target set ${values_str} where id == ${target_id}'
db.conn.exec_none(query)
}

View File

@ -1,7 +1,7 @@
module db
module dbms
import models { Target, TargetFilter }
import sqlite
import db.sqlite
// Iterator providing a filtered view into the list of targets currently stored
// in the database. It replaces functionality usually performed in the database

View File

@ -14,5 +14,5 @@ pub:
// str return a single-line string representation of a build log
pub fn (c BuildConfig) str() string {
return '{ target: $c.target_id, kind: $c.kind, url: $c.url, branch: $c.branch, path: $c.path, repo: $c.repo, base_image: $c.base_image, force: $c.force }'
return '{ target: ${c.target_id}, kind: ${c.kind}, url: ${c.url}, branch: ${c.branch}, path: ${c.path}, repo: ${c.repo}, base_image: ${c.base_image}, force: ${c.force} }'
}

View File

@ -16,13 +16,13 @@ pub mut:
// str returns a string representation.
pub fn (bl &BuildLog) str() string {
mut parts := [
'id: $bl.id',
'target id: $bl.target_id',
'start time: $bl.start_time.local()',
'end time: $bl.end_time.local()',
'id: ${bl.id}',
'target id: ${bl.target_id}',
'start time: ${bl.start_time.local()}',
'end time: ${bl.end_time.local()}',
'duration: ${bl.end_time - bl.start_time}',
'arch: $bl.arch',
'exit code: $bl.exit_code',
'arch: ${bl.arch}',
'exit code: ${bl.exit_code}',
]
str := parts.join('\n')

View File

@ -2,19 +2,19 @@ module models
import time
// from_params<T> creates a new instance of T from the given map by parsing all
// from_params[T] creates a new instance of T from the given map by parsing all
// of its fields from the map.
pub fn from_params<T>(params map[string]string) ?T {
pub fn from_params[T](params map[string]string) ?T {
mut o := T{}
patch_from_params<T>(mut o, params)?
patch_from_params[T](mut o, params)?
return o
}
// patch_from_params<T> updates the given T object with the params defined in
// patch_from_params[T] updates the given T object with the params defined in
// the map.
pub fn patch_from_params<T>(mut o T, params map[string]string) ? {
pub fn patch_from_params[T](mut o T, params map[string]string) ? {
$for field in T.fields {
if field.name in params && params[field.name] != '' {
$if field.typ is string {
@ -36,8 +36,8 @@ pub fn patch_from_params<T>(mut o T, params map[string]string) ? {
}
}
// params_from<T> converts a given T struct into a map of strings.
pub fn params_from<T>(o &T) map[string]string {
// params_from[T] converts a given T struct into a map of strings.
pub fn params_from[T](o &T) map[string]string {
mut out := map[string]string{}
$for field in T.fields {

View File

@ -38,13 +38,13 @@ pub mut:
// str returns a string representation.
pub fn (t &Target) str() string {
mut parts := [
'id: $t.id',
'kind: $t.kind',
'url: $t.url',
'branch: $t.branch',
'path: $t.path',
'repo: $t.repo',
'schedule: $t.schedule',
'id: ${t.id}',
'kind: ${t.kind}',
'url: ${t.url}',
'branch: ${t.branch}',
'path: ${t.path}',
'repo: ${t.repo}',
'schedule: ${t.schedule}',
'arch: ${t.arch.map(it.value).join(', ')}',
]
str := parts.join('\n')

View File

@ -3,14 +3,14 @@ module package
// format_entry returns a string properly formatted to be added to a desc file.
[inline]
fn format_entry(key string, value string) string {
return '\n%$key%\n$value\n'
return '\n%${key}%\n${value}\n'
}
// full_name returns the properly formatted name for the package, including
// version & architecture
pub fn (pkg &Pkg) full_name() string {
p := pkg.info
return '$p.name-$p.version-$p.arch'
return '${p.name}-${p.version}-${p.arch}'
}
// filename returns the correct filename of the package file
@ -20,10 +20,10 @@ pub fn (pkg &Pkg) filename() string {
1 { '.tar.gz' }
6 { '.tar.xz' }
14 { '.tar.zst' }
else { panic("Another compression code shouldn't be possible. Faulty code: $pkg.compression") }
else { panic("Another compression code shouldn't be possible. Faulty code: ${pkg.compression}") }
}
return '${pkg.full_name()}.pkg$ext'
return '${pkg.full_name()}.pkg${ext}'
}
// to_desc returns a desc file valid string representation
@ -31,7 +31,7 @@ pub fn (pkg &Pkg) to_desc() !string {
p := pkg.info
// filename
mut desc := '%FILENAME%\n$pkg.filename()\n'
mut desc := '%FILENAME%\n${pkg.filename()}\n'
desc += format_entry('NAME', p.name)
desc += format_entry('BASE', p.base)
@ -94,10 +94,10 @@ pub fn (pkg &Pkg) to_desc() !string {
desc += format_entry('CHECKDEPENDS', p.checkdepends.join_lines())
}
return '$desc\n'
return '${desc}\n'
}
// to_files returns a files file valid string representation
pub fn (pkg &Pkg) to_files() string {
return '%FILES%\n$pkg.files.join_lines()\n'
return '%FILES%\n${pkg.files.join_lines()}\n'
}

View File

@ -103,7 +103,7 @@ fn parse_pkg_info_string(pkg_info_str &string) !PkgInfo {
// NOTE: this command only supports zstd-, xz- & gzip-compressed tarballs.
pub fn read_pkg_archive(pkg_path string) !Pkg {
if !os.is_file(pkg_path) {
return error("'$pkg_path' doesn't exist or isn't a file.")
return error("'${pkg_path}' doesn't exist or isn't a file.")
}
a := C.archive_read_new()

View File

@ -31,11 +31,15 @@ pub:
// new creates a new RepoGroupManager & creates the directories as needed
pub fn new(repos_dir string, pkg_dir string, default_arch string) !RepoGroupManager {
if !os.is_dir(repos_dir) {
os.mkdir_all(repos_dir) or { return error('Failed to create repos directory: $err.msg()') }
os.mkdir_all(repos_dir) or {
return error('Failed to create repos directory: ${err.msg()}')
}
}
if !os.is_dir(pkg_dir) {
os.mkdir_all(pkg_dir) or { return error('Failed to create package directory: $err.msg()') }
os.mkdir_all(pkg_dir) or {
return error('Failed to create package directory: ${err.msg()}')
}
}
return RepoGroupManager{
@ -51,7 +55,7 @@ pub fn new(repos_dir string, pkg_dir string, default_arch string) !RepoGroupMana
// the right subdirectories in r.pkg_dir if it was successfully added.
pub fn (r &RepoGroupManager) add_pkg_from_path(repo string, pkg_path string) !RepoAddResult {
pkg := package.read_pkg_archive(pkg_path) or {
return error('Failed to read package file: $err.msg()')
return error('Failed to read package file: ${err.msg()}')
}
archs := r.add_pkg_in_repo(repo, pkg)!
@ -129,7 +133,7 @@ fn (r &RepoGroupManager) add_pkg_in_repo(repo string, pkg &package.Pkg) ![]strin
// files, and afterwards updates the db & files archives to reflect these
// changes.
fn (r &RepoGroupManager) add_pkg_in_arch_repo(repo string, arch string, pkg &package.Pkg) ! {
pkg_dir := os.join_path(r.repos_dir, repo, arch, '$pkg.info.name-$pkg.info.version')
pkg_dir := os.join_path(r.repos_dir, repo, arch, '${pkg.info.name}-${pkg.info.version}')
// Remove the previous version of the package, if present
r.remove_pkg_from_arch_repo(repo, arch, pkg.info.name, false)!

View File

@ -5,7 +5,7 @@ import os
// remove_pkg_from_arch_repo removes a package from an arch-repo's database. It
// returns false if the package wasn't present in the database. It also
// optionally re-syncs the repo archives.
pub fn (r &RepoGroupManager) remove_pkg_from_arch_repo(repo string, arch string, pkg_name string, sync bool) !bool {
pub fn (r &RepoGroupManager) remove_pkg_from_arch_repo(repo string, arch string, pkg_name string, perform_sync bool) !bool {
repo_dir := os.join_path(r.repos_dir, repo, arch)
// If the repository doesn't exist yet, the result is automatically false
@ -39,7 +39,7 @@ pub fn (r &RepoGroupManager) remove_pkg_from_arch_repo(repo string, arch string,
}
// Sync the db archives if requested
if sync {
if perform_sync {
r.sync(repo, arch)!
}

View File

@ -3,7 +3,6 @@ module server
import web
import net.urllib
import web.response { new_data_response, new_response }
import db
import time
import os
import util
@ -13,7 +12,7 @@ import models { BuildLog, BuildLogFilter }
// optionally be added to limit the list of build logs to that repository.
['/api/v1/logs'; auth; get; markused]
fn (mut app App) v1_get_logs() web.Result {
filter := models.from_params<BuildLogFilter>(app.query) or {
filter := models.from_params[BuildLogFilter](app.query) or {
return app.json(.bad_request, new_response('Invalid query parameters.'))
}
logs := app.db.get_build_logs(filter)
@ -101,7 +100,7 @@ fn (mut app App) v1_post_log() web.Result {
// Create the logs directory of it doesn't exist
if !os.exists(os.dir(log_file_path)) {
os.mkdir_all(os.dir(log_file_path)) or {
app.lerror('Error while creating log file: $err.msg()')
app.lerror('Error while creating log file: ${err.msg()}')
return app.status(.internal_server_error)
}
@ -109,7 +108,7 @@ fn (mut app App) v1_post_log() web.Result {
if length := app.req.header.get(.content_length) {
util.reader_to_file(mut app.reader, length.int(), log_file_path) or {
app.lerror('An error occured while receiving logs: $err.msg()')
app.lerror('An error occured while receiving logs: ${err.msg()}')
return app.status(.internal_server_error)
}
@ -127,7 +126,7 @@ fn (mut app App) v1_delete_log(id int) web.Result {
full_path := os.join_path(app.conf.data_dir, logs_dir_name, log.path())
os.rm(full_path) or {
app.lerror('Failed to remove log file $full_path: $err.msg()')
app.lerror('Failed to remove log file ${full_path}: ${err.msg()}')
return app.status(.internal_server_error)
}

View File

@ -2,13 +2,12 @@ module server
import web
import web.response { new_data_response, new_response }
import db
import models { Target, TargetArch, TargetFilter }
// v1_get_targets returns the current list of targets.
['/api/v1/targets'; auth; get; markused]
fn (mut app App) v1_get_targets() web.Result {
filter := models.from_params<TargetFilter>(app.query) or {
filter := models.from_params[TargetFilter](app.query) or {
return app.json(.bad_request, new_response('Invalid query parameters.'))
}
mut iter := app.db.targets(filter)
@ -35,7 +34,7 @@ fn (mut app App) v1_post_target() web.Result {
params['arch'] = app.conf.default_arch
}
mut new_target := models.from_params<Target>(params) or {
mut new_target := models.from_params[Target](params) or {
return app.json(.bad_request, new_response(err.msg()))
}

View File

@ -25,9 +25,9 @@ pub fn cmd() cli.Command {
description: 'Start the Vieter server.'
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
server(conf)!
server(conf_)!
}
}
}

View File

@ -12,7 +12,7 @@ fn (mut app App) log_removal_daemon(schedule &cron.Expression) {
for {
mut too_old_timestamp := time.now().add_days(-app.conf.max_log_age)
app.linfo('Cleaning logs before $too_old_timestamp')
app.linfo('Cleaning logs before ${too_old_timestamp}')
mut logs := []BuildLog{}
mut counter := 0
@ -29,7 +29,7 @@ fn (mut app App) log_removal_daemon(schedule &cron.Expression) {
log_file_path := os.join_path(app.conf.data_dir, logs_dir_name, log.path())
os.rm(log_file_path) or {
app.lerror('Failed to remove log file $log_file_path: $err.msg()')
app.lerror('Failed to remove log file ${log_file_path}: ${err.msg()}')
failed += 1
continue
@ -44,7 +44,7 @@ fn (mut app App) log_removal_daemon(schedule &cron.Expression) {
}
}
app.linfo('Cleaned $counter logs ($failed failed)')
app.linfo('Cleaned ${counter} logs (${failed} failed)')
// Sleep until the next cycle
next_time := schedule.next_from_now()

View File

@ -19,15 +19,15 @@ pub fn (mut app App) healthcheck() web.Result {
// repository's archives, but also package archives or the contents of a
// package's desc file.
['/:repo/:arch/:filename'; get; head; markused]
fn (mut app App) get_repo_file(repo string, arch string, filename string) web.Result {
fn (mut app App) get_repo_file(repo_ string, arch string, filename string) web.Result {
mut full_path := ''
db_exts := ['.db', '.files', '.db.tar.gz', '.files.tar.gz']
// There's no point in having the ability to serve db archives with wrong
// filenames
if db_exts.any(filename == '$repo$it') {
full_path = os.join_path(app.repo.repos_dir, repo, arch, filename)
if db_exts.any(filename == '${repo_}${it}') {
full_path = os.join_path(app.repo.repos_dir, repo_, arch, filename)
// repo-add does this using symlinks, but we just change the requested
// path
@ -35,13 +35,13 @@ fn (mut app App) get_repo_file(repo string, arch string, filename string) web.Re
full_path += '.tar.gz'
}
} else if filename.contains('.pkg') {
full_path = os.join_path(app.repo.pkg_dir, repo, arch, filename)
full_path = os.join_path(app.repo.pkg_dir, repo_, arch, filename)
}
// Default behavior is to return the desc file for the package, if present.
// This can then also be used by the build system to properly check whether
// a package is present in an arch-repo.
else {
full_path = os.join_path(app.repo.repos_dir, repo, arch, filename, 'desc')
full_path = os.join_path(app.repo.repos_dir, repo_, arch, filename, 'desc')
}
return app.file(full_path)
@ -49,10 +49,10 @@ fn (mut app App) get_repo_file(repo string, arch string, filename string) web.Re
// put_package handles publishing a package to a repository.
['/:repo/publish'; auth; markused; post]
fn (mut app App) put_package(repo string) web.Result {
fn (mut app App) put_package(repo_ string) web.Result {
// api is a reserved keyword for api routes & should never be allowed to be
// a repository.
if repo.to_lower() == 'api' {
if repo_.to_lower() == 'api' {
return app.json(.bad_request, new_response("'api' is a reserved keyword & cannot be used as a repository name."))
}
@ -62,19 +62,19 @@ fn (mut app App) put_package(repo string) web.Result {
// Generate a random filename for the temp file
pkg_path = os.join_path_single(app.repo.pkg_dir, rand.uuid_v4())
app.ldebug("Uploading $length bytes (${util.pretty_bytes(length.int())}) to '$pkg_path'.")
app.ldebug("Uploading ${length} bytes (${util.pretty_bytes(length.int())}) to '${pkg_path}'.")
// This is used to time how long it takes to upload a file
mut sw := time.new_stopwatch(time.StopWatchOptions{ auto_start: true })
util.reader_to_file(mut app.reader, length.int(), pkg_path) or {
app.lwarn("Failed to upload '$pkg_path'")
app.lwarn("Failed to upload '${pkg_path}'")
return app.status(.internal_server_error)
}
sw.stop()
app.ldebug("Upload of '$pkg_path' completed in ${sw.elapsed().seconds():.3}s.")
app.ldebug("Upload of '${pkg_path}' completed in ${sw.elapsed().seconds():.3}s.")
} else {
app.lwarn('Tried to upload package without specifying a Content-Length.')
@ -82,15 +82,15 @@ fn (mut app App) put_package(repo string) web.Result {
return app.status(.length_required)
}
res := app.repo.add_pkg_from_path(repo, pkg_path) or {
app.lerror('Error while adding package: $err.msg()')
res := app.repo.add_pkg_from_path(repo_, pkg_path) or {
app.lerror('Error while adding package: ${err.msg()}')
os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path': $err.msg()") }
os.rm(pkg_path) or { app.lerror("Failed to remove download '${pkg_path}': ${err.msg()}") }
return app.status(.internal_server_error)
}
app.linfo("Added '$res.name-$res.version' to '$repo (${res.archs.join(',')})'.")
app.linfo("Added '${res.name}-${res.version}' to '${repo_} (${res.archs.join(',')})'.")
return app.json(.ok, new_data_response(res))
}

View File

@ -6,17 +6,17 @@ import web
['/:repo/:arch/:pkg'; auth; delete; markused]
fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result {
res := app.repo.remove_pkg_from_arch_repo(repo, arch, pkg, true) or {
app.lerror('Error while deleting package: $err.msg()')
app.lerror('Error while deleting package: ${err.msg()}')
return app.status(.internal_server_error)
}
if res {
app.linfo("Removed package '$pkg' from '$repo/$arch'")
app.linfo("Removed package '${pkg}' from '${repo}/${arch}'")
return app.status(.ok)
} else {
app.linfo("Tried removing package '$pkg' from '$repo/$arch', but it doesn't exist.")
app.linfo("Tried removing package '${pkg}' from '${repo}/${arch}', but it doesn't exist.")
return app.status(.not_found)
}
@ -26,17 +26,17 @@ fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result
['/:repo/:arch'; auth; delete; markused]
fn (mut app App) delete_arch_repo(repo string, arch string) web.Result {
res := app.repo.remove_arch_repo(repo, arch) or {
app.lerror('Error while deleting arch-repo: $err.msg()')
app.lerror('Error while deleting arch-repo: ${err.msg()}')
return app.status(.internal_server_error)
}
if res {
app.linfo("Removed arch-repo '$repo/$arch'")
app.linfo("Removed arch-repo '${repo}/${arch}'")
return app.status(.ok)
} else {
app.linfo("Tried removing '$repo/$arch', but it doesn't exist.")
app.linfo("Tried removing '${repo}/${arch}', but it doesn't exist.")
return app.status(.not_found)
}
@ -46,17 +46,17 @@ fn (mut app App) delete_arch_repo(repo string, arch string) web.Result {
['/:repo'; auth; delete; markused]
fn (mut app App) delete_repo(repo string) web.Result {
res := app.repo.remove_repo(repo) or {
app.lerror('Error while deleting repo: $err.msg()')
app.lerror('Error while deleting repo: ${err.msg()}')
return app.status(.internal_server_error)
}
if res {
app.linfo("Removed repo '$repo'")
app.linfo("Removed repo '${repo}'")
return app.status(.ok)
} else {
app.linfo("Tried removing '$repo', but it doesn't exist.")
app.linfo("Tried removing '${repo}', but it doesn't exist.")
return app.status(.not_found)
}

View File

@ -5,7 +5,7 @@ import os
import log
import repo
import util
import db
import dbms
import build { BuildJobQueue }
import cron
import metrics
@ -25,7 +25,7 @@ pub mut:
repo repo.RepoGroupManager [required; web_global]
// Keys are the various architectures for packages
job_queue BuildJobQueue [required; web_global]
db db.VieterDb
db dbms.VieterDb
}
// init_job_queue populates a fresh job queue with all the targets currently
@ -44,11 +44,11 @@ pub fn server(conf Config) ! {
}
global_ce := cron.parse_expression(conf.global_schedule) or {
util.exit_with_message(1, 'Invalid global cron expression: $err.msg()')
util.exit_with_message(1, 'Invalid global cron expression: ${err.msg()}')
}
log_removal_ce := cron.parse_expression(conf.log_removal_schedule) or {
util.exit_with_message(1, 'Invalid log removal cron expression: $err.msg()')
util.exit_with_message(1, 'Invalid log removal cron expression: ${err.msg()}')
}
// Configure logger
@ -82,14 +82,14 @@ pub fn server(conf Config) ! {
repo_dir := os.join_path_single(conf.data_dir, server.repo_dir_name)
// This also creates the directories if needed
repo := repo.new(repo_dir, conf.pkg_dir, conf.default_arch) or {
repo_ := repo.new(repo_dir, conf.pkg_dir, conf.default_arch) or {
logger.error(err.msg())
exit(1)
}
db_file := os.join_path_single(conf.data_dir, server.db_file_name)
db := db.init(db_file) or {
util.exit_with_message(1, 'Failed to initialize database: $err.msg()')
db := dbms.init(db_file) or {
util.exit_with_message(1, 'Failed to initialize database: ${err.msg()}')
}
mut collector := if conf.collect_metrics {
@ -97,25 +97,25 @@ pub fn server(conf Config) ! {
} else {
&metrics.MetricsCollector(metrics.new_null_collector())
}
collector.histogram_buckets_set('http_requests_duration_seconds', [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5,
10] )
collector.histogram_buckets_set('http_requests_duration_seconds', [0.001, 0.005, 0.01, 0.05,
0.1, 0.5, 1, 5, 10])
mut app := &App{
logger: logger
api_key: conf.api_key
conf: conf
repo: repo
repo: repo_
db: db
collector: collector
job_queue: build.new_job_queue(global_ce, conf.base_image)
}
app.init_job_queue() or {
util.exit_with_message(1, 'Failed to inialize job queue: $err.msg()')
util.exit_with_message(1, 'Failed to inialize job queue: ${err.msg()}')
}
if conf.max_log_age > 0 {
go app.log_removal_daemon(log_removal_ce)
spawn app.log_removal_daemon(log_removal_ce)
}
web.run(app, conf.port)

View File

@ -48,10 +48,10 @@ pub fn reader_to_file(mut reader io.BufferedReader, length int, path string) ! {
}
}
// match_array_in_array<T> returns how many elements of a2 overlap with a1. For
// match_array_in_array[T] returns how many elements of a2 overlap with a1. For
// example, if a1 = "abcd" & a2 = "cd", the result will be 2. If the match is
// not at the end of a1, the result is 0.
pub fn match_array_in_array<T>(a1 []T, a2 []T) int {
pub fn match_array_in_array[T](a1 []T, a2 []T) int {
mut i := 0
mut match_len := 0

View File

@ -10,7 +10,7 @@ const attrs_to_ignore = ['auth', 'markused']
// Parsing function attributes for methods and path.
fn parse_attrs(name string, attrs []string) !([]http.Method, string) {
if attrs.len == 0 {
return [http.Method.get], '/$name'
return [http.Method.get], '/${name}'
}
mut x := attrs.clone()
@ -45,7 +45,7 @@ fn parse_attrs(name string, attrs []string) !([]http.Method, string) {
methods = [http.Method.get]
}
if path == '' {
path = '/$name'
path = '/${name}'
}
// Make path lowercase for case-insensitive comparisons
return methods, path.to_lower()

View File

@ -1,6 +1,6 @@
module response
pub struct Response<T> {
pub struct Response[T] {
pub:
message string
data T
@ -8,26 +8,26 @@ pub:
// new_response constructs a new Response<String> object with the given message
// & an empty data field.
pub fn new_response(message string) Response<string> {
return Response<string>{
pub fn new_response(message string) Response[string] {
return Response[string]{
message: message
data: ''
}
}
// new_data_response<T> constructs a new Response<T> object with the given data
// new_data_response[T] constructs a new Response<T> object with the given data
// & an empty message field.
pub fn new_data_response<T>(data T) Response<T> {
return Response<T>{
pub fn new_data_response[T](data T) Response[T] {
return Response[T]{
message: ''
data: data
}
}
// new_full_response<T> constructs a new Response<T> object with the given
// new_full_response[T] constructs a new Response<T> object with the given
// message & data.
pub fn new_full_response<T>(message string, data T) Response<T> {
return Response<T>{
pub fn new_full_response[T](message string, data T) Response[T] {
return Response[T]{
message: message
data: data
}

View File

@ -44,7 +44,7 @@ pub mut:
// Files from multipart-form.
files map[string][]http.FileData
// Allows reading the request body
reader io.BufferedReader
reader &io.BufferedReader = unsafe { nil }
// RESPONSE
status http.Status = http.Status.ok
content_type string = 'text/plain'
@ -157,8 +157,8 @@ pub fn (mut ctx Context) body(status http.Status, content_type string, body stri
return Result{}
}
// json<T> HTTP_OK with json_s as payload with content-type `application/json`
pub fn (mut ctx Context) json<T>(status http.Status, j T) Result {
// json[T] HTTP_OK with json_s as payload with content-type `application/json`
pub fn (mut ctx Context) json[T](status http.Status, j T) Result {
ctx.status = status
ctx.content_type = 'application/json'
@ -278,14 +278,14 @@ interface DbInterface {
// run runs the app
[manualfree]
pub fn run<T>(global_app &T, port int) {
mut l := net.listen_tcp(.ip6, ':$port') or { panic('failed to listen $err.code() $err') }
pub fn run[T](global_app &T, port int) {
mut l := net.listen_tcp(.ip6, ':${port}') or { panic('failed to listen ${err.code()} ${err}') }
// Parsing methods attributes
mut routes := map[string]Route{}
$for method in T.methods {
http_methods, route_path := parse_attrs(method.name, method.attrs) or {
eprintln('error parsing method attributes: $err')
eprintln('error parsing method attributes: ${err}')
return
}
@ -294,7 +294,7 @@ pub fn run<T>(global_app &T, port int) {
path: route_path
}
}
println('[Vweb] Running app on http://localhost:$port')
println('[Vweb] Running app on http://localhost:${port}')
for {
// Create a new app object for each connection, copy global data like db connections
mut request_app := &T{}
@ -311,16 +311,16 @@ pub fn run<T>(global_app &T, port int) {
request_app.Context = global_app.Context // copy the context ref that contains static files map etc
mut conn := l.accept() or {
// failures should not panic
eprintln('accept() failed with error: $err.msg()')
eprintln('accept() failed with error: ${err.msg()}')
continue
}
go handle_conn<T>(mut conn, mut request_app, routes)
spawn handle_conn[T](mut conn, mut request_app, routes)
}
}
// handle_conn handles a connection
[manualfree]
fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
fn handle_conn[T](mut conn net.TcpConn, mut app T, routes map[string]Route) {
conn.set_read_timeout(30 * time.second)
conn.set_write_timeout(30 * time.second)
@ -362,8 +362,8 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
// Request parse
head := http.parse_request_head(mut reader) or {
// Prevents errors from being thrown when BufferedReader is empty
if '$err' != 'none' {
eprintln('error parsing request head: $err')
if '${err}' != 'none' {
eprintln('error parsing request head: ${err}')
}
return
}
@ -371,7 +371,7 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
// The healthcheck spams the logs, which isn't very useful
if head.url != '/health' {
lock app.logger {
app.logger.debug('$head.method $head.url $head.version')
app.logger.debug('${head.method} ${head.url} ${head.version}')
}
}
@ -385,7 +385,7 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
// URL Parse
url := urllib.parse(head.url) or {
eprintln('error parsing path: $err')
eprintln('error parsing path: ${err}')
return
}
@ -423,7 +423,7 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
$for method in T.methods {
$if method.return_type is Result {
route := routes[method.name] or {
eprintln('parsed attributes for the `$method.name` are not found, skipping...')
eprintln('parsed attributes for the `${method.name}` are not found, skipping...')
Route{}
}
@ -455,7 +455,7 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
method_args := params.clone()
if method_args.len != method.args.len {
eprintln('warning: uneven parameters count ($method.args.len) in `$method.name`, compared to the web route `$method.attrs` ($method_args.len)')
eprintln('warning: uneven parameters count (${method.args.len}) in `${method.name}`, compared to the web route `${method.attrs}` (${method_args.len})')
}
app.$method(method_args)
return