Skip to content

Commit

Permalink
Change to Stack setup
Browse files Browse the repository at this point in the history
  • Loading branch information
owickstrom committed Apr 29, 2016
1 parent 390be30 commit f252aa6
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 78 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.stack-work
dist
build
.history
.cabal-sandbox
cabal.sandbox.config
Expand Down
92 changes: 23 additions & 69 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
TMP = .tmp
VERSION ?= $(shell grep '^version:' oden.cabal | sed -Ee 's/^version\:(.+)$$/\1/' | xargs)
OS=$(shell tools/get_os.sh)

STACK_DIST_DIR=$(shell stack path --dist-dir)
STACK_ODEN_EXE=$(STACK_DIST_DIR)/build/oden-exe/oden-exe

DIST_NAME=oden-$(VERSION)-$(OS)
DIST_ARCHIVE=dist/$(DIST_NAME).tar.gz
DIST_ARCHIVE=build/$(DIST_NAME).tar.gz

TEST_FLAG=
ifneq ($(strip $(TEST_PATTERN)),)
Expand All @@ -13,28 +16,29 @@ IMPORTER_SRC=$(shell find go/src/oden -name '*.go')

NODEMON=node_modules/.bin/nodemon

.PHONY: build
build: dist/go-lib/importer.a
cabal build oden
dist: $(DIST_ARCHIVE)

dist/go-lib/importer.a: $(IMPORTER_SRC)
mkdir -p dist/go-lib
(cd dist/go-lib \
&& GOPATH=$(PWD)/go go build -buildmode=c-archive oden/cmd/importer)
$(STACK_ODEN_EXE):
stack build

.PHONY: libs
libs: dist/go-lib/importer.a
build/oden: $(STACK_ODEN_EXE)
@mkdir -p build/oden/bin
cp README.md build/oden/README.txt
cp LICENSE.md build/oden/LICENSE.txt
cp CREDITS.md build/oden/CREDITS.txt
cp CHANGELOG.md build/oden/CHANGELOG.txt
cp $(STACK_ODEN_EXE) build/oden/bin/oden-exe
cp distribution/oden.sh build/oden/bin/oden
cp -r build/lib build/oden/lib

.PHONY: clean
clean:
rm -rf dist

$(TMP):
mkdir -p $(TMP)
rm -rf build

.PHONY: test
test:
cabal build spec && dist/build/spec/spec $(TEST_FLAG)
LD_LIBRARY_PATH=build/lib:$(LD_LIBRARY_PATH) \
stack build --test --test-arguments '$(TEST_FLAG)'

.PHONY: regression-test
regression-test:
Expand All @@ -54,58 +58,8 @@ watch-test: $(NODEMON)
$(NODEMON):
npm install nodemon

init-dev:
cabal sandbox init
cabal install --enable-tests --only-dependencies
cabal configure --enable-tests

