Skip to content

Commit

Permalink
nix: Use status-go commit sha1 in Nix expression to allow for moving …
Browse files Browse the repository at this point in the history
…branches
  • Loading branch information
Pedro Pombeiro committed Jul 19, 2019
1 parent 7230897 commit 80835c5
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 50 deletions.
1 change: 0 additions & 1 deletion STATUS_GO_OWNER

This file was deleted.

3 changes: 0 additions & 3 deletions STATUS_GO_SHA256

This file was deleted.

5 changes: 4 additions & 1 deletion STATUS_GO_VERSION
@@ -1,3 +1,6 @@
## DO NOT EDIT THIS FILE BY HAND. USE `scripts/update-status-go.sh <tag>` instead

v0.30.0-beta.0
owner=status-im
version=v0.30.0-beta.0
commit-sha1=f2139105bfa9a82ff4f8cb2ec6b98c2149964a71
src-sha256=1nm0b1nbz4ly2fx6n2pybrfa1m9x0zzj7kkkqf7fwjxg6hjnp6y5
2 changes: 1 addition & 1 deletion ci/Jenkinsfile.nix-cache
Expand Up @@ -53,7 +53,7 @@ pipeline {
// Run a Nix build to build/fetch everything that is necessary to instantiate shell.nix for TARGET_OS=all
sh '''
. ~/.nix-profile/etc/profile.d/nix.sh && \
nix-build --pure --no-out-link --show-trace -A shell default.nix
nix-shell --pure --show-trace shell.nix
'''
}
}
Expand Down
5 changes: 3 additions & 2 deletions modules/react-native-status/android/build.gradle
@@ -1,8 +1,9 @@
apply plugin: 'com.android.library'

def getStatusGoVersion = { ->
version = new File('../STATUS_GO_VERSION').text
return version.tokenize('\n').last().replaceAll("\\s","")
def lines = new File('../STATUS_GO_VERSION').text.tokenize('\n')
def versionLine = lines.find { line -> line.startsWith("version=") }
return versionLine.tokenize('=').last()
}

