From e321bd394125cec7054fe6f39a21e0a7cfb37b16 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Wed, 17 Mar 2021 21:03:35 +0100 Subject: [PATCH] lib/*/auto: Add noassets files (#7490) This adds a couple of dummy asset files protected by the "noassets" build tag. The purpose is that it should be possible for, for example, CI tools and static analysis things to compile and analyze the source tree without our custom asset generation step. Also makes `go test -tags noassets ./...` work without building assets first. --- .deepsource.toml | 3 ++- cmd/strelaypoolsrv/auto/noassets.go | 15 ++++++++++++++ lib/api/auto/noassets.go | 32 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 cmd/strelaypoolsrv/auto/noassets.go create mode 100644 lib/api/auto/noassets.go diff --git a/.deepsource.toml b/.deepsource.toml index db824ada9..ab2662a58 100644 --- a/.deepsource.toml +++ b/.deepsource.toml @@ -7,4 +7,5 @@ name = "go" enabled = true [analyzers.meta] - import_paths = ["github.com/syncthing/syncthing"] \ No newline at end of file + import_paths = ["github.com/syncthing/syncthing"] + build_tags = ["noassets"] diff --git a/cmd/strelaypoolsrv/auto/noassets.go b/cmd/strelaypoolsrv/auto/noassets.go new file mode 100644 index 000000000..f8fa5e06d --- /dev/null +++ b/cmd/strelaypoolsrv/auto/noassets.go @@ -0,0 +1,15 @@ +// Copyright (C) 2021 The Syncthing Authors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at https://mozilla.org/MPL/2.0/. + +//+build noassets + +package auto + +import "github.com/syncthing/syncthing/lib/assets" + +func Assets() map[string]assets.Asset { + return nil +} diff --git a/lib/api/auto/noassets.go b/lib/api/auto/noassets.go new file mode 100644 index 000000000..06e726c09 --- /dev/null +++ b/lib/api/auto/noassets.go @@ -0,0 +1,32 @@ +// Copyright (C) 2021 The Syncthing Authors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at https://mozilla.org/MPL/2.0/. + +//+build noassets + +package auto + +import ( + "bytes" + "compress/gzip" + + "github.com/syncthing/syncthing/lib/assets" +) + +func Assets() map[string]assets.Asset { + // Return a minimal index.html and nothing else, to allow the trivial + // test to pass. + + buf := new(bytes.Buffer) + gw := gzip.NewWriter(buf) + _, _ = gw.Write([]byte("")) + _ = gw.Flush() + return map[string]assets.Asset{ + "default/index.html": { + Gzipped: true, + Content: buf.String(), + }, + } +}