瀏覽代碼

Merge pull request #307 from Psiphon-Labs/master

Merge master
Adam Pritchard 9 年之前
父節點
當前提交
0f4b921628
共有 2 個文件被更改,包括 29 次插入7 次删除
  1. 24 4
      MobileLibrary/iOS/build-psiphon-framework.sh
  2. 5 3
      psiphon/server/log.go

+ 24 - 4
MobileLibrary/iOS/build-psiphon-framework.sh

@@ -162,10 +162,30 @@ if [[ $rc != 0 ]]; then
     cd ${GOPATH}/src/golang.org/x/mobile/cmd/gomobile
     git checkout master
     git checkout -b pinned ${GOMOBILE_PINNED_REV}
-    mv ./build.go ./build.go.orig
-    sed -e 's/"-tags="+strconv.Quote(strings.Join(ctx.BuildTags, ",")),/"-tags",strings.Join(ctx.BuildTags, " "),/g' ./build.go.orig > ./build.go
-    mv ./build.go ./build.go.orig
-    sed -e 's/"strconv"//g' ./build.go.orig > ./build.go
+
+    # Gomobile messes up the build tags by quoting them incorrectly. We'll hack a fix for it.
+    # First do a grep to see if this code is still there (or has been fixed upstream).
+    grep -q 'strconv.Quote' ./build.go 
+    if [[ $? != 0 ]]; then
+      echo "Upstream gomobile code has changed, breaking hacks."
+      exit 1
+    fi
+    # Then do the hack-fix-replacement.
+    perl -i -pe 's/"-tags="\+strconv\.Quote\(strings.Join\(ctx\.BuildTags, ","\)\),/"-tags",strings.Join(ctx.BuildTags, " "),/g' ./build.go
+    # We also need to remove the now-unused strconv import.
+    perl -i -pe 's/"strconv"//g' ./build.go
+    
+    # Gomobile's iOS code puts an *additional* build tags flag at the end of the command line. This
+    # overrides any existing build tags and messes up our builds. So we'll hack a fix for that, too.
+    # First do a grep to see if this code is still there (or has been fixed upstream).
+    grep -q '"-tags=ios",' ./bind_iosapp.go 
+    if [[ $? != 0 ]]; then
+      echo "Upstream gomobile code has changed, breaking hacks."
+      exit 1
+    fi
+    # Then do the hack-fix-replacement.
+    perl -i -pe 's/(.+)"-tags=ios",(.+)/\tctx.BuildTags = append(ctx.BuildTags, "ios")\n\1\2/g' ./bind_iosapp.go
+    
     go install
     ${GOPATH}/bin/gomobile init -v
     if [[ $? != 0 ]]; then

+ 5 - 3
psiphon/server/log.go

@@ -28,6 +28,7 @@ import (
 	"os"
 
 	"github.com/Psiphon-Inc/logrus"
+	"github.com/Psiphon-Inc/rotate-safe-writer"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 )
 
@@ -150,14 +151,15 @@ func InitLogging(config *Config) error {
 		return common.ContextError(err)
 	}
 
-	logWriter := os.Stderr
+	var logWriter io.Writer
 
 	if config.LogFilename != "" {
-		logWriter, err = os.OpenFile(
-			config.LogFilename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
+		logWriter, err = rotate.NewRotatableFileWriter(config.LogFilename, 0666)
 		if err != nil {
 			return common.ContextError(err)
 		}
+	} else {
+		logWriter = os.Stderr
 	}
 
 	log = &ContextLogger{