android {
Expand Down
24 changes: 19 additions & 5 deletions modules/react-native-status/desktop/CMakeLists.txt
Expand Up @@ -16,16 +16,30 @@ if (WIN32)

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)
if(STATUS_GO_VERSION MATCHES ";owner=([^;]+).*")
set(owner ${CMAKE_MATCH_1})
else()
set(owner "status-im")
message(WARNING "Repository owner name missing from STATUS_GO_VERSION, defaulting to ${owner}")
endif()
if(STATUS_GO_VERSION MATCHES ";version=([^;]+).*")
set(version ${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Version name missing from STATUS_GO_VERSION")
endif()
if(STATUS_GO_VERSION MATCHES ";commit-sha1=([^;]+).*")
set(commit ${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Commit SHA1 missing from STATUS_GO_VERSION")
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
Expand All @@ -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 ""
Expand Down
3 changes: 2 additions & 1 deletion nix/bootstrapped-shell.nix
Expand Up @@ -3,12 +3,13 @@
# as well as define STATUS_REACT_HOME
#

{ stdenv, mkShell, git }:
{ stdenv, mkShell, target-os, git }:

let
shell' = shellAttr:
shellAttr // {
nativeBuildInputs = (shellAttr.nativeBuildInputs or []) ++ [ git ];
TARGET_OS = target-os;
shellHook = ''
set -e
Expand Down
4 changes: 2 additions & 2 deletions nix/derivation.nix
Expand Up @@ -10,14 +10,14 @@ let
platform = pkgs.callPackage ./platform.nix { inherit target-os; };
# Declare a specialized mkShell function which adds some bootstrapping
# so that e.g. STATUS_REACT_HOME is automatically available in the shell
mkShell = (import ./bootstrapped-shell.nix { inherit stdenv; inherit (pkgs) mkShell git; });
mkShell = (import ./bootstrapped-shell.nix { inherit stdenv target-os; inherit (pkgs) mkShell git; });
# TODO: Try to use stdenv for iOS. The problem is with building iOS as the build is trying to pass parameters to Apple's ld that are meant for GNU's ld (e.g. -dynamiclib)
stdenv = pkgs.stdenvNoCC;
maven = pkgs.maven;
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)
Expand Down
16 changes: 9 additions & 7 deletions nix/desktop/linux/appimagekit/default.nix
Expand Up @@ -7,18 +7,19 @@
}:

let
owner = "AppImage";
repo = "AppImageKit";
rev = "b0859501df61cde198b54a317c03b41dbafc98b1";
sha256 = "0qqg79jw9w9rs8c2w3lla4kz62ihafrf7jm370pp1dl8y2i81jzg";

appimagekit_src = fetchFromGitHub {
name = "AppImageKit-source";
owner = "AppImage";
repo = "AppImageKit";
rev = "b0859501df61cde198b54a317c03b41dbafc98b1";
sha256 = "0qqg79jw9w9rs8c2w3lla4kz62ihafrf7jm370pp1dl8y2i81jzg";
name = "${repo}-${stdenv.lib.strings.substring 0 7 rev}-source";
inherit owner repo rev sha256;
};

# squashfuse adapted to nix from cmake experession in "${appimagekit_src}/cmake/dependencies.cmake"
appimagekit_squashfuse = squashfuse.overrideAttrs (attrs: rec {
name = "squashfuse-${version}";
pname = "squashfuse";
version = "20161009";

src = fetchFromGitHub {
Expand Down Expand Up @@ -60,7 +61,8 @@ let
});

in stdenv.mkDerivation rec {
name = "appimagekit-20180727";
pname = "appimagekit";
version = "20180727";

src = appimagekit_src;

Expand Down
13 changes: 7 additions & 6 deletions nix/desktop/linux/linuxdeployqt/default.nix
Expand Up @@ -3,17 +3,18 @@
with pkgs;

stdenv.mkDerivation rec {
name = "linuxdeployqt";
pname = "linuxdeployqt";
version = "20181215";
owner = "probonopd";
repo = "linuxdeployqt";
rev = "600fc20ea73ee937a402a2bb6b3663d93fcc1d4b";
sha256 = "05kvkfbhsyadlcggl63rhrw5s36d8qxs8gyihrjn2cjk42xx8r7j";

src =
if stdenv.hostPlatform.system == "x86_64-linux" then
fetchFromGitHub {
name = "${name}-source";
owner = "probonopd";
repo = "linuxdeployqt";
rev = "600fc20ea73ee937a402a2bb6b3663d93fcc1d4b";
sha256 = "05kvkfbhsyadlcggl63rhrw5s36d8qxs8gyihrjn2cjk42xx8r7j";
name = "${repo}-${stdenv.lib.strings.substring 0 7 rev}-source";
inherit owner repo rev sha256;
}
else throw "${name} is not supported on ${stdenv.hostPlatform.system}";

Expand Down
4 changes: 2 additions & 2 deletions nix/desktop/macos/base-image/default.nix
Expand Up @@ -2,7 +2,7 @@

let
package = stdenv.mkDerivation rec {
name = "StatusImAppBundle";
pname = "StatusImAppBundle";
version = "20190515";

src =
Expand All @@ -11,7 +11,7 @@ let
url = "https://desktop-app-files.ams3.digitaloceanspaces.com/Status_${version}.app.zip";
sha256 = "1255jgdp0apqh7qfp752nww91iq39x5mm7rf0wazq2vjahfr4pc5";
}
else throw "${name} is not supported on ${stdenv.hostPlatform.system}";
else throw "${pname} is not supported on ${stdenv.hostPlatform.system}";

nativeBuildInputs = [ unzip ];

Expand Down
9 changes: 8 additions & 1 deletion nix/status-go/build-status-go.nix
Expand Up @@ -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 ++
Expand Down Expand Up @@ -75,6 +78,10 @@ let
return
'';

passthru = {
inherit owner version rev;
};

meta = {
# Add default meta information
inherit (meta) platforms;
Expand Down
14 changes: 7 additions & 7 deletions nix/status-go/default.nix
Expand Up @@ -3,20 +3,20 @@
androidPkgs, xcodeWrapper }:

let
inherit (stdenv.lib) catAttrs concatStrings fileContents last makeBinPath optional optionalString splitString;
inherit (stdenv.lib) catAttrs concatStrings fileContents 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; };
owner = extractStatusGoConfig "owner";
version = extractStatusGoConfig "version";
sha256 = extractStatusGoConfig "src-sha256";
repo = "status-go";
rev = version;
rev = extractStatusGoConfig "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 = {
Expand Down
20 changes: 20 additions & 0 deletions nix/status-go/extract-status-go-config.nix
@@ -0,0 +1,20 @@
#
# This nix expression contains logic to extract the value of a field in the STATUS_GO_VERSION file, when given the field name
#

{ lib }:

let
inherit (lib) fileContents findFirst head splitString;
content = fileContents ../../STATUS_GO_VERSION; # TODO: Simplify this path search with lib.locateDominatingFile
extractStatusGoConfig =
fieldName:
let lines = splitString "\n" content;
# Find the first line containing the field name
matchedLine = findFirst (line: (builtins.match "${fieldName}=.+" line) != null) null lines;
in if matchedLine != null
# If line is found, extract the field value
then head (builtins.match "${fieldName}=(.+)" matchedLine)
else throw "Could not find '${fieldName}' in ${content}";

in extractStatusGoConfig
2 changes: 1 addition & 1 deletion nix/status-go/gomobile/default.nix
Expand Up @@ -10,7 +10,7 @@ let
platform = callPackage ../../platform.nix { inherit target-os; };

in buildGoPackage rec {
name = "gomobile-${version}";
pname = "gomobile";
version = "20190319-${strings.substring 0 7 rev}";
rev = "167ebed0ec6dd457a6b24a4f61db913f0af11f70";
sha256 = "0lspdhikhnhbwv8v0q6fs3a0pd9sjnhkpg8z03m2dc5h6f84m38w";
Expand Down
18 changes: 10 additions & 8 deletions scripts/update-status-go.sh
Expand Up @@ -23,18 +23,20 @@ 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
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}"
3 changes: 1 addition & 2 deletions shell.nix
Expand Up @@ -4,7 +4,7 @@

let
project = import ./default.nix { inherit target-os pkgs nixpkgs-bootstrap; inherit (nixpkgs-bootstrap) config; };
mkShell = pkgs.callPackage ./nix/bootstrapped-shell.nix { inherit stdenv; inherit (pkgs) mkShell; };
mkShell = pkgs.callPackage ./nix/bootstrapped-shell.nix { inherit stdenv target-os; inherit (pkgs) mkShell; };
platform = pkgs.callPackage ./nix/platform.nix { inherit target-os; };
# TODO: Try to use stdenv for iOS. The problem is with building iOS as the build is trying to pass parameters to Apple's ld that are meant for GNU's ld (e.g. -dynamiclib)
stdenv = pkgs.stdenvNoCC;
Expand All @@ -30,6 +30,5 @@ in mkShell {
watchman
];
inputsFrom = [ project.shell ];
TARGET_OS = target-os;
shellHook = project.shell.shellHook;
}

0 comments on commit 80835c5

Please sign in to comment.