From 038d45f9640aca15542bdf486c1f6c98e2714748 Mon Sep 17 00:00:00 2001
From: tobtoht <thotbot@protonmail.com>
Date: Sat, 10 Jul 2021 14:01:29 +0200
Subject: [PATCH] Build: TOR_VERSION

---
 CMakeLists.txt     |  5 -----
 Dockerfile         |  3 ++-
 Dockerfile.windows |  3 ++-
 Makefile           | 37 +++++++------------------------------
 4 files changed, 11 insertions(+), 37 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8d5e71b..82e8716 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -181,11 +181,6 @@ if(TOR_BIN)
         execute_process(COMMAND bash -c "touch ${CMAKE_CURRENT_SOURCE_DIR}/src/tor/libevent-2.1.7.dylib")
     endif()
 
-    execute_process(COMMAND bash -c "${TOR_BIN} --version --quiet" OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE out RESULT_VARIABLE ret)
-    if (ret EQUAL "0")
-        string(REGEX MATCH "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]" version ${out})
-        set(TOR_VERSION "${version}")
-    endif()
     message(STATUS "Embedded Tor version: ${TOR_VERSION}")
     configure_file("cmake/config-feather.h.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/src/config-feather.h")
 
diff --git a/Dockerfile b/Dockerfile
index c24034c..793cda0 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -12,6 +12,7 @@ ENV DEBIAN_FRONTEND=noninteractive
 # Feather build flags
 ENV CHECK_UPDATES=ON
 ENV WITH_SCANNER=ON
+ENV TOR_VERSION=0.4.6.6
 
 COPY --from=featherwallet/feather-deps:linux-beta-8 /deps /deps
 COPY --from=featherwallet/feather-deps:linux-beta-8 /var/cache/apt/archives /archives
@@ -230,7 +231,7 @@ RUN git clone -b v1.2.11 --depth 1 https://github.com/madler/zlib && \
 # Tor: Optional for Feather (-DTOR_BIN)
 # Binary can be embedded in Feather
 ENV TOR_BIN=/usr/local/tor/bin/tor
-RUN git clone -b tor-0.4.6.6 --depth 1 https://git.torproject.org/tor.git && \
+RUN git clone -b tor-$TOR_VERSION --depth 1 https://git.torproject.org/tor.git && \
     cd tor && \
     git reset --hard 60d1fb3d37274e29e9e88620d77e1636ef922561 && \
     ./autogen.sh && \
diff --git a/Dockerfile.windows b/Dockerfile.windows
index fedc93d..a81b22e 100644
--- a/Dockerfile.windows
+++ b/Dockerfile.windows
@@ -11,6 +11,7 @@ ENV WITH_SCANNER=ON
 
 ENV OPENSSL_ROOT_DIR=/usr/local/openssl/
 ENV TOR_BIN=/usr/local/tor/bin/tor.exe
+ENV TOR_VERSION=0.4.6.6
 
 RUN apt update && \
     apt install -y \
@@ -154,7 +155,7 @@ RUN wget https://github.com/libevent/libevent/releases/download/release-2.1.11-s
     make -j$THREADS install && \
     rm -rf $(pwd)
 
-RUN git clone -b tor-0.4.6.6 --depth 1 https://git.torproject.org/tor.git && \
+RUN git clone -b tor-$TOR_VERSION --depth 1 https://git.torproject.org/tor.git && \
     cd tor  && \
     git reset --hard 60d1fb3d37274e29e9e88620d77e1636ef922561 && \
     ./autogen.sh && \
diff --git a/Makefile b/Makefile
index c17ab0e..704f82b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,30 +1,5 @@
-# Copyright (c) 2014-2021, The Monero Project
-#
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without modification, are
-# permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this list of
-#    conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice, this list
-#    of conditions and the following disclaimer in the documentation and/or other
-#    materials provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors may be
-#    used to endorse or promote products derived from this software without specific
-#    prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
-# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (c) 2020-2021, The Monero Project.
 
 CMAKEFLAGS = \
 	-DARCH=x86_64 \
@@ -43,11 +18,12 @@ CMAKEFLAGS = \
 	$(CMAKEFLAGS_EXTRA)
 
 release-static: CMAKEFLAGS += -DBUILD_TAG="linux-x64"
-release-static: CMAKEFLAGS += -DTOR_BIN=$(or ${TOR_BIN},OFF)
+release-static: CMAKEFLAGS += -DTOR_BIN=$(or ${TOR_BIN}, Off)
+release-static: CMAKEFLAGS += -DTOR_VERSION=$(or ${TOR_VERSION}, Off)
 release-static: CMAKEFLAGS += -DCHECK_UPDATES=$(or ${CHECK_UPDATES}, Off)
 release-static: CMAKEFLAGS += -DWITH_SCANNER=$(or ${WITH_SCANNER}, Off)
 release-static: CMAKEFLAGS += -DCMAKE_BUILD_TYPE=Release
-release-static: CMAKEFLAGS += -DREPRODUCIBLE=$(or ${SOURCE_DATE_EPOCH},OFF)
+release-static: CMAKEFLAGS += -DREPRODUCIBLE=$(or ${SOURCE_DATE_EPOCH}, Off)
 release-static:
 	cmake -Bbuild $(CMAKEFLAGS)
 	$(MAKE) -Cbuild
@@ -57,7 +33,8 @@ depends:
 	cd build/$(target)/release && cmake -D STATIC=ON -DREPRODUCIBLE=$(or ${SOURCE_DATE_EPOCH},OFF) -DTOR_VERSION=$(or ${TOR_VERSION}, OFF) -DTOR_BIN=$(or ${TOR_BIN},OFF) -DCHECK_UPDATES=$(or ${CHECK_UPDATES}, OFF) -D DEV_MODE=$(or ${DEV_MODE},OFF) -D BUILD_TAG=$(tag) -D CMAKE_BUILD_TYPE=Release -D CMAKE_TOOLCHAIN_FILE=$(root)/$(target)/share/toolchain.cmake ../../.. && $(MAKE)
 
 mac-release: CMAKEFLAGS += -DSTATIC=Off
-mac-release: CMAKEFLAGS += -DTOR_BIN=$(or ${TOR_BIN},OFF)
+mac-release: CMAKEFLAGS += -DTOR_BIN=$(or ${TOR_BIN}, Off)
+mac-release: CMAKEFLAGS += -DTOR_VERSION=$(or ${TOR_VERSION}, Off)
 mac-release: CMAKEFLAGS += -DCHECK_UPDATES=$(or ${CHECK_UPDATES}, Off)
 mac-release: CMAKEFLAGS += -DWITH_SCANNER=$(or ${WITH_SCANNER}, On)
 mac-release: CMAKEFLAGS += -DBUILD_TAG="mac-x64"