libusb 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -2
  3. data/Gemfile +2 -0
  4. data/History.md +12 -0
  5. data/README.md +25 -14
  6. data/Rakefile +64 -109
  7. data/appveyor.yml +23 -0
  8. data/ext/extconf.rb +10 -12
  9. data/ext/libusb_recipe.rb +29 -0
  10. data/lib/libusb/call.rb +14 -11
  11. data/lib/libusb/compat.rb +9 -9
  12. data/lib/libusb/context.rb +16 -1
  13. data/lib/libusb/dependencies.rb +7 -0
  14. data/lib/libusb/dev_handle.rb +13 -3
  15. data/lib/libusb/eventmachine.rb +4 -4
  16. data/lib/libusb/transfer.rb +71 -10
  17. data/lib/libusb/version_gem.rb +1 -1
  18. data/libusb.gemspec +7 -5
  19. data/ports/archives/libusb-1.0.21.tar.bz2 +0 -0
  20. data/test/test_libusb_bulk_stream_transfer.rb +1 -1
  21. data/test/test_libusb_descriptors.rb +4 -4
  22. data/test/test_libusb_event_machine.rb +7 -7
  23. data/test/test_libusb_hotplug.rb +15 -3
  24. data/test/test_libusb_iso_transfer.rb +1 -1
  25. data/test/test_libusb_mass_storage.rb +19 -19
  26. data/test/test_libusb_mass_storage2.rb +1 -1
  27. data/test/test_libusb_structs.rb +13 -0
  28. data/test/test_libusb_threads.rb +2 -2
  29. data/wireshark-usb-sniffer.png +0 -0
  30. metadata +32 -156
  31. checksums.yaml.gz.sig +0 -0
  32. data.tar.gz.sig +0 -0
  33. data/ext/libusb-1.0.20/AUTHORS +0 -89
  34. data/ext/libusb-1.0.20/COPYING +0 -504
  35. data/ext/libusb-1.0.20/ChangeLog +0 -227
  36. data/ext/libusb-1.0.20/INSTALL +0 -234
  37. data/ext/libusb-1.0.20/Makefile.am +0 -28
  38. data/ext/libusb-1.0.20/Makefile.in +0 -897
  39. data/ext/libusb-1.0.20/NEWS +0 -2
  40. data/ext/libusb-1.0.20/PORTING +0 -94
  41. data/ext/libusb-1.0.20/README +0 -29
  42. data/ext/libusb-1.0.20/TODO +0 -2
  43. data/ext/libusb-1.0.20/Xcode/common.xcconfig +0 -49
  44. data/ext/libusb-1.0.20/Xcode/config.h +0 -28
  45. data/ext/libusb-1.0.20/Xcode/debug.xcconfig +0 -29
  46. data/ext/libusb-1.0.20/Xcode/libusb.xcconfig +0 -21
  47. data/ext/libusb-1.0.20/Xcode/libusb.xcodeproj/project.pbxproj +0 -865
  48. data/ext/libusb-1.0.20/Xcode/libusb_debug.xcconfig +0 -21
  49. data/ext/libusb-1.0.20/Xcode/libusb_release.xcconfig +0 -21
  50. data/ext/libusb-1.0.20/Xcode/release.xcconfig +0 -30
  51. data/ext/libusb-1.0.20/aclocal.m4 +0 -1193
  52. data/ext/libusb-1.0.20/android/README +0 -114
  53. data/ext/libusb-1.0.20/android/config.h +0 -81
  54. data/ext/libusb-1.0.20/android/jni/Android.mk +0 -23
  55. data/ext/libusb-1.0.20/android/jni/Application.mk +0 -24
  56. data/ext/libusb-1.0.20/android/jni/examples.mk +0 -134
  57. data/ext/libusb-1.0.20/android/jni/libusb.mk +0 -54
  58. data/ext/libusb-1.0.20/android/jni/tests.mk +0 -56
  59. data/ext/libusb-1.0.20/compile +0 -347
  60. data/ext/libusb-1.0.20/config.guess +0 -1421
  61. data/ext/libusb-1.0.20/config.h.in +0 -155
  62. data/ext/libusb-1.0.20/config.sub +0 -1807
  63. data/ext/libusb-1.0.20/configure +0 -15466
  64. data/ext/libusb-1.0.20/configure.ac +0 -326
  65. data/ext/libusb-1.0.20/depcomp +0 -791
  66. data/ext/libusb-1.0.20/doc/Makefile.am +0 -9
  67. data/ext/libusb-1.0.20/doc/Makefile.in +0 -456
  68. data/ext/libusb-1.0.20/doc/doxygen.cfg.in +0 -2334
  69. data/ext/libusb-1.0.20/examples/Makefile.am +0 -19
  70. data/ext/libusb-1.0.20/examples/Makefile.in +0 -713
  71. data/ext/libusb-1.0.20/examples/dpfp.c +0 -506
  72. data/ext/libusb-1.0.20/examples/dpfp_threaded.c +0 -549
  73. data/ext/libusb-1.0.20/examples/ezusb.c +0 -831
  74. data/ext/libusb-1.0.20/examples/ezusb.h +0 -120
  75. data/ext/libusb-1.0.20/examples/fxload.c +0 -308
  76. data/ext/libusb-1.0.20/examples/getopt/getopt.c +0 -1060
  77. data/ext/libusb-1.0.20/examples/getopt/getopt.h +0 -180
  78. data/ext/libusb-1.0.20/examples/getopt/getopt1.c +0 -188
  79. data/ext/libusb-1.0.20/examples/hotplugtest.c +0 -122
  80. data/ext/libusb-1.0.20/examples/listdevs.c +0 -71
  81. data/ext/libusb-1.0.20/examples/sam3u_benchmark.c +0 -193
  82. data/ext/libusb-1.0.20/examples/xusb.c +0 -1130
  83. data/ext/libusb-1.0.20/install-sh +0 -501
  84. data/ext/libusb-1.0.20/libusb-1.0.pc.in +0 -11
  85. data/ext/libusb-1.0.20/libusb/Makefile.am +0 -90
  86. data/ext/libusb-1.0.20/libusb/Makefile.in +0 -1053
  87. data/ext/libusb-1.0.20/libusb/core.c +0 -2452
  88. data/ext/libusb-1.0.20/libusb/descriptor.c +0 -1201
  89. data/ext/libusb-1.0.20/libusb/hotplug.c +0 -344
  90. data/ext/libusb-1.0.20/libusb/hotplug.h +0 -90
  91. data/ext/libusb-1.0.20/libusb/io.c +0 -2760
  92. data/ext/libusb-1.0.20/libusb/libusb-1.0.def +0 -168
  93. data/ext/libusb-1.0.20/libusb/libusb-1.0.rc +0 -61
  94. data/ext/libusb-1.0.20/libusb/libusb.h +0 -1999
  95. data/ext/libusb-1.0.20/libusb/libusbi.h +0 -1102
  96. data/ext/libusb-1.0.20/libusb/os/darwin_usb.c +0 -1969
  97. data/ext/libusb-1.0.20/libusb/os/darwin_usb.h +0 -158
  98. data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.am +0 -5
  99. data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.in +0 -810
  100. data/ext/libusb-1.0.20/libusb/os/haiku/aclocal.m4 +0 -1193
  101. data/ext/libusb-1.0.20/libusb/os/haiku/compile +0 -347
  102. data/ext/libusb-1.0.20/libusb/os/haiku/config.guess +0 -1421
  103. data/ext/libusb-1.0.20/libusb/os/haiku/config.sub +0 -1807
  104. data/ext/libusb-1.0.20/libusb/os/haiku/configure +0 -17579
  105. data/ext/libusb-1.0.20/libusb/os/haiku/configure.ac +0 -8
  106. data/ext/libusb-1.0.20/libusb/os/haiku/depcomp +0 -791
  107. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_pollfs.cpp +0 -378
  108. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb.h +0 -112
  109. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_backend.cpp +0 -550
  110. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.cpp +0 -255
  111. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.h +0 -180
  112. data/ext/libusb-1.0.20/libusb/os/haiku/install-sh +0 -501
  113. data/ext/libusb-1.0.20/libusb/os/haiku/ltmain.sh +0 -9655
  114. data/ext/libusb-1.0.20/libusb/os/haiku/m4/libtool.m4 +0 -7992
  115. data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltoptions.m4 +0 -384
  116. data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltsugar.m4 +0 -123
  117. data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltversion.m4 +0 -23
  118. data/ext/libusb-1.0.20/libusb/os/haiku/m4/lt~obsolete.m4 +0 -98
  119. data/ext/libusb-1.0.20/libusb/os/haiku/missing +0 -215
  120. data/ext/libusb-1.0.20/libusb/os/linux_netlink.c +0 -369
  121. data/ext/libusb-1.0.20/libusb/os/linux_udev.c +0 -306
  122. data/ext/libusb-1.0.20/libusb/os/linux_usbfs.c +0 -2692
  123. data/ext/libusb-1.0.20/libusb/os/linux_usbfs.h +0 -192
  124. data/ext/libusb-1.0.20/libusb/os/netbsd_usb.c +0 -674
  125. data/ext/libusb-1.0.20/libusb/os/openbsd_usb.c +0 -768
  126. data/ext/libusb-1.0.20/libusb/os/poll_posix.c +0 -53
  127. data/ext/libusb-1.0.20/libusb/os/poll_posix.h +0 -11
  128. data/ext/libusb-1.0.20/libusb/os/poll_windows.c +0 -728
  129. data/ext/libusb-1.0.20/libusb/os/poll_windows.h +0 -131
  130. data/ext/libusb-1.0.20/libusb/os/threads_posix.c +0 -82
  131. data/ext/libusb-1.0.20/libusb/os/threads_posix.h +0 -50
  132. data/ext/libusb-1.0.20/libusb/os/threads_windows.c +0 -214
  133. data/ext/libusb-1.0.20/libusb/os/threads_windows.h +0 -87
  134. data/ext/libusb-1.0.20/libusb/os/wince_usb.c +0 -869
  135. data/ext/libusb-1.0.20/libusb/os/wince_usb.h +0 -131
  136. data/ext/libusb-1.0.20/libusb/os/windows_common.h +0 -108
  137. data/ext/libusb-1.0.20/libusb/os/windows_usb.c +0 -4643
  138. data/ext/libusb-1.0.20/libusb/os/windows_usb.h +0 -973
  139. data/ext/libusb-1.0.20/libusb/strerror.c +0 -202
  140. data/ext/libusb-1.0.20/libusb/sync.c +0 -308
  141. data/ext/libusb-1.0.20/libusb/version.h +0 -18
  142. data/ext/libusb-1.0.20/libusb/version_nano.h +0 -1
  143. data/ext/libusb-1.0.20/ltmain.sh +0 -9655
  144. data/ext/libusb-1.0.20/m4/libtool.m4 +0 -7992
  145. data/ext/libusb-1.0.20/m4/ltoptions.m4 +0 -384
  146. data/ext/libusb-1.0.20/m4/ltsugar.m4 +0 -123
  147. data/ext/libusb-1.0.20/m4/ltversion.m4 +0 -23
  148. data/ext/libusb-1.0.20/m4/lt~obsolete.m4 +0 -98
  149. data/ext/libusb-1.0.20/missing +0 -215
  150. data/ext/libusb-1.0.20/tests/Makefile.am +0 -6
  151. data/ext/libusb-1.0.20/tests/Makefile.in +0 -596
  152. data/ext/libusb-1.0.20/tests/libusb_testlib.h +0 -107
  153. data/ext/libusb-1.0.20/tests/stress.c +0 -160
  154. data/ext/libusb-1.0.20/tests/testlib.c +0 -277
  155. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a70a49c54714bfac3447b6dea8c1d93e6921985c