dist/build-oden-cli/bin/oden: build
rm -rf dist/build-oden-cli
cp -r dist/build dist/build-oden-cli
mkdir -p dist/build-oden-cli/bin
ghc \
--make \
-package-db .cabal-sandbox/*-packages.conf.d \
-odir dist/build-oden-cli \
-hidir dist/build-oden-cli \
-ioden \
-isrc \
-fPIC \
-static \
-threaded \
-o dist/build-oden-cli/bin/oden \
dist/build-oden-cli/libHSoden*.a \
dist/build-oden-cli/autogen/Paths_oden.hs \
dist/go-lib/importer.a \
$(shell find cli -name '*.hs')

.PHONY: cli
cli: dist/build-oden-cli/bin/oden

dist/oden: dist/build-oden-cli/bin/oden
@mkdir -p dist/oden/bin
cp README.md dist/oden/README.txt
cp LICENSE.md dist/oden/LICENSE.txt
cp CREDITS.md dist/oden/CREDITS.txt
cp CHANGELOG.md dist/oden/CHANGELOG.txt
cp dist/build-oden-cli/bin/oden dist/oden/bin/oden

$(DIST_ARCHIVE): dist/oden
(cd dist && tar -czf $(DIST_NAME).tar.gz oden)

dist: $(DIST_ARCHIVE)

docker-dist:
@(docker kill oden-builder &> /dev/null ; true)
@(docker rm oden-builder &> /dev/null ; true)
docker build \
-t oden-build:$(VERSION) \
.
docker run \
--env VERSION=$(VERSION) \
--name oden-builder \
oden-build:$(VERSION)
docker cp oden-builder:/src/dist/oden-$(VERSION)-linux.tar.gz dist
$(DIST_ARCHIVE): build/oden
(cd build && tar -czf $(DIST_NAME).tar.gz oden)

release: $(DIST_ARCHIVE)
@echo "\n\nDon't forget to set env variable GITHUB_TOKEN first!\n\n"
Expand All @@ -117,7 +71,7 @@ release: $(DIST_ARCHIVE)
--tag $(VERSION) \
--name $(VERSION) \
--pre-release
find dist -name 'oden-$(VERSION)-*.tar.gz' -execdir \
find build -name 'oden-$(VERSION)-*.tar.gz' -execdir \
github-release upload \
--user oden-lang \
--repo oden \
Expand Down
79 changes: 79 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import Distribution.PackageDescription
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.UserHooks
import Distribution.Simple.Setup

import System.Info
import System.Directory
import System.Environment
import System.Process
import System.FilePath

import Data.Maybe

main = defaultMainWithHooks simpleUserHooks { confHook = odenConfHook
, postConf = odenPostConf }

addLibDirsToBuildInfo :: BuildInfo -> IO BuildInfo
addLibDirsToBuildInfo buildInfo = do
wd <- getCurrentDirectory
let libDir = wd </> "build" </> "lib"
return $ buildInfo {
extraLibDirs = libDir : extraLibDirs buildInfo
}

addLibDirsToOdenExe :: [Executable] -> IO [Executable]
addLibDirsToOdenExe exes = mapM addIfOden exes
where
addIfOden exe
| exeName exe == "oden-exe" = do
withLibDirs <- addLibDirsToBuildInfo (buildInfo exe)
return $ exe { buildInfo = withLibDirs }
| otherwise = return exe

addLibDirsToTests :: [TestSuite] -> IO [TestSuite]
addLibDirsToTests suites = mapM addLibDirs suites
where
addLibDirs suite = do
withLibDirs <- addLibDirsToBuildInfo (testBuildInfo suite)
return $ suite { testBuildInfo = withLibDirs }

odenConfHook :: (GenericPackageDescription, HookedBuildInfo)
-> ConfigFlags
-> IO LocalBuildInfo
odenConfHook (description, buildInfo) flags = do
localBuildInfo <- confHook simpleUserHooks (description, buildInfo) flags
let packageDescription = localPkgDescr localBuildInfo
lib = fromJust $ library packageDescription

libWithLibDirs <- addLibDirsToBuildInfo (libBuildInfo lib)
executablesWithLibDirs <- addLibDirsToOdenExe (executables packageDescription)
testSuitesWithLibDirs <- addLibDirsToTests (testSuites packageDescription)

return $ localBuildInfo {
localPkgDescr = packageDescription {
library = Just $ lib {
libBuildInfo = libWithLibDirs
},
executables = executablesWithLibDirs,
testSuites = testSuitesWithLibDirs
}
}

ext :: String
ext = case os of
"darwin" -> ".dylib"
"windows" -> ".dll"
_ -> ".so"

odenPostConf :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
odenPostConf _ _ _ _ = do
wd <- getCurrentDirectory
setEnv "GOPATH" (wd </> "go")

let dynamicPath = wd </> "build" </> "lib" </> ("libimporter" ++ ext)
buildDynamic = shell ("go build -buildmode=c-shared -o " ++ dynamicPath ++ " oden/cmd/importer")

putStrLn $ "Compiling Go dynamic library to " ++ dynamicPath
readCreateProcess buildDynamic "" >>= putStr
8 changes: 8 additions & 0 deletions distribution/oden.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

here="$(dirname "$(readlink -f "$0")")"

LD_LIBRARY_PATH="$here"/../lib:"$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH
exec "$0"-exe "$@"

22 changes: 15 additions & 7 deletions oden.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ license: MIT
license-file: LICENSE.md
author: Oskar Wickström
maintainer: [email protected]
build-type: Simple
build-type: Custom
extra-source-files:
README.md,
go/src/oden/importer/main.go,
go/src/oden/cmd/importer/importer.go,
go/src/oden/importer/objects.go,
go/src/oden/importer/types.go
cabal-version: >=1.10

Expand Down Expand Up @@ -81,12 +82,16 @@ library
Oden.Type.Signature
default-language: Haskell2010
hs-source-dirs: src
ghc-options: -fPIC -Wall dist/go-lib/importer.a -fno-warn-orphans
extra-libraries: importer
ghc-options: -Wall -fno-warn-orphans

executable cli
exposed-modules:
executable oden-exe
other-modules:
Paths_oden,
Oden.CLI,
Oden.CLI.Build,
Oden.CLI.Lint,
Oden.CLI.PrintPackage,
Oden.CLI.Run
build-depends:
base == 4.*,
Expand All @@ -104,7 +109,8 @@ executable cli
default-language: Haskell2010
main-is: Main.hs
hs-source-dirs: cli
ghc-options: -fPIC -Wall dist/go-lib/importer.a -fno-warn-orphans
extra-libraries: importer
ghc-options: -Wall -fno-warn-orphans

test-suite spec
type: exitcode-stdio-1.0
Expand All @@ -124,4 +130,6 @@ test-suite spec
containers >= 0.4 && <0.6,
wl-pprint >= 1.2,
oden
ghc-options: -Wall -fno-warn-orphans -fno-warn-missing-signatures
extra-libraries: importer
ghc-options:
-Wall -fno-warn-orphans -fno-warn-missing-signatures
6 changes: 4 additions & 2 deletions regression-test/run-regression-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

ODEN=$DIR/../dist/build/cli/cli
export LD_LIBRARY_PATH="$DIR/../build/lib:$LD_LIBRARY_PATH"

ODEN=$DIR/../$(stack path --dist-dir)/build/oden-exe/oden-exe
if ! hash $ODEN ; then
ODEN=$DIR/../dist/oden/bin/oden
ODEN=$DIR/../build/oden/bin
fi

cd $DIR
Expand Down
34 changes: 34 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md

# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: lts-4.2

# Local packages, usually specified by relative directory name
packages:
- '.'

# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
extra-deps: []

# Override default flag values for local packages and extra-deps
flags: {}

# Extra package databases containing global packages
extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true

# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: >= 0.1.10.0

# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64

# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
ghc-options:
"spec": -Wall -L build/lib

0 comments on commit f252aa6

Please sign in to comment.