Skip to content

Commit

Permalink
Support GHC-8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
basvandijk committed Mar 31, 2018
1 parent b0df4a9 commit 2ef919f
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 72 deletions.
117 changes: 77 additions & 40 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# This Travis job script has been generated by a script via
#
# make_travis_yml_2.hs './usb.cabal'
# runghc make_travis_yml_2.hs './usb.cabal'
#
# For more information, see https://github.com/hvr/multi-ghc-travis
#
language: c
sudo: false
dist: trusty # Contains libusb-1.0.17

git:
submodules: false # whether to recursively clone submodules
Expand All @@ -25,82 +24,120 @@ before_cache:
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx

- rm -rfv $HOME/.cabal/packages/head.hackage

matrix:
include:
- compiler: "ghc-7.4.1"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-7.4.1], sources: [hvr-ghc]}}
- compiler: "ghc-7.4.2"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-7.4.2], sources: [hvr-ghc]}}
- compiler: "ghc-7.6.1"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-7.6.1], sources: [hvr-ghc]}}
- compiler: "ghc-7.6.2"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-7.6.2], sources: [hvr-ghc]}}
- compiler: "ghc-7.6.3"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-7.6.3], sources: [hvr-ghc]}}
- compiler: "ghc-7.8.1"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-7.8.1], sources: [hvr-ghc]}}
- compiler: "ghc-7.8.2"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-7.8.2], sources: [hvr-ghc]}}
- compiler: "ghc-7.8.3"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-7.8.3], sources: [hvr-ghc]}}
- compiler: "ghc-7.8.4"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-7.8.4], sources: [hvr-ghc]}}
- compiler: "ghc-7.10.1"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-7.10.1], sources: [hvr-ghc]}}
- compiler: "ghc-7.10.2"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-7.10.2], sources: [hvr-ghc]}}
- compiler: "ghc-7.10.3"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-7.10.3], sources: [hvr-ghc]}}
- compiler: "ghc-8.0.1"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-8.0.1], sources: [hvr-ghc]}}
- compiler: "ghc-8.0.2"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}
- compiler: "ghc-head"
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-head], sources: [hvr-ghc]}}

allow_failures:
- compiler: "ghc-head"
- compiler: "ghc-8.2.1"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-8.2.1], sources: [hvr-ghc]}}
- compiler: "ghc-8.2.2"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-8.2.2], sources: [hvr-ghc]}}
- compiler: "ghc-8.4.1"
# env: TEST=--disable-tests BENCH=--disable-benchmarks
addons: {apt: {packages: [libusb-1.0-0-dev,ghc-ppa-tools,cabal-install-head,ghc-8.4.1], sources: [hvr-ghc]}}

before_install:
- HC=${CC}
- unset CC
- PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$PATH
- PKGNAME='usb'
- HC=${CC}
- HCPKG=${HC/ghc/ghc-pkg}
- unset CC
- ROOTDIR=$(pwd)
- mkdir -p $HOME/.local/bin
- "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH"
- HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') ))
- echo $HCNUMVER

install:
- cabal --version
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
- BENCH=${BENCH---enable-benchmarks}
- TEST=${TEST---enable-tests}
- travis_retry cabal update -v
- sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
- rm -fv cabal.project.local
- "echo 'packages: .' > cabal.project"
- rm -f cabal.project.freeze
- cabal new-build -w ${HC} ${TEST} ${BENCH} --dep -j2 all
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --dep -j2 all
- cabal --version
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
- BENCH=${BENCH---enable-benchmarks}
- TEST=${TEST---enable-tests}
- HADDOCK=${HADDOCK-true}
- INSTALLED=${INSTALLED-true}
- GHCHEAD=${GHCHEAD-false}
- travis_retry cabal update -v
- "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config"
- rm -fv cabal.project cabal.project.local
- grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'
- "printf 'packages: \".\"\\n' > cabal.project"
- cat cabal.project
- if [ -f "./configure.ac" ]; then
(cd "." && autoreconf -i);
fi
- rm -f cabal.project.freeze
- cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 all
- rm -rf .ghc.environment.* "."/dist
- DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)