4
- data.tar.gz: 54d453912040ca5b2c65e1b6aa129ce9b2b559c6
3
+ metadata.gz: 5e5f9e0c5d8b081434798fc6043348862276ed6c
4
+ data.tar.gz: d7d1324fd8f0718c83abd011cf2840b8259cfda5
5
5
  SHA512:
6
- metadata.gz: 3a0e00959b7d17f590d8ffc8708f6cf5da93d365efb922a668135047650a8278f77dcb8484066def32af7237dc90a02a24d1d1b9cb280cbb9d21f3d7399f2be4
7
- data.tar.gz: d4518a07a200486947377e19a69a4710bc83dae8d088d1ba4fe336f0d917876eb5c4d9560decef13b1aac9f8d6efc961faf58a57f9a1c6f51f0559f9b755e7ac
6
+ metadata.gz: bcff1f67a785ea9b9605c031153fec3c457bb5b33c283ac3c0228a1d78c20050922cf798fb2d3dc75c3676702f9e97c99a4a5fae0f036e0fbce1e138f5527155
7
+ data.tar.gz: d11ed544f2813e8c221b232e19b6ad393c94a31dc9d0e66995c0f5dc28cb4261cb61b391bfd8e1096fe47ae681066cf5bf668e71f717106717233b573bb0d40b
@@ -1,11 +1,17 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - "1.8.7"
5
4
  - "1.9.3"
