chore(no-torrent)_: Implemented build OS conditional build instructions

This commit is contained in:
Samuel Hawksby-Robinson 2024-06-04 22:55:36 +01:00
parent 9ec8cdf3d8
commit 4bb4ca5cce
5 changed files with 33 additions and 2 deletions

View File

@ -1,3 +1,6 @@
//go:build windows || linux || darwin
// +build windows linux darwin
package communities
import (

View File

@ -1,3 +1,6 @@
//go:build android || ios
// +build android ios
package communities
import (

View File

@ -1,3 +1,6 @@
//go:build windows || linux || darwin
// +build windows linux darwin
package communities
import (
@ -96,7 +99,11 @@ type TorrentManager struct {
publisher Publisher
}
func NewTorrentManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, transport *transport.Transport, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) (*TorrentManager, error) {
// NewTorrentManager this function is only built and called when the "windows || linux || darwin" build OS criteria are met
// In this case this version of NewTorrentManager will return the full Desktop TorrentManager ensuring that the
// build command will import and build the torrent deps for the Desktop OSes.
// NOTE: It is intentional that this file contains the identical function name as in "manager_torrent_mobile.go"
func NewTorrentManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, transport *transport.Transport, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) (TorrentContract, error) {
stdoutLogger, err := zap.NewDevelopment()
if err != nil {
return nil, fmt.Errorf("failed to create archive logger %w", err)

View File

@ -1,10 +1,15 @@
//go:build android || ios
// +build android ios
package communities
import (
"crypto/ecdsa"
"time"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/encryption"
"github.com/status-im/status-go/protocol/transport"
"go.uber.org/zap"
@ -15,6 +20,16 @@ type TorrentManagerMobile struct {
logger *zap.Logger
}
// NewTorrentManager this function is only built and called when the "android || ios" build OS criteria are met
// In this case this version of NewTorrentManager will return the mobile "nil" TorrentManagerMobile ensuring that the
// build command will not import or build the torrent deps for the mobile OS.
// NOTE: It is intentional that this file contains the identical function name as in "manager_torrent.go"
func NewTorrentManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, transport *transport.Transport, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) (TorrentContract, error) {
return &TorrentManagerMobile{
logger: logger,
}, nil
}
func (tmm *TorrentManagerMobile) LogStdout(input string, fields ...zap.Field) {
tmm.logger.Debug(input, fields...)
}

View File

@ -113,7 +113,7 @@ type Messenger struct {
pushNotificationClient *pushnotificationclient.Client
pushNotificationServer *pushnotificationserver.Server
communitiesManager *communities.Manager
torrentManager *communities.TorrentManager
torrentManager communities.TorrentContract
communitiesKeyDistributor communities.KeyDistributor
accountsManager account.Manager
mentionsManager *MentionManager
@ -498,6 +498,9 @@ func NewMessenger(
return nil, err
}
// Depending on the OS go will choose whether to use the "communities/manager_torrent_mobile.go" or
// "communities/manager_torrent.go" version of this function based on the build instructions for those files.
// See those file for more details.
torrentManager, err := communities.NewTorrentManager(c.torrentConfig, logger, communitiesManager.GetPersistence(), transp, identity, encryptionProtocol, communitiesManager)
if err != nil {
return nil, err