nix: Use status-go commit sha1 in Nix expression to allow for moving branches

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Pedro Pombeiro 2019-07-19 20:42:16 +02:00 committed by Jakub Sokołowski
parent f6527f014e
commit 67d21c98c1
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
12 changed files with 366 additions and 36 deletions

View File

@ -1 +0,0 @@
status-im

View File

@ -1,3 +0,0 @@
## DO NOT EDIT THIS FILE BY HAND. USE `scripts/update-status-go.sh <tag>` instead
1nm0b1nbz4ly2fx6n2pybrfa1m9x0zzj7kkkqf7fwjxg6hjnp6y5

View File

@ -1,3 +0,0 @@
## DO NOT EDIT THIS FILE BY HAND. USE `scripts/update-status-go.sh <tag>` instead
v0.30.0-beta.0

View File

@ -1,8 +1,13 @@
apply plugin: 'com.android.library'
def getStatusGoVersion = { ->
version = new File('../STATUS_GO_VERSION').text
return version.tokenize('\n').last().replaceAll("\\s","")
def jsonSlurper = new groovy.json.JsonSlurper()
def content = new File('../status-go-version.json').text
def object = jsonSlurper.parseText(content)
assert object instanceof Map
return object.version
}
android {

View File

@ -13,19 +13,33 @@ if (WIN32)
# Right now we only build status-go from source for Windows, since that needs to be cross-compiled with the toolchain in Conan
#
include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
include(JSONParser.cmake)
find_package(Go REQUIRED)
file(STRINGS "../../../STATUS_GO_OWNER" STATUS_GO_OWNER)
file(STRINGS "../../../STATUS_GO_VERSION" STATUS_GO_VERSION)
list(GET STATUS_GO_VERSION -1 STATUS_GO_VERSION)
set(versionJSONFilePath "../../../status-go-version.json")
file(READ ${versionJSONFilePath} versionJSON)
sbeParseJson(json versionJSON)
set(owner ${json.owner})
if(NOT owner)
set(owner "status-im")
message(WARNING "Repository owner name missing from ${versionJSONFilePath}, defaulting to ${owner}")
endif()
set(version ${json.version})
if(NOT version)
message(FATAL_ERROR "Version name missing from ${versionJSONFilePath}")
endif()
set(commit ${json.commit-sha1})
if(NOT commit)
message(FATAL_ERROR "Commit SHA1 missing from ${versionJSONFilePath}")
endif()
if (CUSTOM_STATUSGO_BUILD_DIR_PATH)
set(StatusGo_ROOT ${CUSTOM_STATUSGO_BUILD_DIR_PATH})
else()
set(StatusGo_ROOT "${CMAKE_CURRENT_BINARY_DIR}/StatusGo")
endif()
set(StatusGo_PREFIX "${StatusGo_ROOT}/src/github.com/${STATUS_GO_OWNER}")
set(StatusGo_PREFIX "${StatusGo_ROOT}/src/github.com/${owner}")
set(StatusGo_SOURCE_DIR "${StatusGo_PREFIX}/status-go")
set(StatusGo_INCLUDE_DIR "${StatusGo_SOURCE_DIR}/build/bin")
set(StatusGo_STATIC_LIB
@ -38,8 +52,8 @@ if (WIN32)
ExternalProject_Add(StatusGo_ep
PREFIX ${StatusGo_PREFIX}
SOURCE_DIR ${StatusGo_SOURCE_DIR}
URL https://status-go.ams3.digitaloceanspaces.com/status-go-desktop-${STATUS_GO_VERSION}.zip
https://github.com/${STATUS_GO_OWNER}/status-go/archive/${STATUS_GO_VERSION}.zip
URL https://status-go.ams3.digitaloceanspaces.com/status-go-desktop-${version}.zip
https://github.com/${owner}/status-go/archive/${commit}.zip
BUILD_BYPRODUCTS ${StatusGo_STATIC_LIB}
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${CONFIGURE_SCRIPT} ${CMAKE_SYSTEM_NAME} ${GO_ROOT_PATH} ${StatusGo_ROOT} ${StatusGo_SOURCE_DIR} ${CMAKE_C_COMPILER} ${CMAKE_CXX_COMPILER}
BUILD_COMMAND ""

View File

@ -0,0 +1,300 @@
# https://github.com/sbellus/json-cmake/blob/master/JSONParser.cmake
cmake_minimum_required(VERSION 3.1)
if (DEFINED JSonParserGuard)
return()
endif()
set(JSonParserGuard yes)
macro(sbeParseJson prefix jsonString)
cmake_policy(PUSH)
set(json_string "${${jsonString}}")
string(LENGTH "${json_string}" json_jsonLen)
set(json_index 0)
set(json_AllVariables ${prefix})
set(json_ArrayNestingLevel 0)
set(json_MaxArrayNestingLevel 0)
_sbeParse(${prefix})
unset(json_index)
unset(json_AllVariables)
unset(json_jsonLen)
unset(json_string)
unset(json_value)
unset(json_inValue)
unset(json_name)
unset(json_inName)
unset(json_newPrefix)
unset(json_reservedWord)
unset(json_arrayIndex)
unset(json_char)
unset(json_end)
unset(json_ArrayNestingLevel)
foreach(json_nestingLevel RANGE ${json_MaxArrayNestingLevel})
unset(json_${json_nestingLevel}_arrayIndex)
endforeach()
unset(json_nestingLevel)
unset(json_MaxArrayNestingLevel)
cmake_policy(POP)
endmacro()
macro(sbeClearJson prefix)
foreach(json_var ${${prefix}})
unset(${json_var})
endforeach()
unset(${prefix})
unset(json_var)
endmacro()
macro(sbePrintJson prefix)
foreach(json_var ${${prefix}})
message("${json_var} = ${${json_var}}")
endforeach()
endmacro()
macro(_sbeParse prefix)
while(${json_index} LESS ${json_jsonLen})
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
if("\"" STREQUAL "${json_char}")
_sbeParseNameValue(${prefix})
elseif("{" STREQUAL "${json_char}")
_sbeMoveToNextNonEmptyCharacter()
_sbeParseObject(${prefix})
elseif("[" STREQUAL "${json_char}")
_sbeMoveToNextNonEmptyCharacter()
_sbeParseArray(${prefix})
endif()
if(${json_index} LESS ${json_jsonLen})
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
else()
break()
endif()
if ("}" STREQUAL "${json_char}" OR "]" STREQUAL "${json_char}")
break()
endif()
_sbeMoveToNextNonEmptyCharacter()
endwhile()
endmacro()
macro(_sbeParseNameValue prefix)
set(json_name "")
set(json_inName no)
while(${json_index} LESS ${json_jsonLen})
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
# check if name ends
if("\"" STREQUAL "${json_char}" AND json_inName)
set(json_inName no)
_sbeMoveToNextNonEmptyCharacter()
if(NOT ${json_index} LESS ${json_jsonLen})
break()
endif()
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
set(json_newPrefix ${prefix}.${json_name})
set(json_name "")
if(":" STREQUAL "${json_char}")
_sbeMoveToNextNonEmptyCharacter()
if(NOT ${json_index} LESS ${json_jsonLen})
break()
endif()
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
if("\"" STREQUAL "${json_char}")
_sbeParseValue(${json_newPrefix})
break()
elseif("{" STREQUAL "${json_char}")
_sbeMoveToNextNonEmptyCharacter()
_sbeParseObject(${json_newPrefix})
break()
elseif("[" STREQUAL "${json_char}")
_sbeMoveToNextNonEmptyCharacter()
_sbeParseArray(${json_newPrefix})
break()
else()
# reserved word starts
_sbeParseReservedWord(${json_newPrefix})
break()
endif()
else()
# name without value
list(APPEND ${json_AllVariables} ${json_newPrefix})
set(${json_newPrefix} "")
break()
endif()
endif()
if(json_inName)
# remove escapes
if("\\" STREQUAL "${json_char}")
math(EXPR json_index "${json_index} + 1")
if(NOT ${json_index} LESS ${json_jsonLen})
break()
endif()
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
endif()
set(json_name "${json_name}${json_char}")
endif()
# check if name starts
if("\"" STREQUAL "${json_char}" AND NOT json_inName)
set(json_inName yes)
endif()
_sbeMoveToNextNonEmptyCharacter()
endwhile()
endmacro()
macro(_sbeParseReservedWord prefix)
set(json_reservedWord "")
set(json_end no)
while(${json_index} LESS ${json_jsonLen} AND NOT json_end)
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
if("," STREQUAL "${json_char}" OR "}" STREQUAL "${json_char}" OR "]" STREQUAL "${json_char}")
set(json_end yes)
else()
set(json_reservedWord "${json_reservedWord}${json_char}")
math(EXPR json_index "${json_index} + 1")
endif()
endwhile()
list(APPEND ${json_AllVariables} ${prefix})
string(STRIP "${json_reservedWord}" json_reservedWord)
set(${prefix} ${json_reservedWord})
endmacro()
macro(_sbeParseValue prefix)
cmake_policy(SET CMP0054 NEW) # turn off implicit expansions in if statement
set(json_value "")
set(json_inValue no)
while(${json_index} LESS ${json_jsonLen})
# fast path for copying strings
if (json_inValue)
# attempt to gobble up to 128 bytes of string
string(SUBSTRING "${json_string}" ${json_index} 128 try_gobble)
# consume a piece of string we can just straight copy before encountering \ or "
string(REGEX MATCH "^[^\"\\\\]+" simple_copy "${try_gobble}")
string(CONCAT json_value "${json_value}" "${simple_copy}")
string(LENGTH "${simple_copy}" copy_length)
math(EXPR json_index "${json_index} + ${copy_length}")
endif()
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
# check if json_value ends, it is ended by "
if("\"" STREQUAL "${json_char}" AND json_inValue)
set(json_inValue no)
set(${prefix} ${json_value})
list(APPEND ${json_AllVariables} ${prefix})
_sbeMoveToNextNonEmptyCharacter()
break()
endif()
if(json_inValue)
# if " is escaped consume
if("\\" STREQUAL "${json_char}")
math(EXPR json_index "${json_index} + 1")
if(NOT ${json_index} LESS ${json_jsonLen})
break()
endif()
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
if(NOT "\"" STREQUAL "${json_char}")
# if it is not " then copy also escape character
set(json_char "\\${json_char}")
endif()
endif()
_sbeAddEscapedCharacter("${json_char}")
endif()
# check if value starts
if("\"" STREQUAL "${json_char}" AND NOT json_inValue)
set(json_inValue yes)
endif()
math(EXPR json_index "${json_index} + 1")
endwhile()
endmacro()
macro(_sbeAddEscapedCharacter char)
string(CONCAT json_value "${json_value}" "${char}")
endmacro()
macro(_sbeParseObject prefix)
_sbeParse(${prefix})
_sbeMoveToNextNonEmptyCharacter()
endmacro()
macro(_sbeParseArray prefix)
math(EXPR json_ArrayNestingLevel "${json_ArrayNestingLevel} + 1")
set(json_${json_ArrayNestingLevel}_arrayIndex 0)
set(${prefix} "")
list(APPEND ${json_AllVariables} ${prefix})
while(${json_index} LESS ${json_jsonLen})
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
if("\"" STREQUAL "${json_char}")
# simple value
list(APPEND ${prefix} ${json_${json_ArrayNestingLevel}_arrayIndex})
_sbeParseValue(${prefix}_${json_${json_ArrayNestingLevel}_arrayIndex})
elseif("{" STREQUAL "${json_char}")
# object
_sbeMoveToNextNonEmptyCharacter()
list(APPEND ${prefix} ${json_${json_ArrayNestingLevel}_arrayIndex})
_sbeParseObject(${prefix}_${json_${json_ArrayNestingLevel}_arrayIndex})
else()
list(APPEND ${prefix} ${json_${json_ArrayNestingLevel}_arrayIndex})
_sbeParseReservedWord(${prefix}_${json_${json_ArrayNestingLevel}_arrayIndex})
endif()
if(NOT ${json_index} LESS ${json_jsonLen})
break()
endif()
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
if("]" STREQUAL "${json_char}")
_sbeMoveToNextNonEmptyCharacter()
break()
elseif("," STREQUAL "${json_char}")
math(EXPR json_${json_ArrayNestingLevel}_arrayIndex "${json_${json_ArrayNestingLevel}_arrayIndex} + 1")
endif()
_sbeMoveToNextNonEmptyCharacter()
endwhile()
if(${json_MaxArrayNestingLevel} LESS ${json_ArrayNestingLevel})
set(json_MaxArrayNestingLevel ${json_ArrayNestingLevel})
endif()
math(EXPR json_ArrayNestingLevel "${json_ArrayNestingLevel} - 1")
endmacro()
macro(_sbeMoveToNextNonEmptyCharacter)
math(EXPR json_index "${json_index} + 1")
if(${json_index} LESS ${json_jsonLen})
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
while(${json_char} MATCHES "[ \t\n\r]" AND ${json_index} LESS ${json_jsonLen})
math(EXPR json_index "${json_index} + 1")
string(SUBSTRING "${json_string}" ${json_index} 1 json_char)
endwhile()
endif()
endmacro()

View File

@ -17,7 +17,7 @@ let
baseGo = pkgs.go_1_11;
go = pkgs.callPackage ./patched-go { inherit baseGo; };
buildGoPackage = pkgs.buildGoPackage.override { inherit go; };
desktop = pkgs.callPackage ./desktop { inherit target-os stdenv status-go pkgs nodejs; inherit (pkgs) darwin; go = baseGo; };
desktop = pkgs.callPackage ./desktop { inherit target-os stdenv status-go pkgs go nodejs; inherit (pkgs) darwin; };
mobile = pkgs.callPackage ./mobile { inherit target-os config stdenv pkgs mkShell nodejs yarn status-go maven localMavenRepoBuilder mkFilter prod-build-fn; inherit (pkgs.xcodeenv) composeXcodeWrapper; };
status-go = pkgs.callPackage ./status-go { inherit target-os go buildGoPackage; inherit (mobile.ios) xcodeWrapper; androidPkgs = mobile.android.androidComposition; };
# mkFilter is a function that allows filtering a directory structure (used for filtering source files being captured in a closure)

View File

@ -38,7 +38,7 @@ in stdenv.mkDerivation {
"resources"
];
dirsToExclude = [ ".git" ".svn" "CVS" ".hg" ".gradle" "build" "intermediates" "libs" "obj" ];
filesToInclude = [ envFileName "STATUS_GO_VERSION" "VERSION" ];
filesToInclude = [ envFileName "status-go-version.json" "VERSION" ];
root = path;
};
};

View File

@ -11,12 +11,15 @@
with stdenv;
let
inherit (stdenv.lib) strings;
removeReferences = [ go ];
removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}'';
args = removeAttrs args' [ "buildMessage" ]; # Remove our arguments from args before passing them on to buildGoPackage
buildStatusGo = buildGoPackage (args // {
name = "${repo}-${version}-${host}";
pname = repo;
version = "${version}-${strings.substring 0 7 rev}-${host}";
nativeBuildInputs =
nativeBuildInputs ++
@ -75,6 +78,10 @@ let
return
'';
passthru = {
inherit owner version rev;
};
meta = {
# Add default meta information
inherit (meta) platforms;

View File

@ -3,20 +3,21 @@
androidPkgs, xcodeWrapper }:
let
inherit (stdenv.lib) catAttrs concatStrings fileContents last makeBinPath optional optionalString splitString;
inherit (stdenv.lib) catAttrs concatStrings fileContents importJSON makeBinPath optional optionalString strings;
platform = callPackage ../platform.nix { inherit target-os; };
utils = callPackage ../utils.nix { inherit xcodeWrapper; };
gomobile = callPackage ./gomobile { inherit (androidPkgs) platform-tools; inherit target-os xcodeWrapper utils buildGoPackage; };
buildStatusGoDesktopLib = callPackage ./build-desktop-status-go.nix { inherit buildGoPackage go xcodeWrapper utils; };
buildStatusGoMobileLib = callPackage ./build-mobile-status-go.nix { inherit buildGoPackage go gomobile xcodeWrapper utils; };
extractStatusGoConfig = f: last (splitString "\n" (fileContents f));
owner = fileContents ../../STATUS_GO_OWNER;
version = extractStatusGoConfig ../../STATUS_GO_VERSION; # TODO: Simplify this path search with lib.locateDominatingFile
sha256 = extractStatusGoConfig ../../STATUS_GO_SHA256;
extractStatusGoConfig = callPackage ./extract-status-go-config.nix { inherit (stdenv) lib; };
versionJSON = importJSON ../../status-go-version.json; # TODO: Simplify this path search with lib.locateDominatingFile
owner = versionJSON.owner;
version = versionJSON.version;
sha256 = versionJSON.src-sha256;
repo = "status-go";
rev = version;
rev = versionJSON.commit-sha1;
goPackagePath = "github.com/${owner}/${repo}";
src = fetchFromGitHub { inherit rev owner repo sha256; name = "${repo}-source"; };
src = fetchFromGitHub { inherit rev owner repo sha256; name = "${repo}-${strings.substring 0 7 rev}-source"; };
mobileConfigs = {
android = {

View File

@ -23,18 +23,21 @@ if [ $# -eq 0 ]; then
exit 1
fi
STATUS_GO_OWNER="$(cat ${GIT_ROOT}/STATUS_GO_OWNER)"
repoUrl="https://github.com/${STATUS_GO_OWNER:=status-im}/status-go"
STATUS_GO_VERSION=$1
STATUS_GO_SHA256=$(nix-prefetch-url --unpack https://github.com/${STATUS_GO_OWNER}/status-go/archive/${STATUS_GO_VERSION}.zip)
STATUS_GO_SHA256=$(nix-prefetch-url --unpack ${repoUrl}/archive/${STATUS_GO_VERSION}.zip)
STATUS_GO_COMMIT_SHA1=$(git ls-remote ${repoUrl} U ${STATUS_GO_VERSION} | cut -f1)
cat << EOF > ${GIT_ROOT}/STATUS_GO_VERSION
## DO NOT EDIT THIS FILE BY HAND. USE \`scripts/update-status-go.sh <tag>\` instead
$STATUS_GO_VERSION
cat << EOF > ${GIT_ROOT}/status-go-version.json
{
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "${STATUS_GO_OWNER}",
"version": "${STATUS_GO_VERSION}",
"commit-sha1": "${STATUS_GO_COMMIT_SHA1}",
"src-sha256": "${STATUS_GO_SHA256}"
}
EOF
cat << EOF > ${GIT_ROOT}/STATUS_GO_SHA256
## DO NOT EDIT THIS FILE BY HAND. USE \`scripts/update-status-go.sh <tag>\` instead
$STATUS_GO_SHA256
EOF
echo "SHA-1 for ${STATUS_GO_VERSION} is ${STATUS_GO_COMMIT_SHA1}.
SHA-256 for source archive is ${STATUS_GO_SHA256}
Owner is ${STATUS_GO_OWNER}"

7
status-go-version.json Normal file
View File

@ -0,0 +1,7 @@
{
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"version": "v0.30.0-beta.0",
"commit-sha1": "f2139105bfa9a82ff4f8cb2ec6b98c2149964a71",
"src-sha256": "1nm0b1nbz4ly2fx6n2pybrfa1m9x0zzj7kkkqf7fwjxg6hjnp6y5"
}