6
5
  - "2.0.0"
7
6
  - "2.1"
8
7
  - "2.2"
9
- - jruby
8
+ - "2.3.1"
9
+ - "2.3.1-clang"
10
+ - jruby-1.7.26
11
+ - jruby-9.1.5.0
10
12
  - rbx
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: rbx
16
+ - rvm: "2.3.1-clang"
11
17
  script: bundle exec rake travis
data/Gemfile CHANGED
@@ -7,3 +7,5 @@ group :test do
7
7
  gem 'eventmachine'
8
8
  gem 'minitest'
9
9
  end
10
+
11
+ gem 'rake-compiler-dock', git: 'http://github.com/rake-compiler/rake-compiler-dock'
data/History.md CHANGED
@@ -1,3 +1,15 @@
1
+ 0.6.0 / 2016-12-09
2
+ ------------------
3
+ * Update bundled libusb version to 1.0.21.
4
+ * Set minimum Ruby version requirement to 1.9.3.
5
+ * Add binary gems for Linux in addition to Windows.
6
+ * Switch to mini_portile2 for (cross-) builing the libusb library.
7
+ * Add Context#interrupt_event_handler new in libusb-1.0.21
8
+ * Add support for persistent/zerocopy device memory for transfers.
9
+ It is new in libusb-1.0.21 and enabled by default for DevHandle#*_transfer methods.
10
+ * Raise a more meaningful exception in case of bulk stream transfers on too old libusb versions.
11
+ * Prefer the bundled libusb-dll over installed system library.
12
+
1
13
  0.5.1 / 2015-09-29
