From dbe71185bb9298db38ad05d2a141e5e9c9037f12 Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Tue, 31 Jul 2018 16:28:00 +0200 Subject: [PATCH] Either backend or blockbook config sections are optional --- build/docker/deb/build-deb.sh | 4 +-- build/templates/generate.go | 47 ++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/build/docker/deb/build-deb.sh b/build/docker/deb/build-deb.sh index e51f88f7..e4cd23b0 100755 --- a/build/docker/deb/build-deb.sh +++ b/build/docker/deb/build-deb.sh @@ -17,12 +17,12 @@ cp -r /src/configs . go run build/templates/generate.go $coin # backend -if [ $package = "backend" ] || [ $package = "all" ]; then +if ([ $package = "backend" ] || [ $package = "all" ]) && [ -d build/pkg-defs/backend ]; then (cd build/pkg-defs/backend && dpkg-buildpackage -us -uc $@) fi # blockbook -if [ $package = "blockbook" ] || [ $package = "all" ]; then +if ([ $package = "blockbook" ] || [ $package = "all" ]) && [ -d build/pkg-defs/blockbook ]; then export VERSION=$(cd build/pkg-defs/blockbook && dpkg-parsechangelog | sed -rne 's/^Version: ([0-9.]+)([-+~].+)?$/\1/p') cp Makefile ldb sst_dump build/pkg-defs/blockbook diff --git a/build/templates/generate.go b/build/templates/generate.go index 82db779e..bafb51ee 100644 --- a/build/templates/generate.go +++ b/build/templates/generate.go @@ -166,31 +166,48 @@ func loadConfig(coin string) *Config { config.Meta.BuildDatetime = time.Now().Format("Mon, 02 Jan 2006 15:04:05 -0700") - switch config.Backend.ServiceType { - case "forking": - case "simple": - default: - panic("Invalid service type: " + config.Backend.ServiceType) - } + if !isEmpty(config, "backend") { + switch config.Backend.ServiceType { + case "forking": + case "simple": + default: + panic("Invalid service type: " + config.Backend.ServiceType) + } - switch config.Backend.VerificationType { - case "": - case "gpg": - case "sha256": - case "gpg-sha256": - default: - panic("Invalid verification type: " + config.Backend.VerificationType) + switch config.Backend.VerificationType { + case "": + case "gpg": + case "sha256": + case "gpg-sha256": + default: + panic("Invalid verification type: " + config.Backend.VerificationType) + } } return config } +func isEmpty(config *Config, target string) bool { + switch target { + case "backend": + return config.Backend.PackageName == "" + case "blockbook": + return config.Blockbook.PackageName == "" + default: + panic("Invalid target name: " + target) + } +} + func generatePackageDefinitions(config *Config) { templ := config.ParseTemplate() makeOutputDir(outputDir) for _, subdir := range []string{"backend", "blockbook"} { + if isEmpty(config, subdir) { + continue + } + root := filepath.Join(inputDir, subdir) err := os.Mkdir(filepath.Join(outputDir, subdir), 0755) @@ -235,7 +252,9 @@ func generatePackageDefinitions(config *Config) { } } - writeBackendConfigFile(config) + if !isEmpty(config, "backend") { + writeBackendConfigFile(config) + } } func makeOutputDir(path string) {