-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-native-core): working android module
- Loading branch information
Showing
190 changed files
with
7,203 additions
and
698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) | ||
NAME ?= berty | ||
# FIXME: create a everythingButVendor helper that runs a wildcard but ignores node_modules/ and vendor/, and simplify variables below | ||
GOPATH ?= $(HOME)/go | ||
GO_ROOT_PACKAGES := . ../network | ||
GO_ROOT_PACKAGES_VENDORS := ./vendor/% ../network/vendor/% | ||
BIN ?= $(GOPATH)/bin/berty | ||
BUILD_MODE ?= dev | ||
SOURCES = $(strip $(call rwildcard, $(GO_ROOT_PACKAGES), *.go)) | ||
OUR_SOURCES = $(filter-out $(GO_ROOT_PACKAGES_VENDORS),$(SOURCES)) | ||
PROTOS = $(strip $(call rwildcard, $(GO_ROOT_PACKAGES), *.proto)) | ||
OUR_PROTOS = $(filter-out $(GO_ROOT_PACKAGES_VENDORS),$(PROTOS)) | ||
PROTOC_OPTS = -I /protobuf:./vendor/berty.tech:./vendor/github.com/gogo/protobuf:vendor:../network:. | ||
SERVICE_PROTOS = $(call rwildcard, api, *.proto) | ||
GENERATED_PATTERNS = %.validate.gen.go %.service.gen.go %generated.gen.go %kind.gen.go %.pb.go %.gen.js | ||
GENERATED_FILES = $(filter $(GENERATED_PATTERNS),$(filter-out $(call rwildcard ./vendor/,*),$(call rwildcard,./,*))) | ||
GENERATION_TARGETS = .kind.generated .client.generated .pb.generated | ||
CGO_LDFLAGS ?= -L/usr/local/opt/openssl/lib | ||
CGO_CPPFLAGS ?= -I/usr/local/opt/openssl/include | ||
BUILD_ENV ?= GO111MODULE=on CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CPPFLAGS="$(CGO_CPPFLAGS)" | ||
GIT_SHA ?= $(shell git rev-parse HEAD) | ||
GIT_TAG ?= $(shell git describe --tags --always) | ||
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) | ||
GIT_COMMIT_DATE ?= $(shell git show -s --format=%ct $(GIT_SHA)) | ||
GO_ROOT_PKG ?= berty.tech/core | ||
EXT_LDFLAGS ?= -ldflags "-X $(GO_ROOT_PKG).GitSha=$(GIT_SHA) -X $(GO_ROOT_PKG).GitTag=$(GIT_TAG) -X $(GO_ROOT_PKG).GitBranch=$(GIT_BRANCH) -X $(GO_ROOT_PKG).BuildMode=$(BUILD_MODE) -X $(GO_ROOT_PKG).commitDate=$(GIT_COMMIT_DATE)" | ||
RUN_DAEMON_OPTS ?= --log-level=debug --notification | ||
TEST_PATHS ?= $(shell go list ./... | grep -v core/platform/desktop) | ||
TEST_OPTS ?= -v | ||
TEST_TIMEOUT ?= 3m | ||
TEST_CMD ?= go test -test.timeout $(TEST_TIMEOUT) $(TEST_OPTS) $(TEST_PATHS) | ||
PROTOC ?= protoc | ||
GIN_OPTS ?= --immediate --port=2999 --appPort=1337 --build=./cmd/berty --excludeDir vendor | ||
RN_PATH ?= ../client | ||
|
||
## | ||
## phonies | ||
## | ||
|
||
.PHONY: help | ||
help: | ||
@echo "Core commands:" | ||
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | grep -v / | sed 's/^/ $(HELP_MSG_PREFIX)make /' | ||
|
||
.PHONY: callvis | ||
callvis: | ||
cd $$GOPATH/src/berty.tech/core/cmd/berty && $(BUILD_ENV) GO111MODULE=auto go-callvis \ | ||
-nostd \ | ||
-group=pkg,type \ | ||
-focus=berty.tech/core/cmd/berty \ | ||
-ignore=berty.tech/core/vendor/go.uber.org,berty.tech/core/pkg/tracing,berty.tech/core/vendor/github.com,berty.tech/core/vendor/golang.org,berty.tech/core/vendor/google.golang.org,berty.tech/core/vendor/gopkg.in \ | ||
. | ||
# -include=berty.tech/core/vendor/github.com/libp2p \ | ||
|
||
.PHONY: deps | ||
deps: ./vendor | ||
|
||
./vendor: ./go.mod | ||
GO111MODULE=on go mod vendor | ||
|
||
.PHONY: dev | ||
dev: install | ||
@if ! command -v gin &>/dev/null; then go get github.com/codegangsta/gin; fi | ||
$(BUILD_ENV) gin $(GIN_OPTS) run -- daemon $(RUN_DAEMON_OPTS) | ||
|
||
.PHONY: run | ||
run: $(BIN) | ||
$(BIN) daemon $(RUN_DAEMON_OPTS) | ||
|
||
.PHONY: install | ||
install: $(BIN) | ||
|
||
$(BIN): generate $(OUR_SOURCES) | ||
$(BUILD_ENV) go install $(EXT_LDFLAGS) -v ./cmd/... | ||
|
||
.PHONY: testwatch | ||
testwatch: | ||
@if ! command -v watchman &>/dev/null; then brew install watchman; fi | ||
while true; do clear; $(BUILD_ENV) $(TEST_CMD); sleep .3; watchman-wait . -p "**/*.go"; done | ||
|
||
.PHONY: test | ||
test: generate | ||
$(BUILD_ENV) $(TEST_CMD) | ||
|
||
# testloop runs test suite until it fails (without test caching) | ||
.PHONY: testloop | ||
testloop: generate | ||
@if ! command -v watchman &>/dev/null; then go get moul.io/retry; fi | ||
$(BUILD_ENV) retry -r $(TEST_CMD) -count 1 | ||
|
||
.PHONY: integration | ||
integration: install | ||
rm -f /tmp/berty.integration.db | ||
@# initialize a new daemon on a fresh db | ||
$(BIN) daemon --init-only --no-p2p --sql-name=berty.integration.db | ||
|
||
.PHONY: lint | ||
lint: generate | ||
$(BUILD_ENV) golangci-lint run $(TEST_PATHS) | ||
|
||
.PHONY: generate | ||
.generate: export SHELL = /bin/sh | ||
generate: .generated | ||
|
||
.generated: $(PROTOS) | ||
make generate_prepare | ||
docker run \ | ||
--volume="$(PWD)/..:/go/src/berty.tech" \ | ||
--workdir="/go/src/$(GO_ROOT_PKG)" \ | ||
--entrypoint="sh" \ | ||
--rm \ | ||
bertytech/protoc:v15 \ | ||
-xec 'make generate_local' | ||
touch $@ | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f .generated $(GENERATED_FILES) $(GENERATION_TARGETS) $(BIN) | ||
rm -rf vendor | ||
@# FIXME: investigate | ||
rm -rf google gogoproto github.com google.golang.org | ||
cd $(PWD)/../client && make clean.generate | ||
|
||
.PHONY: generate_local | ||
generate_local: $(GENERATION_TARGETS) | ||
@# FIXME: investigate why (sometimes?) there are "github.com" and "google.golang.org" directories generated at the root of core/ | ||
rm -rf google gogoproto github.com google.golang.org | ||
|
||
goimports -w `find . -name "*.pb.go" -or -name "*.gen.go" | grep -v /vendor/` | ||
gofmt -w -s `find . -name "*.pb.go" -or -name "*.gen.go" | grep -v /vendor/` | ||
|
||
.PHONY: generate_prepare | ||
generate_prepare: deps | ||
|
||
.PHONY: _ci_prepare | ||
_ci_prepare: | ||
@# touching files to avoid regenerating files based on modification date | ||
touch $(PROTOS) $(SOURCES) | ||
sleep 1 | ||
touch .generated $(GENERATION_TARGETS) | ||
|
||
## | ||
## file-based rules | ||
## | ||
|
||
%.pb.go: %.proto | ||
@echo $< | ||
$(PROTOC) $(PROTOC_OPTS) \ | ||
--gofast_out="plugins=grpc:$(GOPATH)/src" \ | ||
--gotemplate_out=debug=false,all=true,single-package-mode=false,template_dir=./pkg/validate:. \ | ||
"$(dir $<)"/*.proto | ||
|
||
.kind.generated: $(PROTOS) | ||
$(PROTOC) $(PROTOC_OPTS) --gotemplate_out=debug=false,single-package-mode=true,all=true,template_dir=./entity:./entity ./entity/kind.proto | ||
goimports -w ./entity | ||
touch $@ | ||
|
||
.client.generated: $(PROTOS) | ||
$(PROTOC) $(PROTOC_OPTS) --gotemplate_out=debug=false,all=true,template_dir=./api/node:./api/node ./api/node/service.proto | ||
@set -e; for protodir in `echo $(dir $(SERVICE_PROTOS)) | tr " " "\n" | uniq`; do (set -xe; \ | ||
$(PROTOC) $(PROTOC_OPTS) --gotemplate_out=debug=false,all=false,single-package-mode=true,template_dir=./api/client:./api/client $$protodir/*.proto; \ | ||
); done | ||
@# FIXME: the following hack is due to goimports -w not deleting duplicated imports | ||
goimports -w ./api/client/ | ||
sed -i'' '/^$$/d' api/client/*.gen.go api/client/jsonclient/*.gen.go | ||
goimports -w ./api/client/*.gen.go ./api/client/jsonclient/*.gen.go | ||
sed -i'' '/^$$/d' api/client/*.gen.go api/client/jsonclient/*.gen.go | ||
goimports -w ./api/client/*.gen.go ./api/client/jsonclient/*.gen.go | ||
#$(MAKE) -C ../client generate | ||
touch $@ | ||
|
||
.pb.generated: $(patsubst %.proto,%.pb.go,$(OUR_PROTOS)) | ||
rm -rf google/ # remove directory generated by protoc-gen-gotemplate for proto deps | ||
touch $@ | ||
|
||
|
||
displayprotos: | ||
@echo $(PROTOS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
export PWD = $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))) | ||
|
||
BUILD_MODE ?= dev | ||
|
||
CLIENT_PATH=$(abspath $(PWD)/../../../client) | ||
ANDROID_OUT_PATH ?= $(CLIENT_PATH)/packages/react-native-core/android | ||
ANDROID_CORE_SOURCES_PATH ?= $(CLIENT_PATH)/android | ||
ANDROID_SOURCE_CORE = $(ANDROID_CORE_SOURCES_PATH)/core/core.aar | ||
ANDROID_CORE = $(ANDROID_OUT_PATH)/core.aar | ||
|
||
CORE_PACKAGE := $(abspath $(PWD)/../..) | ||
CORE_MOBILE := $(PWD)/core | ||
CORE_SOURCES := $(shell find $(CORE_PACKAGE) -type f -name "*.go" -not -path "$(CORE_PACKAGE)/platform/*") \ | ||
$(shell find $(CORE_MOBILE) -type f -name "*.go") | ||
|
||
BUILD_PATCH_PATH := $(abspath $(PWD)/../../../build/docker/patch) | ||
|
||
BLE_ROOT = $(ANDROID_CORE_SOURCES_PATH)/ble | ||
BLE_JAR = $(BLE_ROOT)/build/libs/ble.jar | ||
BLE_MANAGER_SOURCE = $(BLE_ROOT)/src/main/java/libp2p/transport/ble/BleManager.java | ||
BLE_BUILD_SOURCE = $(BLE_ROOT)/build.gradle | ||
|
||
GIT_SHA ?= $(shell git rev-parse HEAD) | ||
GIT_TAG ?= $(shell git describe --tags --always) | ||
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) | ||
GIT_COMMIT_DATE ?= $(shell git show -s --format=%ct $(GIT_SHA)) | ||
EXT_LDFLAGS ?= -ldflags="-X \"berty.tech/core.GitTag=$(GIT_TAG)\" -X \"berty.tech/core.GitBranch=$(GIT_BRANCH)\" -X \"berty.tech/core.GitSha=$(GIT_SHA)\" -X \"berty.tech/core.BuildMode=$(BUILD_MODE)\" -X \"berty.tech/core.commitDate=$(GIT_COMMIT_DATE)\"" | ||
|
||
GOPATH ?= $(HOME)/go | ||
|
||
CGO_CPPFLAGS ?= -Wno-nullability-completeness \ | ||
-Wno-error=unused-command-line-argument \ | ||
-I$(PWD)/../common/openssl/built/include | ||
|
||
CGO_OS_LDFLAGS ?= -L/usr/local/opt/openssl/lib | ||
CGO_OS_CPPFLAGS ?= -I/usr/local/opt/openssl/include | ||
|
||
LIBS_PATH := $(abspath $(PWD)/../common/openssl/built) | ||
|
||
IOS_BUILD_PATH := $(abspath $(PWD)/../../../client/packages/react-native-core/ios) | ||
IOS_LDFLAGS := -L$(LIBS_PATH)/ios | ||
|
||
ANDROID_NDK_HOME := /usr/local/share/android-ndk/ | ||
ANDROID_ARCHS := aarch64 arm x86_64 x86 | ||
ANDROID_LIBS_PATHS := $(addprefix $(LIBS_PATH)/android/, $(ANDROID_ARCHS)) | ||
ANDROID_LDFLAGS := $(addprefix -L, $(ANDROID_LIBS_PATHS)) | ||
|
||
GOMOBILES_OPT ?= | ||
|
||
GOTEST_TIMEOUT ?= 30s | ||
|
||
TEST_FILE_CMD = stat -t 2>/dev/null | ||
|
||
SED_CMD := | ||
UNAME_S := $(shell uname -s) | ||
ifeq ($(UNAME_S),Darwin) | ||
SED_CMD += sed -E -i '' | ||
else | ||
SED_CMD += sed -r -i | ||
endif | ||
|
||
.PHONY: help | ||
help: | ||
@echo "Gomobile commands:" | ||
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | grep -v / | sed 's/^/ $(HELP_MSG_PREFIX)make /' | ||
|
||
.PHONY: deps-osx | ||
deps-osx: | ||
brew cask install android-sdk android-ndk | ||
|
||
.PHONY: deps | ||
deps: ios-deploy gomobile gobind | ||
cd $(PWD)/../.. && make deps | ||
[ ! -z "$$CIRCLE_JOB" ] || (cd $(abspath $(PWD)/../..) && make generate) | ||
|
||
.PHONY: gomobile | ||
gomobile: $(GOPATH)/src/golang.org/x/mobile/cmd/gomobile | ||
|
||
.PHONY: gobind | ||
gobind: $(GOPATH)/src/golang.org/x/mobile/cmd/gobind | ||
|
||
$(GOPATH)/src/golang.org/x/mobile/cmd/gomobile $(GOPATH)/src/golang.org/x/mobile/cmd/gobind: | ||
cd $(GOPATH)/src/golang.org/x/mobile && git checkout -- . || true | ||
GO111MODULE=off go get -u $(GOPATH)/src/golang.org/x/mobile/cmd/gomobile | ||
GO111MODULE=off go get -u $(GOPATH)/src/golang.org/x/mobile/cmd/gobind | ||
patch -N $(GOPATH)/src/golang.org/x/mobile/cmd/gomobile/env.go $(BUILD_PATCH_PATH)/gomobile-env-flag.diff || (rm -rf $(GOPATH)/src/golang.org/x/mobile && false) | ||
cd $(GOPATH)/src/golang.org/x/mobile && GO111MODULE=off go install -v ./cmd/... | ||
gomobile init -v | ||
|
||
ifeq ($(UNAME_S),Darwin) | ||
IOS_DEPLOY = $(shell which ios-deploy || echo '/usr/local/bin/ios-deploy') | ||
endif | ||
.PHONY: ios-deploy | ||
ios-deploy: $(IOS_DEPLOY) | ||
|
||
$(IOS_DEPLOY): | ||
npm install -g ios-deploy | ||
|
||
.PHONY: test | ||
test: | ||
cd $(CORE_MOBILE) && CGO_LDFLAGS="$(CGO_OS_LDFLAGS)" CGO_CPPFLAGS="$(CGO_OS_CPPFLAGS)" go test -test.timeout $(GOTEST_TIMEOUT) -v ./... | ||
|
||
.PHONY: deps.android | ||
deps.android: deps | ||
$(MAKE) -C $(CLIENT_PATH) $(abspath $(CLIENT_PATH)/node_modules) | ||
|
||
.PHONY: build.core | ||
build.core: deps.android $(ANDROID_SOURCE_CORE) | ||
|
||
.PHONY: build.android | ||
build.android: deps.android | ||
$(MAKE) build.ble | ||
$(MAKE) build.core | ||
$(MAKE) build.ble | ||
rm -f $(ANDROID_CORE) | ||
ln -s $(ANDROID_SOURCE_CORE) $(ANDROID_CORE) | ||
|
||
.PHONY: build.ble | ||
build.ble: $(BLE_JAR) | ||
|
||
$(BLE_JAR): deps.android | ||
$(SED_CMD) "s/.*implementation project\(':core'\)/\/\/implementation project\(':core'\)/g" $(BLE_BUILD_SOURCE) | ||
$(SED_CMD) 's/new GoBridgeImplem\(\)/null/g' $(BLE_MANAGER_SOURCE) | ||
$(SED_CMD) 's/(.*GoBridgeImplem.*)/\/\/\1/g' $(BLE_MANAGER_SOURCE) | ||
cd $(ANDROID_CORE_SOURCES_PATH) && ./gradlew ble:createJar | ||
|
||
$(ANDROID_SOURCE_CORE): $(CORE_SOURCES) | deps.android | ||
$(SED_CMD) "s/.*\/\/implementation project\(':core'\)/implementation project\(':core'\)/g" $(BLE_BUILD_SOURCE) | ||
$(SED_CMD) 's/(goBridge = )(null)/\1new GoBridgeImplem\(\)/g' $(BLE_MANAGER_SOURCE) | ||
$(SED_CMD) 's/[\/\/]*(.*GoBridgeImplem.*)/\1/g' $(BLE_MANAGER_SOURCE) | ||
mkdir -p $(ANDROID_OUT_PATH) | ||
- mv $(PWD)/core/os_android.go_ $(PWD)/core/os_android.go | ||
- GO111MODULE=off GOOS=android GOPATH=$(GOPATH) CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_LDFLAGS="$(ANDROID_LDFLAGS)" \ | ||
gomobile bind -v $(EXT_LDFLAGS) $(GOMOBILES_OPT) -classpath=$(BLE_ROOT)/libs/jars/ble.jar -o $@ berty.tech/core/platform/mobile/core | ||
mv $(PWD)/core/os_android.go $(PWD)/core/os_android.go_ | ||
|
||
.PHONY: deps.ios | ||
deps.ios: deps | ||
|
||
.PHONY: build.ios | ||
build.ios: deps.ios $(IOS_BUILD_PATH)/core.framework | ||
|
||
$(IOS_BUILD_PATH)/core.framework: $(CORE_SOURCES) | deps | ||
mkdir -p $(IOS_BUILD_PATH) | ||
GO111MODULE=off CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_LDFLAGS="$(IOS_LDFLAGS)" gomobile bind -v $(EXT_LDFLAGS) $(GOMOBILES_OPT) -target=ios -o $(IOS_BUILD_PATH)/core.framework berty.tech/core/platform/mobile/core | ||
|
||
.PHONY: build | ||
build: build.android build.ios | ||
|
||
.PHONY: clean.core | ||
clean.core: | ||
rm -rf $(ANDROID_CORE) | ||
|
||
.PHONY: clean.ble | ||
clean.ble: | ||
rm -rf $(BLE_JAR) | ||
|
||
.PHONY: clean.android | ||
clean.android: clean.core clean.ble | ||
|
||
.PHONY: clean.ios | ||
clean.ios: | ||
rm -rf $(IOS_BUILD_PATH)/core.framework | ||
|
||
.PHONY: clean | ||
clean: clean.android clean.ios | ||
|
||
.PHONY: re.android | ||
re.android: build.ble clean.core build.core | ||
|
||
.PHONY: re.ios | ||
re.ios: clean.ios build.ios | ||
|
||
.PHONY: re | ||
re: clean build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
connection.project.dir= | ||
eclipse.preferences.version=1 |
Oops, something went wrong.