2
14
  ------------------
3
15
  * Add ability to force use of the system or builtin libusb-1.0 library.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  <!-- -*- coding: utf-8 -*- -->
2
2
 
3
3
  [![Build Status](https://travis-ci.org/larskanis/libusb.svg)](https://travis-ci.org/larskanis/libusb)
4
+ [![Build Status](https://ci.appveyor.com/api/projects/status/mdfnfdwu4mil42o3?svg=true)](https://ci.appveyor.com/project/larskanis/libusb)
4
5
 
5
6
  Access USB devices from Ruby
6
7
  ============================
@@ -23,15 +24,13 @@ Features
23
24
 
24
25
  Synopsis
25
26
  --------
26
- See [the documentation](http://rubydoc.info/gems/libusb/frames) for a full API description.
27
-
28
27
  ```ruby
29
28
  require "libusb"
30
29
 
31
30
  usb = LIBUSB::Context.new
32
- device = usb.devices(:idVendor => 0x04b4, :idProduct => 0x8613).first
31
+ device = usb.devices(idVendor: 0x04b4, idProduct: 0x8613).first
33
32
  device.open_interface(0) do |handle|
34
- handle.control_transfer(:bmRequestType => 0x40, :bRequest => 0xa0, :wValue => 0xe600, :wIndex => 0x0000, :dataOut => 1.chr)
33
+ handle.control_transfer(bmRequestType: 0x40, bRequest: 0xa0, wValue: 0xe600, wIndex: 0x0000, dataOut: 1.chr)
35
34
  end
36
35
  ```
37
36
  {LIBUSB::Context#devices} is used to get all or only particular devices.
@@ -55,18 +54,20 @@ Each {LIBUSB::Setting} specifies it's own set of communication endpoints.
55
54
  Each {LIBUSB::Endpoint} specifies the type of transfer, direction, polling interval and
56
55
  maximum packet size.
57
56
 
57
+ See [the documentation](http://rubydoc.info/gems/libusb/frames) for a full API description.
58
58
 
59
59
  Prerequisites
60
60
  -------------
61
61
 
62
- * Linux, MacOSX or Windows system with Ruby MRI 1.8.7/1.9/2.0, JRuby or recent version of Rubinius
63
- * Optionally: [libusb](http://libusb.info) or [libusbx](http://libusbx.org) library version 1.0.8+ :
62
+ * Linux, MacOS or Windows system with Ruby MRI 1.9/2.x, JRuby or recent version of Rubinius
63
+ * Optionally: [libusb](http://libusb.info) C-library version 1.0.8 or any newer version.
64
+ The system libusb library can be installed like so:
64
65
  * Debian or Ubuntu:
65
66
 
66
67
  ```
67
68
  $ sudo apt-get install libusb-1.0-0-dev
68
69
  ```
69
- * OS-X: install with homebrew:
70
+ * MacOS: install with homebrew:
70
71
 
71
72
  ```
72
73
  $ brew install libusb
@@ -83,7 +84,7 @@ Install
83
84
 
84
85
  $ gem install libusb
85
86
 
86
- While ```gem install``` the system is checked for a usable libusb(x) library installation.
87
+ While ```gem install``` the system is checked for a usable libusb library installation.
87
88
  If none could be found, a bundled libusb version is built and used, instead.
88
89
 
89
90
  Latest code can be used in this way:
@@ -92,11 +93,21 @@ Latest code can be used in this way:
92
93
  $ bundle
93
94
  $ rake install_gem
94
95
 
96
+ Troubleshooting
97
+ ------------------------
98
+ In order to implement a driver for a USB device, it's essential to have a look at the packets that are send to and received back from the USB device. [Wireshark](https://www.wireshark.org) has builtin capabilities to sniff USB traffic. On Linux you possibly need to load the usbmon kernel module before start:
99
+ ```
100
+ sudo modprobe usbmon
101
+ ```
102
+ On Windows it's possible to sniff USB, if the USB kernel driver was installed by the Wireshark setup.
103
+
104
+ ![Wireshark](wireshark-usb-sniffer.png?raw=true "Wireshark sniffing USB packets")
105
+
95
106
  Device hotplug support
96
107
  ----------------------
97
108
 
98
109
  Support for device hotplugging can be used, if ```LIBUSB.has_capability?(:CAP_HAS_HOTPLUG)``` returns ```true```.
99
- This requires libusb(x)-1.0.16 or newer on Linux or OS-X. Windows support is [still on the way](https://github.com/libusbx/libusbx/issues/9).
110
+ This requires libusb-1.0.16 or newer on Linux or MacOS. Windows support is [still on the way](https://github.com/libusbx/libusbx/issues/9).
100
111
 
101
112
  A hotplug event handler can be registered with {LIBUSB::Context#on_hotplug_event}.
102
113
  You then need to call {LIBUSB::Context#handle_events} in order to receive any events.
@@ -109,21 +120,21 @@ Usage on Windows
109
120
 
110
121
  In contrast to Linux, any access to an USB device by LIBUSB on Windows requires a proper driver
111
122
  installed in the system. Fortunately creating such a driver is quite easy with
112
- [Zadig](http://sourceforge.net/projects/libwdi/files/zadig/). Select the interesting USB device,
123
+ [Zadig](http://zadig.akeo.ie/). Select the interesting USB device,
113
124
  choose WinUSB driver and press "Install Driver". That's it. You may take the generated output directory
114
- with it's INI-file and use it for driver installation on other 32 or 64 bit Windows
125
+ with it's INI-file and use it for driver installations on other 32 or 64 bit Windows
115
126
  systems.
116
127
 
117
128
 
118
129
  Cross compiling for Windows
119
130
  ---------------------------
120
131
 
121
- Libusb-gem can be cross built for the win32 platform, using the [rake-compiler-dock](https://github.com/larskanis/rake-compiler-dock) .
132
+ Libusb-gem can be cross built for Windows and Linux operating systems, using the [rake-compiler-dock](https://github.com/larskanis/rake-compiler-dock) .
122
133
  Just run:
123
134
 
124
- $ rake gem:windows
135
+ $ rake gem:native
125
136
 
126
- If everything works, there should be `libusb-VERSION-x86-mingw32.gem` in the pkg
137
+ If everything works, there are several platform specific gem files (like `libusb-VERSION-x64-mingw32.gem`) in the pkg
127
138
  directory.
128
139
 
129
140
  EventMachine integration
data/Rakefile CHANGED
@@ -8,10 +8,11 @@ require 'uri'
8
8
  require 'ostruct'
9
9
  require 'rake/clean'
10
10
  require 'rake_compiler_dock'
11
+ require_relative 'ext/libusb_recipe'
11
12
 
12
13
  task :gem => :build
13
14
  task :compile do
14
- sh "ruby ext/extconf.rb"
15
+ sh "ruby ext/extconf.rb --disable-system-libusb"
15
16
  end
16
17
 
17
18
  task :test=>:compile do
@@ -24,110 +25,64 @@ task :travis=>:compile do
24
25
  end
25
26
  task :default => :test
26
27
 
27
- task 'gem:windows' do
28
- RakeCompilerDock.sh "bundle && rake cross gem"
29
- end
30
-
31
- COMPILE_HOME = Pathname( "./tmp" ).expand_path
32
- STATIC_SOURCESDIR = COMPILE_HOME + 'sources'
33
-
34
- # Fetch tarball from sourceforge
35
- LIBUSB_VERSION = ENV['LIBUSB_VERSION'] || '1.0.20'
36
- LIBUSB_SOURCE_URI = URI( "http://downloads.sourceforge.net/project/libusb/libusb-1.0/libusb-#{LIBUSB_VERSION}/libusb-#{LIBUSB_VERSION}.tar.bz2" )
37
- LIBUSB_TARBALL = STATIC_SOURCESDIR + File.basename( LIBUSB_SOURCE_URI.path )
38
-
39
- # Fetch tarball from git repo
40
- # LIBUSB_VERSION = ENV['LIBUSB_VERSION'] || '295c9d1'
41
- # LIBUSB_SOURCE_URI = URI( "http://git.libusb.org/?p=libusb.git;a=snapshot;h=#{LIBUSB_VERSION};sf=tbz2" )
42
- # LIBUSB_TARBALL = STATIC_SOURCESDIR + "libusb-#{LIBUSB_VERSION}.tar.bz2"
28
+ task "release:tag" do
29
+ hfile = "History.md"
30
+ version = LIBUSB::VERSION
31
+ reldate = Time.now.strftime("%Y-%m-%d")
32
+ headline = '([^\w]*)(\d+\.\d+\.\d+)([^\w]+)([2Y][0Y][0-9Y][0-9Y]-[0-1M][0-9M]-[0-3D][0-9D])([^\w]*|$)'
43
33
 
44
- # Fetch tarball from libusbx
45
- # LIBUSB_VERSION = ENV['LIBUSB_VERSION'] || '1.0.17'
46
- # LIBUSB_SOURCE_URI = URI( "http://downloads.sourceforge.net/project/libusbx/releases/#{LIBUSB_VERSION[/^\d+\.\d+\.\d+/]}/source/libusbx-#{LIBUSB_VERSION}.tar.bz2" )
47
- # LIBUSB_TARBALL = STATIC_SOURCESDIR + File.basename( LIBUSB_SOURCE_URI.path )
48
-
49
- # Fetch tarball from Pete Batard's git repo
50
- # LIBUSB_VERSION = ENV['LIBUSB_VERSION'] || '4cc72d0'
51
- # LIBUSB_SOURCE_URI = URI( "http://git.libusb.org/?p=libusb-pbatard.git;a=snapshot;h=#{LIBUSB_VERSION};sf=tbz2" )
52
- # LIBUSB_TARBALL = STATIC_SOURCESDIR + "libusb-pbatard-#{LIBUSB_VERSION}.tar.bz2"
34
+ hin = File.read(hfile)
35
+ hout = hin.sub(/#{headline}/) do
36
+ raise "#{hfile} isn't up-to-date for version #{version}" unless $2==version
37
+ $1 + $2 + $3 + reldate + $5
38
+ end
39
+ if hout != hin
40
+ Bundler.ui.confirm "Updating #{hfile} for release."
41
+ File.write(hfile, hout)
42
+ sh "git", "commit", hfile, "-m", "Update release date in #{hfile}"
43
+ end
53
44
 
54
- EXT_BUILDDIR = Pathname( "./ext" ).expand_path
55
- EXT_LIBUSB_BUILDDIR = EXT_BUILDDIR + LIBUSB_TARBALL.basename(".tar.bz2")
45
+ Bundler.ui.confirm "Tag release with annotation:"
46
+ m = hout.match(/(?<annotation>#{headline}.*?)#{headline}/m) || raise("Unable to find release notes in #{hfile}")
47
+ Bundler.ui.info(m[:annotation].gsub(/^/, " "))
48
+ IO.popen(["git", "tag", "--file=-", version], "w") do |fd|
49
+ fd.write m[:annotation]
50
+ end
51
+ end
56
52
 
57
- directory STATIC_SOURCESDIR.to_s
53
+ task "release:guard_clean" => "release:tag"
58
54
 
59
- # libusb source file should be stored there
60
- file LIBUSB_TARBALL => STATIC_SOURCESDIR do |t|
61
- # download the source file using wget or curl
62
- chdir File.dirname(t.name) do
63
- url = LIBUSB_SOURCE_URI
64
- sh "wget '#{url}' -O #{LIBUSB_TARBALL}"
55
+ task "release:rubygem_push" => "gem:native" do
56
+ CrossLibraries.each do |ruby_platform, _|
57
+ gh = Bundler::GemHelper.new
58
+ gh.send(:rubygem_push, "pkg/#{gh.gemspec.name}-#{gh.gemspec.version}-#{ruby_platform}.gem")
65
59
  end
66
60
  end
67
61
 
62
+ task 'gem:native' do
63
+ sh "bundle package"
64
+ RakeCompilerDock.sh <<-EOT
65
+ sudo apt-get update &&
66
+ sudo apt-get -y install libudev-dev libudev-dev:i386 &
67
+ bundle --local &&
68
+ rake cross gem
69
+ EOT
70
+ end
68
71
 
69
72
  class CrossLibrary < OpenStruct
70
73
  include Rake::DSL
71
74
 
72
- def initialize(ruby_platform, host_platform)
75
+ def initialize(ruby_platform, host_platform, libusb_dllname)
73
76
  super()
74
77
 
75
- self.ruby_platform = ruby_platform
76
- self.host_platform = host_platform
77
-
78
- self.static_builddir = COMPILE_HOME + 'builds' + ruby_platform
79
- self.ruby_build = RbConfig::CONFIG["host"]
80
-
81
- # Static libusb build vars
82
- self.static_libusb_builddir = static_builddir + LIBUSB_TARBALL.basename(".tar.bz2")
83
- self.libusb_configure = static_libusb_builddir + 'configure'
84
- self.libusb_makefile = static_libusb_builddir + 'Makefile'
85
- self.libusb_dll = static_libusb_builddir + 'libusb/.libs/libusb-1.0.dll'
86
-
87
- #
88
- # Static libusb build tasks
89
- #
90
- CLEAN.include static_libusb_builddir.to_s
91
-
92
- directory static_libusb_builddir.to_s
78
+ self.ruby_platform = ruby_platform
79
+ self.recipe = LibusbRecipe.new
80
+ recipe.host = host_platform
81
+ recipe.configure_options << "--host=#{recipe.host}"
82
+ self.libusb_dll = Pathname.new(recipe.path) + libusb_dllname
93
83
 
94
- # Extract the libusb builds
95
- file static_libusb_builddir => LIBUSB_TARBALL do |t|
96
- sh 'tar', '-xjf', LIBUSB_TARBALL.to_s, '-C', static_libusb_builddir.parent.to_s
97
- libusb_makefile.unlink if libusb_makefile.exist?
98
- end
99
-
100
- file libusb_configure => static_libusb_builddir do |t|
101
- Dir.chdir( static_libusb_builddir ) do
102
- sh "sh autogen.sh && make distclean"
103
- end
104
- end
105
-
106
- libusb_env = [
107
- "CFLAGS='-fno-omit-frame-pointer'",
108
- "LDFLAGS='-static-libgcc'",
109
- "CC='#{host_platform}-gcc -static-libgcc'", # hack libtool, since it doesn't support -static-libgcc yet.
110
- ]
111
-
112
- # generate the makefile in a clean build location
113
- file libusb_makefile => libusb_configure do |t|
114
- Dir.chdir( static_libusb_builddir ) do
115
- options = [
116
- "--target=#{host_platform}",
117
- "--host=#{host_platform}",
118
- "--build=#{ruby_build}",
119
- ]
120
-
121
- configure_path = static_libusb_builddir + 'configure'
122
- sh "env #{[libusb_env, configure_path.to_s, *options].join(" ")}"
123
- end
124
- end
125
-
126
- # make libusb-1.0.dll
127
- task libusb_dll => [ libusb_makefile ] do |t|
128
- Dir.chdir( static_libusb_builddir ) do
129
- sh 'make'
130
- end
84
+ file libusb_dll do
85
+ recipe.cook
131
86
  end
132
87
 
133
88
  task "libusb_dll:#{ruby_platform}" => libusb_dll
@@ -137,9 +92,17 @@ class CrossLibrary < OpenStruct
137
92
  spec = Gem::Specification::load("libusb.gemspec").dup
138
93
  spec.platform = Gem::Platform.new(ruby_platform)
139
94
  spec.extensions = []
95
+
96
+ # Remove files unnecessary for native gems
140
97
  spec.files -= `git ls-files ext`.split("\n")
98
+ spec.files.reject!{|f| f.start_with?('ports') }
141
99
  spec_text_files = spec.files.dup
142
- spec.files << "lib/#{File.basename(libusb_dll)}"
100
+
101
+ # Add native libusb-dll
102
+ spec.files << "lib/#{libusb_dll.basename}"
103
+
104
+ # MiniPortile isn't required for native gems
105
+ spec.dependencies.reject!{|d| d.name=="mini_portile2" }
143
106
 
144
107
  # Generate a package for this gem
145
108
  pkg = Gem::PackageTask.new(spec) do |pkg|
@@ -161,32 +124,24 @@ class CrossLibrary < OpenStruct
161
124
  end
162
125
 
163
126
  # copy libusb.dll to pkg directory
164
- f = "#{pkg.package_dir_path}/lib/#{File.basename(libusb_dll)}"
127
+ f = "#{pkg.package_dir_path}/lib/#{libusb_dll.basename}"
165
128
  mkdir_p File.dirname(f)
166
129
  rm_f f
167
- safe_ln libusb_dll, f
130
+ safe_ln libusb_dll.realpath, f
168
131
  end
169
132
 
170
- file "lib/#{File.basename(libusb_dll)}" => [libusb_dll]
133
+ file "lib/#{libusb_dll.basename}" => [libusb_dll]
171
134
  end
172
135
  end
173
136
  end
174
137
 
175
138
  CrossLibraries = [
176
- ['i386-mingw32', 'i686-w64-mingw32'],
177
- ['x64-mingw32', 'x86_64-w64-mingw32'],
178
- ].map do |ruby_platform, host_platform|
179
- CrossLibrary.new ruby_platform, host_platform
180
- end
181
-
182
- desc "Download and update bundled libusb"
183
- task :update_libusb => LIBUSB_TARBALL do
184
- sh 'rm', '-r', (EXT_BUILDDIR + "libusb-*").to_s do end
185
- sh 'git', 'rm', '-rfq', (EXT_BUILDDIR + "libusb-*").to_s do end
186
- sh 'tar', '-xjf', LIBUSB_TARBALL.to_s, '-C', EXT_LIBUSB_BUILDDIR.parent.to_s
187
- drops = %w[msvc].map{|f| (EXT_LIBUSB_BUILDDIR+f).to_s }
188
- sh 'rm', '-r', '-f', *drops
189
- sh 'git', 'add', EXT_LIBUSB_BUILDDIR.to_s
139
+ ['x86-mingw32', 'i686-w64-mingw32', 'bin/libusb-1.0.dll'],
140
+ ['x64-mingw32', 'x86_64-w64-mingw32', 'bin/libusb-1.0.dll'],
141
+ ['x86-linux', 'i686-linux-gnu', 'lib/libusb-1.0.so'],
142
+ ['x86_64-linux', 'x86_64-linux-gnu', 'lib/libusb-1.0.so'],
143
+ ].each do |ruby_platform, host_platform, libusb_dll|
144
+ CrossLibrary.new ruby_platform, host_platform, libusb_dll
190
145
  end
191
146
 
192
147
  # vim: syntax=ruby
@@ -0,0 +1,23 @@
1
+ init:
2
+ - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
3
+ - SET PATH=C:\MinGW\msys\1.0\bin;%PATH%
4
+ - SET RAKEOPT=-rdevkit
5
+ install:
6
+ - ruby --version
7
+ - gem --version
8
+ - bundle install
9
+ build_script:
10
+ - bundle exec rake compile
11
+ test_script:
12
+ - bundle exec rake travis
13
+ environment:
14
+ matrix:
15
+ - ruby_version: "193"
16
+ - ruby_version: "200"
17
+ - ruby_version: "200-x64"
18
+ - ruby_version: "21"
19
+ - ruby_version: "21-x64"
20
+ - ruby_version: "22"
21
+ - ruby_version: "22-x64"
22
+ - ruby_version: "23"
23
+ - ruby_version: "23-x64"
@@ -2,6 +2,9 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'ffi'
5
+ require 'fileutils'
6
+
7
+ include FileUtils
5
8
 
6
9
  if RUBY_PLATFORM =~ /java/
7
10
  # JRuby's C extension support is disabled by default, so we can not easily test
@@ -50,7 +53,7 @@ def libusb_usable?
50
53
  prefix = FFI::Platform::LIBPREFIX.empty? ? 'lib' : FFI::Platform::LIBPREFIX
51
54
  bundled_dll = File.join(root_path, "lib/#{prefix}usb-1.0.#{ext}")
52
55
  bundled_dll_cygwin = File.join(root_path, "bin/#{prefix}usb-1.0.#{ext}")
53
- ffi_lib(["#{prefix}usb-1.0", bundled_dll, bundled_dll_cygwin])
56
+ ffi_lib([bundled_dll, bundled_dll_cygwin, "#{prefix}usb-1.0"])
54
57
  end
55
58
  true
56
59
  rescue LoadError
@@ -59,23 +62,18 @@ def libusb_usable?
59
62
  end
60
63
 
61
64
  def build_bundled_libusb(have_udev)
62
- libusb_dir = Dir[File.expand_path('../../ext/libusb-*', __FILE__)].first
63
- root_dir = File.expand_path('../..', __FILE__)
64
- raise "could not find embedded libusb sources" unless libusb_dir
65
-
66
65
  # Enable udev for hot-plugging when it is available.
67
66
  # This is the same check that is done in libusb's configure.ac file
68
67
  # but we don't abort in case it's not available, but continue
69
68
  # without hot-plugging.
70
69
  have_udev &&= have_header('libudev.h') && have_library('udev', 'udev_new')
71
70
 
72
- old_dir = Dir.pwd
73
- Dir.chdir libusb_dir
74
- cmd = "sh configure #{'--disable-udev' unless have_udev} --prefix=#{root_dir} && make && make install"
75
- puts cmd
76
- system cmd
77
- raise "libusb build exited with #{$?.exitstatus}" if $?.exitstatus!=0
78
- Dir.chdir old_dir
71
+ require_relative 'libusb_recipe'
72
+ recipe = LibusbRecipe.new
73
+ recipe.configure_options << "--disable-udev" unless have_udev
74
+ recipe.cook_and_activate
75
+
76
+ cp_r File.join(recipe.path, '.'), '.', verbose: true, remove_destination: true
79
77
  end
80
78
 
81
79
  unless enable_config('system-libusb', libusb_usable?)