# Here starts the actual work to be performed for the package under test;
# any command which exits with a non-zero exit code causes the build to fail.
script:
- if [ -f configure.ac ]; then autoreconf -i; fi
- rm -rf .ghc.environment.* dist/
- cabal sdist # test that a source-distribution can be generated
- cd dist/
- SRCTAR=(${PKGNAME}-*.tar.gz)
- SRC_BASENAME="${SRCTAR/%.tar.gz}"
- tar -xvf "./$SRC_BASENAME.tar.gz"
- cd "$SRC_BASENAME/"
## from here on, CWD is inside the extracted source-tarball
- rm -fv cabal.project.local
- "echo 'packages: .' > cabal.project"
# this builds all libraries and executables (without tests/benchmarks)
- rm -f cabal.project.freeze
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks all
# this builds all libraries and executables (including tests/benchmarks)
# - rm -rf ./dist-newstyle
# test that source-distributions can be generated
- (cd "." && cabal sdist)
- mv "."/dist/usb-*.tar.gz ${DISTDIR}/
- cd ${DISTDIR} || false
- find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;
- "printf 'packages: usb-*/*.cabal\\n' > cabal.project"
- cat cabal.project
# this builds all libraries and executables (without tests/benchmarks)
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks all

# Build with installed constraints for packages in global-db
- if $INSTALLED; then echo cabal new-build -w ${HC} --disable-tests --disable-benchmarks $(${HCPKG} list --global --simple-output --names-only | sed 's/\([a-zA-Z0-9-]\{1,\}\) */--constraint="\1 installed" /g') all | sh; else echo "Not building with installed constraints"; fi

# build & run tests, build benchmarks
- cabal new-build -w ${HC} ${TEST} ${BENCH} all

# cabal check
- (cd usb-* && cabal check)

# build & run tests
- cabal new-build -w ${HC} ${TEST} ${BENCH} all
# haddock
- rm -rf ./dist-newstyle
- if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi

# REGENDATA ["./usb.cabal"]
# EOF
5 changes: 5 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.3.0.6 (2018-04-01)

* Support GHC-8.4


1.3.0.5 (2017-07-07)

* Fix segfault in registerHotplugCallback caused by a double-free.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2009–2017 Bas van Dijk
Copyright (c) 2009–2018 Bas van Dijk

All rights reserved.

Expand Down
17 changes: 15 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
let pkgs = import <nixpkgs> {};
in pkgs.haskellPackages.callPackage ./usb.nix {}
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default" }:

let

inherit (nixpkgs) pkgs;

haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};

drv = haskellPackages.callPackage (import ./usb.nix) {};

in

