From 0a5355d7290b2e7a406bcc29781ac0f4c13497d0 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 4 Aug 2016 14:27:17 +0200 Subject: [PATCH 1/5] build: provide snapcraft yaml for cross distribution packaging Provide a snapcraft yaml and merge it into tuo Makefile to provide an easy way to publish for generic Linux packaging. Integrated into usual make via target "make snap". See http://snapcraft.io/ for more detail on snaps. Signed-off-by: Christian Ehrhardt --- Makefile | 5 +++++ README.snap.md | 27 +++++++++++++++++++++++ parts/plugins/toumakefixup.py | 41 +++++++++++++++++++++++++++++++++++ snapcraft.yaml | 33 ++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 README.snap.md create mode 100644 parts/plugins/toumakefixup.py create mode 100644 snapcraft.yaml diff --git a/Makefile b/Makefile index a80241ea..f07deeaa 100644 --- a/Makefile +++ b/Makefile @@ -16,3 +16,8 @@ $(MAIN): $(OBJS) clean: del /q $(MAIN).exe obj\*.o + +# build a snap for cross distribution availability +# cleanbuild uses snapcracft and lxd +snap: + snapcraft cleanbuild diff --git a/README.snap.md b/README.snap.md new file mode 100644 index 00000000..7898eeb5 --- /dev/null +++ b/README.snap.md @@ -0,0 +1,27 @@ +# tyrant-unleashed-optimizer snap usage + +This is about using the snap'ed version of tyrant-unleashed-optimizer (tuo) + +Working features: + - updating local card database + - simulating fights + +Exposed commands: + - tyrant-unleashed-optimizer.updatexml + - tyrant-unleashed-optimizer.sim + +Known issues: + - To get to your card data files the home plug needs to be connected manually + after snap install. This is due to file access being a potential risk (and + snaps are a lot about security and isolation). To connect the home plug + call: + "sudo snap connect tyrant-unleashed-optimizer:home ubuntu-core:home" + +Card-Update: + - Note: As usual if you don't have a "data" dir yet you have to create one via ``mkdir data`` + - Then to actually call it: + ``tyrant-unleashed-optimizer.updatexml`` + +Simulate: + - Note: as usual with tuo you have to run this where you have your ``data`` dir. + - tyrant-unleashed-optimizer.sim "Lord Silus, Extreme Barrager #2" "Lord Silus, Atomic Wardriver #2" sim 100 diff --git a/parts/plugins/toumakefixup.py b/parts/plugins/toumakefixup.py new file mode 100644 index 00000000..b9eee6cc --- /dev/null +++ b/parts/plugins/toumakefixup.py @@ -0,0 +1,41 @@ +# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- +# +# Copyright (C) 2016 Canonical Ltd +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3 as +# published by the Free Software Foundation. +# +# 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 . + + +import logging + +import snapcraft + +LOG = logging.getLogger(__name__) + +class TUOMake(snapcraft.BasePlugin): + """Fixup broken upstream build + Add missing dir and fake missing install target + """ + def __init__(self, name, options, project): + super().__init__(name, options, project) + + def build(self): + super().build() + LOG.info("TUOMake: Fixup build environment") + self.run(['mkdir', '-p', 'obj']) + LOG.info("TUOMake: Build") + self.run(['make'] + ['-j{}'.format(self.project.parallel_build_count)]) + targetdir = self.installdir+'/usr/bin' + LOG.info("TUOMake: Fake install") + self.run(['cp', 'tuo.exe', targetdir]) + self.run(['cp', 'update_xml.sh', targetdir]) + LOG.info("TUOMake: Finished") diff --git a/snapcraft.yaml b/snapcraft.yaml new file mode 100644 index 00000000..7e932555 --- /dev/null +++ b/snapcraft.yaml @@ -0,0 +1,33 @@ +name: tyrant-unleashed-optimizer +version: daily +summary: Tyrant Unleashed Optimizer +description: | + Simulator app for the game Tarant Unleashed that can be used to optimize your + card deck for certain raids, or temporary buffs as well as growth planning in + general. +confinement: strict + +apps: + sim: + command: usr/bin/tuo.exe + plugs: [home] + updatexml: + command: usr/bin/update_xml.sh + plugs: [home, network] + +parts: + tyrant-unleashed-optimizer: + # as we are part of the tuo git tree then just build locally + source: . + plugin: toumakefixup + build-packages: + - g++ + - make + - build-essential + - libboost1.58-dev + - libboost-system1.58-dev + - libboost-thread1.58-dev + - libboost-filesystem1.58-dev + - libboost-regex1.58-dev + stage-packages: + - curl From f122820e439bbcba14dda663967f4511c2f6c59d Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Fri, 5 Aug 2016 08:58:22 +0200 Subject: [PATCH 2/5] make: let clean target work on Linux Signed-off-by: Christian Ehrhardt --- Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f07deeaa..91071933 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,16 @@ INCS := $(wildcard *.h) CPPFLAGS := -Wall -Werror -std=gnu++11 -O3 -DNDEBUG LDFLAGS := -lboost_system -lboost_thread -lboost_filesystem -lboost_regex +ifdef SYSTEMROOT + RM = del /Q + FixPath = $(subst /,\,$1) +else + ifeq ($(shell uname), Linux) + RM = rm -f + FixPath = $1 + endif +endif + all: $(MAIN) obj/%.o: %.cpp $(INCS) @@ -15,7 +25,7 @@ $(MAIN): $(OBJS) $(CXX) -o $@ $(OBJS) $(LDFLAGS) clean: - del /q $(MAIN).exe obj\*.o + $(RM) $(call FixPath,obj/*.o) # build a snap for cross distribution availability # cleanbuild uses snapcracft and lxd From d7289a09350e4844d71ea29f3acd3bd650c65c14 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Fri, 5 Aug 2016 09:06:38 +0200 Subject: [PATCH 3/5] make: create obj dir on demand As reported before the obj is not created and thereby can let the build fail. (Fixes #15) Signed-off-by: Christian Ehrhardt --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 91071933..40f607ee 100644 --- a/Makefile +++ b/Makefile @@ -9,16 +9,21 @@ LDFLAGS := -lboost_system -lboost_thread -lboost_filesystem -lboost_regex ifdef SYSTEMROOT RM = del /Q FixPath = $(subst /,\,$1) + MKDIR = mkdir else ifeq ($(shell uname), Linux) RM = rm -f FixPath = $1 + MKDIR = mkdir -p endif endif all: $(MAIN) -obj/%.o: %.cpp $(INCS) +prep: + $(MKDIR) obj + +obj/%.o: %.cpp $(INCS) prep $(CXX) $(CPPFLAGS) -o $@ -c $< $(MAIN): $(OBJS) From 1521389aaf2095ca6af54a62050c4ca4e4a47621 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Fri, 5 Aug 2016 09:28:02 +0200 Subject: [PATCH 4/5] make: provide install/uninstall rules making the makefile more common in providing a valid install/uninstall rule. The rules allow to set DESTDIR if needed and to overwrite the default PREFIX of /usr/local. Signed-off-by: Christian Ehrhardt --- Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Makefile b/Makefile index 40f607ee..51559601 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ MAIN := tuo.exe SRCS := $(wildcard *.cpp) OBJS := $(patsubst %.cpp,obj/%.o,$(SRCS)) INCS := $(wildcard *.h) +PREFIX ?= /usr/local CPPFLAGS := -Wall -Werror -std=gnu++11 -O3 -DNDEBUG LDFLAGS := -lboost_system -lboost_thread -lboost_filesystem -lboost_regex @@ -32,6 +33,17 @@ $(MAIN): $(OBJS) clean: $(RM) $(call FixPath,obj/*.o) +.PHONY: install +install: + $(MKDIR) $(DESTDIR)$(PREFIX)/bin + cp tuo.exe $(DESTDIR)$(PREFIX)/bin/ + cp update_xml.sh $(DESTDIR)$(PREFIX)/bin/ + +.PHONY: uninstall +uninstall: + $(RM) $(DESTDIR)$(PREFIX)/bin/tuo.exe + $(RM) $(DESTDIR)$(PREFIX)/bin/update_xml.sh + # build a snap for cross distribution availability # cleanbuild uses snapcracft and lxd snap: From cdf94c4bbee785e2e8b3a44ca89c900ca297d175 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Fri, 5 Aug 2016 09:40:45 +0200 Subject: [PATCH 5/5] snap: simplify snapcraft yaml I realized that fixing up the TUO build in the snap plugin was kind of an exercise for me back then. But there is no reason to do so. Now that the build issues are fixed I can simplify the snapcraft.yaml to use the default make plugin. Signed-off-by: Christian Ehrhardt --- parts/plugins/toumakefixup.py | 41 ----------------------------------- snapcraft.yaml | 6 ++--- 2 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 parts/plugins/toumakefixup.py diff --git a/parts/plugins/toumakefixup.py b/parts/plugins/toumakefixup.py deleted file mode 100644 index b9eee6cc..00000000 --- a/parts/plugins/toumakefixup.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- -# -# Copyright (C) 2016 Canonical Ltd -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3 as -# published by the Free Software Foundation. -# -# 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 . - - -import logging - -import snapcraft - -LOG = logging.getLogger(__name__) - -class TUOMake(snapcraft.BasePlugin): - """Fixup broken upstream build - Add missing dir and fake missing install target - """ - def __init__(self, name, options, project): - super().__init__(name, options, project) - - def build(self): - super().build() - LOG.info("TUOMake: Fixup build environment") - self.run(['mkdir', '-p', 'obj']) - LOG.info("TUOMake: Build") - self.run(['make'] + ['-j{}'.format(self.project.parallel_build_count)]) - targetdir = self.installdir+'/usr/bin' - LOG.info("TUOMake: Fake install") - self.run(['cp', 'tuo.exe', targetdir]) - self.run(['cp', 'update_xml.sh', targetdir]) - LOG.info("TUOMake: Finished") diff --git a/snapcraft.yaml b/snapcraft.yaml index 7e932555..5079fde5 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -9,17 +9,17 @@ confinement: strict apps: sim: - command: usr/bin/tuo.exe + command: usr/local/bin/tuo.exe plugs: [home] updatexml: - command: usr/bin/update_xml.sh + command: usr/local/bin/update_xml.sh plugs: [home, network] parts: tyrant-unleashed-optimizer: # as we are part of the tuo git tree then just build locally source: . - plugin: toumakefixup + plugin: make build-packages: - g++ - make