Skip to content

Commit

Permalink
Merge branch 'valencia' into issue-2255
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Feb 22, 2015
2 parents 811360f + 8552fc4 commit c9fb4bd
Show file tree
Hide file tree
Showing 22 changed files with 4,616 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ Lantern.app
lantern.dmg
src/github.com/getlantern/flashlight/ui/resources.go
src/github.com/getlantern/flashlight/lantern.syso
dmgbackground.png
dmgbackground_versioned.svg
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ lantern).

Flashlight requires [Go 1.4.x](http://golang.org/dl/).

You will also need [npm](https://www.npmjs.com/) and gulp.

`npm install -g gulp`
You will also need [npm](https://www.npmjs.com/).

It is convenient to build flashlight for multiple platforms using
[gox](https://github.com/mitchellh/gox).
Expand Down Expand Up @@ -62,6 +60,9 @@ The script `tagandbuild.bash` tags and runs crosscompile.bash.

Note - ./crosscompile.bash omits debug symbols to keep the build smaller.

Note - tagandbuild.bash requires the BNS_CERT and BNS_CERT_PASS environment
variables to sign the windows executable. See Packaging for Windows below.

### Building on Linux

Cross-compilation targeting Linux is currently not supported, so Linux releases
Expand All @@ -87,12 +88,13 @@ Lantern on OS X is packaged as the `Lantern.app` app bundle, distributed inside
of a drag-and-drop dmg installer. The app bundle and dmg can be created using
`./package_osx.bash`.

This script requires the node module `appdmg`. Assuming you have homebrew
installed, you can get it with ...
This script requires that you have [nodejs](http://nodejs.org/) installed.

The script takes a single parameter, which is the version string to display in
the installer background, for example:

```bash
brew install node
npm install -g appdmg
./package_osx.bash 2.0.0_beta1
```

`./package_osx.bash` signs the Lantern.app using the BNS code signing
Expand Down
1 change: 1 addition & 0 deletions crosscompile.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# just the commit id.
VERSION="`git describe --abbrev=0 --tags --exact-match || git rev-parse --short HEAD`"
BUILD_DATE="`date -u +%Y%m%d%.%H%M%S`"
export VERSION_STRING="$VERSION ($BUILD_DATE)"
LOGGLY_TOKEN="469973d5-6eaf-445a-be71-cf27141316a1"
LDFLAGS="-w -X main.version $VERSION -X main.buildDate $BUILD_DATE -X main.logglyToken LOGGLY_TOKEN"
echo "Building flashlight version $VERSION ($BUILD_DATE)"
Expand Down
Binary file removed dmgbackground.png
Binary file not shown.
3,539 changes: 3,539 additions & 0 deletions dmgbackground.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion genassets.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ APP="$LANTERN_UI/app"
DIST="$LANTERN_UI/dist"

if [ ! -d $DIST ] || [ $APP -nt $DIST ]; then
# Install gulp (requires nodejs)
echo "Installing gulp tool if necessary (requires nodejs)"
which gulp || npm install -g gulp

echo "Updating dist folder"
cd $LANTERN_UI
npm install
Expand All @@ -25,5 +29,5 @@ echo " " >> $dest
tarfs -pkg ui src/github.com/getlantern/lantern-ui/dist >> $dest

echo "Now embedding lantern.ico to windows executable"
go get github.com/akavel/rsrc
go install github.com/akavel/rsrc
rsrc -ico lantern.ico -o src/github.com/getlantern/flashlight/lantern.syso
4 changes: 2 additions & 2 deletions lantern.dmg.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"background": "dmgbackground.png",
"icon-size": 100,
"contents": [
{ "x": 100, "y": 140, "type": "file", "path": "Lantern.app" },
{ "x": 380, "y": 140, "type": "link", "path": "/Applications" }
{ "x": 115, "y": 265, "type": "file", "path": "Lantern.app" },
{ "x": 440, "y": 265, "type": "link", "path": "/Applications" }
]
}
16 changes: 16 additions & 0 deletions package_osx.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ function die() {
exit 1
}

if [ $# -lt "1" ]
then
die "$0: Version required"
fi

echo "Installing svgexport tool if necessary (requires nodejs)"
which svgexport || npm install -g svgexport

echo "Installing appdmg tool if necessary (requires nodejs)"
which appdmg || npm install -g appdmg

binary="lantern_darwin_amd64"
dmg="Lantern.dmg"

Expand All @@ -27,4 +38,9 @@ if [ -e $dmg ]
then
rm -Rf lantern.dmg || die "Could not remove existing lantern.dmg"
fi

echo "Generating background image"
sed "s/__VERSION__/$1/g" dmgbackground.svg > dmgbackground_versioned.svg
svgexport dmgbackground_versioned.svg dmgbackground.png 600:400

appdmg lantern.dmg.json $dmg || "Could not package Lantern.app into dmg"
4 changes: 3 additions & 1 deletion package_win.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function die() {

binary="lantern_windows_386.exe"
out="lantern.exe"
archive="lantern.zip"

if [ ! -f $binary ]
then
Expand All @@ -22,6 +23,7 @@ then
fi

osslsigncode sign -pkcs12 "$BNS_CERT" -pass "$BNS_CERT_PASS" -in $binary -out $out || die "Could not sign windows executable"

zip -9 $archive $out
echo "Windows executable available at $out"
echo "Compressed executable archiveavailable at $archive"

4 changes: 4 additions & 0 deletions src/github.com/akavel/rsrc/.hgignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
glob:*.res
glob:*.exe

glob:tmp
2 changes: 2 additions & 0 deletions src/github.com/akavel/rsrc/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Mateusz Czapliński <czapkofan@gmail.com>
shnmng <shnmng@gmail.com>
21 changes: 21 additions & 0 deletions src/github.com/akavel/rsrc/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013-2014 The rsrc Authors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
46 changes: 46 additions & 0 deletions src/github.com/akavel/rsrc/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
rsrc - Tool for embedding binary resources in Go programs.

INSTALL: go get github.com/akavel/rsrc

PREBUILT BINARIES for Windows/Linux/MacOSX available via 3rd party site:
http://gobuild.io/download/github.com/akavel/rsrc

USAGE:

rsrc [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] -o FILE.syso
Generates a .syso file with specified resources embedded in .rsrc section.
The .syso file can be linked by Go linker when building Win32 executables.
Icon embedded this way will show up on application's .exe instead of empty icon.
Manifest file embedded this way will be recognized and detected by Windows.

rsrc -data FILE.dat -o FILE.syso > FILE.c
Generates a .syso file with specified opaque binary blob embedded,
together with related .c file making it possible to access from Go code.
Theoretically cross-platform, but reportedly cannot compile together with cgo.

The generated *.syso and *.c files should get automatically recognized
by 'go build' command and linked into an executable/library, as long as
there are any *.go files in the same directory.

NOTE: starting with Go 1.4+, *.c files reportedly won't be linkable any more,
see: https://codereview.appspot.com/149720043

OPTIONS:
-data="": path to raw data file to embed
-ico="": comma-separated list of paths to .ico files to embed
-manifest="": path to a Windows manifest file to embed
-o="rsrc.syso": name of output COFF (.res or .syso) file

Based on ideas presented by Minux.

In case anything does not work, it'd be nice if you could report (either via Github
issues, or via email to czapkofan@gmail.com), and please attach the input file(s)
which resulted in a problem, plus error message & symptoms, and/or any other details.

TODO MAYBE/LATER:
- fix or remove FIXMEs

LICENSE: MIT
Copyright 2013-2014 The rsrc Authors.

http://github.com/akavel/rsrc
13 changes: 13 additions & 0 deletions src/github.com/akavel/rsrc/binutil/plain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package binutil

import (
"reflect"
)

func Plain(kind reflect.Kind) bool {
switch kind {
case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128:
return true
}
return false
}
35 changes: 35 additions & 0 deletions src/github.com/akavel/rsrc/binutil/sizedfile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package binutil

import (
"io"
"os"
)

type SizedReader interface {
io.Reader
Size() int64
}

type SizedFile struct {
f *os.File
s *io.SectionReader // helper, for Size()
}

func (r *SizedFile) Read(p []byte) (n int, err error) { return r.s.Read(p) }
func (r *SizedFile) Size() int64 { return r.s.Size() }
func (r *SizedFile) Close() error { return r.f.Close() }

func SizedOpen(filename string) (*SizedFile, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
info, err := f.Stat()
if err != nil {
return nil, err
}
return &SizedFile{
f: f,
s: io.NewSectionReader(f, 0, info.Size()),
}, nil
}
63 changes: 63 additions & 0 deletions src/github.com/akavel/rsrc/binutil/walk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package binutil

import (
"errors"
"fmt"
"path"
"reflect"
)

var (
WALK_SKIP = errors.New("")
)

type Walker func(v reflect.Value, path string) error

func Walk(value interface{}, walker Walker) error {
err := walk(reflect.ValueOf(value), "/", walker)
if err == WALK_SKIP {
err = nil
}
return err
}

func stopping(err error) bool {
return err != nil && err != WALK_SKIP
}

func walk(v reflect.Value, spath string, walker Walker) error {
err := walker(v, spath)
if err != nil {
return err
}
v = reflect.Indirect(v)
switch v.Kind() {
case reflect.Slice, reflect.Array:
for i := 0; i < v.Len(); i++ {
err = walk(v.Index(i), spath+fmt.Sprintf("[%d]", i), walker)
if stopping(err) {
return err
}
}
case reflect.Interface:
err = walk(v.Elem(), spath, walker)
if stopping(err) {
return err
}
case reflect.Struct:
//t := v.Type()
for i := 0; i < v.NumField(); i++ {
//f := t.Field(i) //TODO: handle unexported fields
vv := v.Field(i)
err = walk(vv, path.Join(spath, v.Type().Field(i).Name), walker)
if stopping(err) {
return err
}
}
default:
// FIXME: handle other special cases too
// String
return nil
}
return nil
}
33 changes: 33 additions & 0 deletions src/github.com/akavel/rsrc/binutil/writer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package binutil

import (
"encoding/binary"
"io"
"reflect"
)

type Writer struct {
W io.Writer
Offset uint32 //FIXME: int64?
Err error
}

func (w *Writer) WriteLE(v interface{}) {
if w.Err != nil {
return
}
w.Err = binary.Write(w.W, binary.LittleEndian, v)
if w.Err != nil {
return
}
w.Offset += uint32(reflect.TypeOf(v).Size())
}

func (w *Writer) WriteFromSized(r SizedReader) {
if w.Err != nil {
return
}
var n int64
n, w.Err = io.CopyN(w.W, r, r.Size())
w.Offset += uint32(n)
}
Loading

0 comments on commit c9fb4bd

Please sign in to comment.