if pkgs.lib.inNixShell then drv.env else drv
15 changes: 0 additions & 15 deletions shell.nix

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 23 additions & 2 deletions System/USB/Base.hs → src/System/USB/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ import Data.Function ( ($), (.), on )
import Data.Data ( Data )
import Data.Typeable ( Typeable )
import Data.Maybe ( Maybe(Nothing, Just), maybe, fromMaybe )
import Data.Monoid ( Monoid, mempty, mappend )
import Data.Monoid ( Monoid, mempty
#if !MIN_VERSION_base(4,11,0)
, mappend
#endif
)
#if MIN_VERSION_base(4,9,0)
import Data.Semigroup ( Semigroup, (<>) )
#endif
import Data.List
import Data.Int ( Int )
import Data.Word ( Word8, Word16 )
Expand Down Expand Up @@ -714,11 +721,18 @@ getDevices ctx =
-- 'registerHotplugCallback'.
newtype HotplugEvent = HotplugEvent {unHotplugEvent :: C'libusb_hotplug_event}

#if MIN_VERSION_base(4,9,0)
instance Semigroup HotplugEvent where
ev1 <> ev2 = HotplugEvent $ unHotplugEvent ev1 .|. unHotplugEvent ev2
#endif

-- | Use 'mempty' to specify the empty set of events. Use @'mappend' e1 e2@ to
-- join the events in @e1@ and @e2@.
instance Monoid HotplugEvent where
mempty = HotplugEvent 0
#if !MIN_VERSION_base(4,11,0)
ev1 `mappend` ev2 = HotplugEvent $ unHotplugEvent ev1 .|. unHotplugEvent ev2
#endif

-- | A device has been plugged in and is ready to use.
deviceArrived :: HotplugEvent
Expand Down Expand Up @@ -748,11 +762,18 @@ isEvent c'ev = \ev -> unHotplugEvent ev .&. c'ev == c'ev
-- | Set of configuration flags for 'registerHotplugCallback'.
newtype HotplugFlag = HotplugFlag {unHotplugFlag :: C'libusb_hotplug_flag}

#if MIN_VERSION_base(4,9,0)
instance Semigroup HotplugFlag where
flg1 <> flg2 = HotplugFlag $ unHotplugFlag flg1 .|. unHotplugFlag flg2
#endif

-- | Use 'mempty' to specify the empty set of flags. Use @'mappend' e1 e2@ to
-- join the flags in @e1@ and @e2@.
instance Monoid HotplugFlag where
mempty = HotplugFlag 0
ev1 `mappend` ev2 = HotplugFlag $ unHotplugFlag ev1 .|. unHotplugFlag ev2
#if !MIN_VERSION_base(4,11,0)
flg1 `mappend` flg2 = HotplugFlag $ unHotplugFlag flg1 .|. unHotplugFlag flg2
#endif

-- | Fire events for all matching currently attached devices.
enumerate :: HotplugFlag
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 13 additions & 10 deletions usb.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: usb
version: 1.3.0.5
version: 1.3.0.6
cabal-version: >=1.6
build-type: Simple
license: BSD3
Expand Down Expand Up @@ -55,9 +55,10 @@ tested-with: GHC == 7.4.1, GHC == 7.4.2,
GHC == 7.8.1, GHC == 7.8.2, GHC == 7.8.3, GHC == 7.8.4
GHC == 7.10.1, GHC == 7.10.2, GHC == 7.10.3
GHC == 8.0.1, GHC == 8.0.2
GHC == 8.3
GHC == 8.2.1, GHC == 8.2.2
GHC == 8.4.1

extra-source-files: README.markdown, Changelog, default.nix, shell.nix
extra-source-files: README.markdown, Changelog

source-repository head
Type: git
Expand All @@ -66,11 +67,13 @@ source-repository head
Library
GHC-Options: -Wall

build-depends: base >= 4 && < 4.11
, bindings-libusb >= 1.4.5 && < 1.5
, bytestring >= 0.9 && < 0.11
, text >= 0.5 && < 1.3
, vector >= 0.5 && < 0.13
build-depends: base >= 4 && < 5
, bindings-libusb >= 1.4.5
, bytestring >= 0.9
, text >= 0.5
, vector >= 0.5

hs-source-dirs: src

exposed-modules: System.USB
System.USB.Initialization
Expand All @@ -87,8 +90,8 @@ Library
cpp-options: -DHAS_EVENT_MANAGER
exposed-modules: System.USB.IO.Transfers
other-modules: Poll, Event, SystemEventManager
build-depends: containers >= 0.1 && < 0.6
build-depends: containers >= 0.1

if impl(ghc >= 7.2.1)
cpp-options: -DGENERICS
build-depends: ghc-prim >= 0.2 && < 0.6
build-depends: ghc-prim >= 0.2
11 changes: 9 additions & 2 deletions usb.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{ mkDerivation, base, bindings-libusb, bytestring, containers
{ mkDerivation, lib, base, bindings-libusb, bytestring, containers
, ghc-prim, stdenv, text, vector
}:
mkDerivation {
pname = "usb";
version = "HEAD";
src = ./.;
src = lib.sourceByRegex ./. [
"^usb.cabal$"
"^LICENSE$"
"^README.markdown$"
"^Changelog$"
"^src$"
"^src/.*"
];
libraryHaskellDepends = [
base bindings-libusb bytestring containers ghc-prim text vector
];
Expand Down

0 comments on commit 2ef919f

Please sign in to comment.