From 6b2a9dabbfad4d64268967a32dff0f1dc55763de Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 16 May 2020 13:28:52 +0200 Subject: Makefile cleanup, included missing files --- libcommon/Makefile | 23 ++--------------------- libcommon/tempfile.cpp | 27 +++++++++++++++++++++++++++ libcommon/tempfile.h | 16 ++++++++++++++++ 3 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 libcommon/tempfile.cpp create mode 100644 libcommon/tempfile.h (limited to 'libcommon') diff --git a/libcommon/Makefile b/libcommon/Makefile index 932ee90..ab76ed1 100644 --- a/libcommon/Makefile +++ b/libcommon/Makefile @@ -30,8 +30,6 @@ else CXXFLAGS+=-std=c++17 endif -CXXTESTFLAGS=-Igoogletest/include -Igooglemock/include/ -Igoogletest -Igooglemock - LIBS=\ -lboost_context \ -lboost_coroutine \ @@ -64,33 +62,18 @@ PROGSRC=\ stringutil.cpp \ tempfile.cpp -TESTSRC=\ - test-webserver.cpp \ - googlemock/src/gmock-all.cpp \ - googletest/src/gtest-all.cpp \ - $(PROGSRC) - SRC=$(PROGSRC) all: $(PROJECTNAME).a -# testsuite ---------------------------------------------- -test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) - $(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ - $(PROJECTNAME).a: $(SRC:.cpp=.o) ar rcs $@ $^ -dep: $(TESTSRC:.cpp=.d) - %.d: %.cpp - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -MM -MP -MF $@ -c $< + $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< %.o: %.cpp %.d - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ - -googletest/src/%.o: googletest/src/%.cc - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ + $(CXX) $(CXXFLAGS) -c $< -o $@ # dependencies @@ -111,8 +94,6 @@ $(DISTROS): deb-src debs: $(DISTROS) clean: - -rm -f test-$(PROJECTNAME) $(PROJECTNAME) - -find . -name '*.a' -o -name '*.o' -o -name '*.so' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f zip: clean -rm -f ../$(PROJECTNAME).zip diff --git a/libcommon/tempfile.cpp b/libcommon/tempfile.cpp new file mode 100644 index 0000000..5d3a086 --- /dev/null +++ b/libcommon/tempfile.cpp @@ -0,0 +1,27 @@ +#include "tempfile.h" + +#include + +namespace fs = std::filesystem; +using namespace std::string_literals; + +fs::path Tempfile::GetPath() const +{ + return m_path; +} + +Tempfile::Tempfile() { + try { + m_path = std::string{tmpnam(NULL)} + ".zip"s; + } catch (const std::exception& ex) { + throw std::runtime_error("Tempfile error: "s + ex.what()); + } +} + +Tempfile::~Tempfile() { + try { + fs::remove_all(m_path); + } catch (const std::exception& ex) { + std::cerr << "Warning: Couldn't remove temporary file " << m_path << std::endl; + } +} diff --git a/libcommon/tempfile.h b/libcommon/tempfile.h new file mode 100644 index 0000000..5938fb9 --- /dev/null +++ b/libcommon/tempfile.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +class Tempfile +{ + std::filesystem::path m_path; + + public: + std::filesystem::path GetPath() const; + + Tempfile(); + ~Tempfile(); + }; + + -- cgit v1.2.3