u3d 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b306e92ddd2d1534178423f1ee3bc5f2b9dfcfea
4
- data.tar.gz: '082a3ba8cb66d0d150c368627664dee8e08867e7'
3
+ metadata.gz: d9c9db8b88f9c7f182b88f35bc6679cc6834ebbe
4
+ data.tar.gz: 7adc661141c3939a5ad6a336a67d6f485982350f
5
5
  SHA512:
6
- metadata.gz: 345bbce18f4aa6f1c04ed2ead7d09b7a5e74e81235423aaf0edb99249e8dfffe7b1339ae2b21bf4344b052d6d3ce8071d1fca9e5b6d004a5c206d5b566a44253
7
- data.tar.gz: 3bca903f54a03114c2172d2af8f9d33caf822f407aeb1e75d2f94637917849ef51167d84623cf8e20d776cea8f40be23565bdb9d5ecad364e0c4ae1e0808452e
6
+ metadata.gz: 817e030bd2287a8584006bfac86d9651f9b75d62fb3c98959cbd91a5bd6c5b606867111a41f84c4c4f4a395caaaa3cec07fbd8869a035b6e095b5bf74b8faea1
7
+ data.tar.gz: 7a95301d40fb53e6409c6aca3866a855c986bbdb7ed85cc972b6ff0e98254bcffa2d2bf47843598a61c19f5a7f122af1f7f98330c692a77e0e0a5022168329b3
@@ -1,4 +1,4 @@
1
- future-release=v1.0.1
1
+ future-release=v1.0.2
2
2
  since-tag=v0.9
3
3
  exclude_tags_regex=v0\.[0-8]\..*
4
4
  exclude-labels=nochangelog
@@ -1,5 +1,37 @@
1
1
  # Change Log
2
2
 
3
+ ## [v1.0.2](https://github.com/DragonBox/u3d/tree/v1.0.2) (2017-09-05)
4
+ [Full Changelog](https://github.com/DragonBox/u3d/compare/v1.0.1...v1.0.2)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - u3d/prettify: catch missing dependencies errors on Linux [\#123](https://github.com/DragonBox/u3d/issues/123)
9
+ - Prettifyer not plugged when using -logFile /dev/stdout [\#18](https://github.com/DragonBox/u3d/issues/18)
10
+ - u3d/prettify: modify compiler rule parsing for 2017+ [\#121](https://github.com/DragonBox/u3d/pull/121) ([niezbop](https://github.com/niezbop))
11
+ - ud3/prettify: improve exception logging rules [\#118](https://github.com/DragonBox/u3d/pull/118) ([niezbop](https://github.com/niezbop))
12
+ - u3d/available: linux: do not try to fetch package size if already cached [\#116](https://github.com/DragonBox/u3d/pull/116) ([lacostej](https://github.com/lacostej))
13
+ - u3d/dependencies: add command to install Linux dependencies [\#25](https://github.com/DragonBox/u3d/pull/25) ([niezbop](https://github.com/niezbop))
14
+
15
+ **Fixed bugs:**
16
+
17
+ - u3d install updating cache even with --no-download option [\#104](https://github.com/DragonBox/u3d/issues/104)
18
+
19
+ **Merged pull requests:**
20
+
21
+ - u3d/prettify: add rule to catch library loading errors [\#124](https://github.com/DragonBox/u3d/pull/124) ([niezbop](https://github.com/niezbop))
22
+ - u3d/prettify: also plug log analyzer on stdout \(Fixes \#18 \#43\) [\#122](https://github.com/DragonBox/u3d/pull/122) ([lacostej](https://github.com/lacostej))
23
+ - u3d/install: do not refresh cache when download disabled \(Fixes \#104\) [\#120](https://github.com/DragonBox/u3d/pull/120) ([lacostej](https://github.com/lacostej))
24
+
25
+ ## [v1.0.1](https://github.com/DragonBox/u3d/tree/v1.0.1) (2017-08-31)
26
+ [Full Changelog](https://github.com/DragonBox/u3d/compare/v1.0.0...v1.0.1)
27
+
28
+ **Merged pull requests:**
29
+
30
+ - u3d/downloader: use\_ssl should be set dynamically to download from https [\#113](https://github.com/DragonBox/u3d/pull/113) ([lacostej](https://github.com/lacostej))
31
+
32
+ ## [v1.0.0](https://github.com/DragonBox/u3d/tree/v1.0.0) (2017-08-31)
33
+ [Full Changelog](https://github.com/DragonBox/u3d/compare/v1.0.0.rc1...v1.0.0)
34
+
3
35
  ## [v1.0.0.rc1](https://github.com/DragonBox/u3d/tree/v1.0.0.rc1) (2017-08-30)
4
36
  [Full Changelog](https://github.com/DragonBox/u3d/compare/v0.9.4...v1.0.0.rc1)
5
37
 
@@ -20,6 +52,7 @@
20
52
 
21
53
  **Merged pull requests:**
22
54
 
55
+ - u3d: prepare for 1.0.0.rc1 release [\#111](https://github.com/DragonBox/u3d/pull/111) ([lacostej](https://github.com/lacostej))
23
56
  - fastlane-plugin-u3d: allow to depend on coming 1.0.0 version [\#109](https://github.com/DragonBox/u3d/pull/109) ([lacostej](https://github.com/lacostej))
24
57
  - u3d/run allow to configure the rules.json location using U3D\_RULES\_PATH env variable [\#108](https://github.com/DragonBox/u3d/pull/108) ([lacostej](https://github.com/lacostej))
25
58
  - u3d/run: if thread exits abnormally, don't wait for it and return [\#107](https://github.com/DragonBox/u3d/pull/107) ([lacostej](https://github.com/lacostej))
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- u3d (1.0.1)
4
+ u3d (1.0.2)
5
5
  colored (>= 1.2, < 2.0.0)
6
6
  commander (>= 4.4.0, < 5.0.0)
7
7
  file-tail (>= 1.2.0)
@@ -1,6 +1,11 @@
1
1
  # Log Analyzer rules
2
2
 
3
- The Log Prettifier processes both Unity output and existing log files thanks to a set of JSON rules. These rules are under ./config/log_rules.json. They are meant to be customizable to fit as best as possible your logging specifications.
3
+ The Log Prettifier processes both Unity output and existing log files thanks to a set of JSON rules. They are meant to be customizable to fit as best as possible your logging specifications. The default rules config found under [config/log_rules.json](https://github.com/DragonBox/u3d/blob/master/config/log_rules.json) is packaged with u3d. To use a custom ruleset set the `U3D_RULES_PATH` environment variable to point to the path of the overriding config.
4
+ ```
5
+ U3D_RULES_PATH=./my_custom_rules.json u3d prettify ...
6
+ [...]
7
+ Using ./my_custom_rules.json for prettify rules path
8
+ ```
4
9
 
5
10
  This document explains how to customize the ruleset.
6
11
 
data/README.md CHANGED
@@ -43,6 +43,8 @@ The prettifyer is on by default but can be turned off to get Unity3d's raw outpu
43
43
 
44
44
  [Information on how `prettify` works](https://github.com/DragonBox/u3d/blob/master/LOG_RULES.md)
45
45
 
46
+ * `u3d dependencies`: [Linux] Install dependencies that Unity don't install by default on Linux.
47
+
46
48
  ## Installation
47
49
 
48
50
  ```shell
@@ -89,7 +91,7 @@ When referencing to a version on the CLI, u3d sanitizes these weird versions. Fo
89
91
 
90
92
  When you install Unity with this tool, you will have to grant it higher privileges so it can perform the installation. It means that under MacOS and Linux, you will be asked for your `sudo` password.
91
93
 
92
- On Windows, you must launch a administrative command interface to be able to run `local_install` and `install` (only if you install for the latter).
94
+ On Windows, you must launch an administrative command interface to be able to run `install` without the `--no-install` option. Same goes for any kind of sanitization where u3d would move files around.
93
95
 
94
96
  ## Examples
95
97
 
@@ -117,7 +119,7 @@ u3d install 5.6.0f3 -p Unity,Documentation,WebPlayer
117
119
  u3d install 5.6.0f3 --no-install
118
120
  ```
119
121
 
120
- * Install version 5.6.0f3 of Unity without downloading it:
122
+ * Install previously downloaded version 5.6.0f3:
121
123
 
122
124
  ```shell
123
125
  u3d install 5.6.0f3 --no-download
@@ -141,9 +143,10 @@ You can get further information on how to use U3d by running `u3d --help` (or `u
141
143
 
142
144
  If you face an issue similar to this one
143
145
 
144
- SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
145
-
146
- your ruby setup to work with OpenSSL may want to be fixed.
146
+ ```shell
147
+ SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
148
+ ```
149
+ your ruby setup to work with OpenSSL probably needs to be fixed.
147
150
 
148
151
  * __On MacOS:__
149
152
 
@@ -24,10 +24,10 @@
24
24
  },
25
25
  "exception": {
26
26
  "active": true,
27
- "start_pattern": "[eE]xception.*: (?<message>.*)\\n",
28
- "end_pattern": "Filename: (?:[\\w/:]+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)",
27
+ "start_pattern": "[eE]xception\\w*: (?<message>.*)\\n",
28
+ "end_pattern": "(?:Filename: (?:[\\w/:]+/(?<file>\\w+\\.\\w+))? Line: (?<line>-?\\d+)|(?<fileunknown>filename unknown)>:(?<lineunknown>-?\\d+))",
29
29
  "start_message": false,
30
- "end_message": "%{file}(line %{line}): %{message}",
30
+ "end_message": "%{file}%{fileunknown}(line %{line}%{lineunknown}): %{message}",
31
31
  "store_lines": false,
32
32
  "ignore_lines": [
33
33
  "UnityEditor",
@@ -45,6 +45,12 @@
45
45
  "store_lines": false,
46
46
  "type": "error"
47
47
  },
48
+ "error_shared_library": {
49
+ "active": true,
50
+ "start_pattern": "error while loading shared libraries: (?<message>.*)\\n",
51
+ "start_message": "Error while loading shared libraries: %{message}",
52
+ "type": "error"
53
+ },
48
54
  "log": {
49
55
  "active": true,
50
56
  "start_pattern": "UnityEngine\\.Debug:Log\\(Object\\)",
@@ -185,13 +191,13 @@
185
191
  "active": true,
186
192
  "silent": false,
187
193
  "comment": "Compiling phase",
188
- "phase_start_pattern": "- starting compile",
194
+ "phase_start_pattern": "- [sS]tarting compile",
189
195
  "phase_end_pattern": "- Finished compile",
190
196
  "rules": {
191
197
  "target": {
192
198
  "active": true,
193
- "start_pattern": "- starting compile (?<path>.+), for buildtarget (?<target>.+)",
194
- "start_message": "Target: %{path} (buildtarget %{target})"
199
+ "start_pattern": "- [sS]tarting compile (?<path>.+)(?<target>, for buildtarget .+)?",
200
+ "start_message": "Starting compile: %{path} %{target}"
195
201
  },
196
202
  "finished": {
197
203
  "active": true,
@@ -7,7 +7,7 @@ PATH
7
7
  PATH
8
8
  remote: /Users/lacostej/Code/OSS/u3d
9
9
  specs:
10
- u3d (1.0.0.rc1)
10
+ u3d (1.0.1)
11
11
  colored (>= 1.2, < 2.0.0)
12
12
  commander (>= 4.4.0, < 5.0.0)
13
13
  file-tail (>= 1.2.0)
@@ -51,13 +51,18 @@ module U3d
51
51
  @cache[key]
52
52
  end
53
53
 
54
- def initialize(path: nil, force_os: nil, force_refresh: false)
54
+ def initialize(path: nil, force_os: nil, force_refresh: false, offline: false)
55
+ raise "Cache: cannot specify both offline and force_refresh" if offline && force_refresh
55
56
  @path = path || default_path
56
57
  @cache = {}
57
58
  os = force_os || U3dCore::Helper.operating_system
58
59
  Utils.ensure_dir(@path)
59
60
  file_path = File.expand_path(DEFAULT_NAME, @path)
60
61
  need_update, data = check_for_update(file_path, os)
62
+ if offline
63
+ UI.verbose("Cache outdated but we are working offline, so no updating it.")
64
+ need_update = false
65
+ end
61
66
  @cache = data
62
67
  overwrite_cache(file_path, os) if need_update || force_refresh
63
68
  end
@@ -67,7 +72,7 @@ module U3d
67
72
  # Checks if the cache needs updating
68
73
  def check_for_update(file_path, os)
69
74
  need_update = false
70
- data = nil
75
+ data = {}
71
76
  if !File.file?(file_path)
72
77
  need_update = true
73
78
  else
@@ -98,6 +98,13 @@ module U3d
98
98
  end
99
99
  end
100
100
 
101
+ def cache_versions(os, offline: false)
102
+ cache = Cache.new(force_os: os, offline: offline)
103
+ cache_os = cache[os.id2name] || {}
104
+ cache_versions = cache_os['versions'] || {}
105
+ cache_versions
106
+ end
107
+
101
108
  def install(args: [], options: {})
102
109
  version = specified_or_current_project_version(args[0])
103
110
 
@@ -105,8 +112,7 @@ module U3d
105
112
 
106
113
  packages = packages_with_unity_first(os, options)
107
114
 
108
- cache = Cache.new(force_os: os)
109
- cache_versions = cache[os.id2name]['versions']
115
+ cache_versions = cache_versions(os, offline: !options[:download])
110
116
  version = interpret_latest(version, cache_versions)
111
117
  unless cache_versions[version]
112
118
  UI.error "No version '#{version}' was found in cache. Either it doesn't exist or u3d doesn't know about it yet. Try refreshing with 'u3d available -f'"
@@ -129,6 +135,15 @@ module U3d
129
135
  Installer.install_modules(files, definition.version, installation_path: options[:installation_path])
130
136
  end
131
137
 
138
+ def install_dependencies
139
+ unless Helper.linux?
140
+ UI.important 'u3d dependencies is Linux-only, and not needed on other OS'
141
+ return
142
+ end
143
+
144
+ LinuxDependencies.install
145
+ end
146
+
132
147
  def run(options: {}, run_args: [])
133
148
  version = options[:unity_version]
134
149
 
@@ -148,6 +148,22 @@ This command allows you to either:
148
148
  end
149
149
  end
150
150
 
151
+ command :dependencies do |c|
152
+ c.syntax = 'u3d dependencies'
153
+ c.summary = 'Installs Unity dependencies. [Linux only]'
154
+ c.description = %(
155
+ #{c.summary}
156
+
157
+ Regarding the package manager: if dpkg is installed, u3d uses apt-get else if rpm is installed yum is used. If none of them is insalled, fails.
158
+
159
+ Regarding the dependencies themselves: only dependencies for the editor are installed. WebGL, Android and Tizen require others that you will have to install manually.
160
+ More on that: https://forum.unity3d.com/threads/unity-on-linux-release-notes-and-known-issues.350256/
161
+ )
162
+ c.action do |_args, _options|
163
+ Commands.install_dependencies
164
+ end
165
+ end
166
+
151
167
  command :credentials do |c|
152
168
  c.syntax = "u3d credentials <#{Commands.credentials_actions.join(' | ')}>"
153
169
  c.description = 'Manages keychain credentials so u3d remembers them. [OSX only]'
@@ -158,7 +174,17 @@ This command allows you to either:
158
174
 
159
175
  command :prettify do |c|
160
176
  c.syntax = 'u3d prettify <logfile>'
161
- c.description = 'Prettify a saved logfile'
177
+ c.summary = 'Prettify a saved logfile'
178
+ c.description = %(
179
+ #{c.summary}
180
+
181
+ The default prettifier rules file is packaged with u3d (#{U3d::LogAnalyzer::RULES_PATH}).
182
+ You may which to pass your own using the environment variable U3D_RULES_PATH.
183
+
184
+ E.g. U3D_RULES_PATH=my_rules.json u3d prettify ...
185
+
186
+ Fore more information about how the rules work, see https://github.com/DragonBox/u3d/blob/master/LOG_RULES.md
187
+ )
162
188
  c.action do |args, _options|
163
189
  Commands.local_analyze(args: args)
164
190
  end
@@ -20,13 +20,11 @@
20
20
  # SOFTWARE.
21
21
  ## --- END LICENSE BLOCK ---
22
22
 
23
- require 'net/http'
24
23
  require 'u3d/utils'
25
24
  require 'u3d/download_validator'
26
25
 
27
26
  module U3d
28
27
  # Take care of downloading files and packages
29
- # rubocop:disable ModuleLength
30
28
  module Downloader
31
29
  # Name of the directory for the package downloading
32
30
  DOWNLOAD_DIRECTORY = 'Unity_Packages'.freeze
@@ -115,7 +113,7 @@ module U3d
115
113
 
116
114
  UI.header "Downloading #{package} version #{definition.version}"
117
115
  UI.message 'Downloading from ' + url.to_s.cyan.underline
118
- download_package(path, url, size: definition.size_in_kb(package))
116
+ download_package(path, url, size: definition.size_in_bytes(package))
119
117
 
120
118
  if validator.validate(package, path, definition)
121
119
  UI.success "Successfully downloaded #{package}."
@@ -126,38 +124,7 @@ module U3d
126
124
  end
127
125
 
128
126
  def download_package(path, url, size: nil)
129
- File.open(path, 'wb') do |f|
130
- uri = URI(url)
131
- current = 0
132
- last_print_update = 0
133
- Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
134
- request = Net::HTTP::Get.new uri
135
- http.request request do |response|
136
- begin
137
- size ||= Integer(response['Content-Length'])
138
- rescue ArgumentError
139
- UI.verbose 'Unable to get length of file in download'
140
- end
141
- started_at = Time.now.to_i - 1
142
- response.read_body do |segment|
143
- f.write(segment)
144
- current += segment.length
145
- # wait for Net::HTTP buffer on slow networks
146
- # FIXME revisits, this slows down download on fast network
147
- # sleep 0.08 # adjust to reduce CPU
148
- next unless UI.interactive?
149
- next unless Time.now.to_f - last_print_update > 0.5
150
- last_print_update = Time.now.to_f
151
- if size
152
- Utils.print_progress(current, size, started_at)
153
- else
154
- Utils.print_progress_nosize(current, started_at)
155
- end
156
- end
157
- end
158
- end
159
- print "\n" if UI.interactive?
160
- end
127
+ Utils.download_file(path, url, size: size)
161
128
  rescue Interrupt => e
162
129
  # Ensure that the file is deleted if download is aborted
163
130
  File.delete path
@@ -207,5 +174,4 @@ module U3d
207
174
  end
208
175
  end
209
176
  end
210
- # rubocop:enable ModuleLength
211
177
  end
@@ -47,7 +47,7 @@ module U3d
47
47
  ini_path = File.expand_path(ini_name, default_ini_path)
48
48
  unless File.file?(ini_path)
49
49
  if os == 'linux'
50
- UI.error "No INI file for version #{version}. Try discovering the available versions with 'u3d available -f'"
50
+ UI.error "No INI file for version #{version}. Try discovering the available versions with 'u3d available -f'" unless offline
51
51
  return nil
52
52
  end
53
53
  raise "INI file does not exist at #{ini_path}" if offline
@@ -279,4 +279,63 @@ module U3d
279
279
  end
280
280
  end
281
281
  end
282
+
283
+ class LinuxDependencies
284
+ # see https://forum.unity3d.com/threads/unity-on-linux-release-notes-and-known-issues.350256/
285
+ DEPENDENCIES = [
286
+ 'gconf-service',
287
+ 'lib32gcc1',
288
+ 'lib32stdc++6',
289
+ 'libasound2',
290
+ 'libc6',
291
+ 'libc6-i386',
292
+ 'libcairo2',
293
+ 'libcap2',
294
+ 'libcups2',
295
+ 'libdbus-1-3',
296
+ 'libexpat1',
297
+ 'libfontconfig1',
298
+ 'libfreetype6',
299
+ 'libgcc1',
300
+ 'libgconf-2-4',
301
+ 'libgdk-pixbuf2.0-0',
302
+ 'libgl1-mesa-glx',
303
+ 'libglib2.0-0',
304
+ 'libglu1-mesa',
305
+ 'libgtk2.0-0',
306
+ 'libnspr4',
307
+ 'libnss3',
308
+ 'libpango1.0-0',
309
+ 'libstdc++6',
310
+ 'libx11-6',
311
+ 'libxcomposite1',
312
+ 'libxcursor1',
313
+ 'libxdamage1',
314
+ 'libxext6',
315
+ 'libxfixes3',
316
+ 'libxi6',
317
+ 'libxrandr2',
318
+ 'libxrender1',
319
+ 'libxtst6',
320
+ 'zlib1g',
321
+ 'debconf',
322
+ 'npm',
323
+ 'libpq5' # missing from original list
324
+ ].freeze
325
+
326
+ def self.install
327
+ if `which dpkg` != ''
328
+ prefix = 'apt-get -y install'
329
+ elsif `which rpm` != ''
330
+ prefix = 'yum -y install'
331
+ else
332
+ raise 'Cannot install dependencies on your Linux distribution'
333
+ end
334
+
335
+ if UI.interactive?
336
+ return unless UI.confirm "Install dependencies? (#{DEPENDENCIES.length} dependency(ies) to install)"
337
+ end
338
+ U3dCore::CommandExecutor.execute(command: "#{prefix} #{DEPENDENCIES.join(' ')}", admin: true)
339
+ end
340
+ end
282
341
  end
@@ -78,15 +78,8 @@ module U3d
78
78
  @phases.each do |name, phase|
79
79
  next if name == @active_phase
80
80
  next unless line =~ phase['phase_start_pattern']
81
- if @active_rule
82
- # Active rule should be finished
83
- # If it is still active during phase change, it means that something went wrong
84
- UI.error("[#{@active_phase}] Could not finish active rule '#{@active_rule}'. Aborting it.")
85
- @active_rule = nil
86
- end
81
+ finish_phase
87
82
  @active_phase = name
88
- @context.clear
89
- @rule_lines_buffer.clear
90
83
  UI.verbose("--- Beginning #{name} phase ---")
91
84
  break
92
85
  end
@@ -189,12 +182,30 @@ module U3d
189
182
  end
190
183
  end
191
184
 
192
- apply_ruleset.call(@phases[@active_phase]['rules'], @active_phase) if @active_phase
185
+ if @active_phase
186
+ apply_ruleset.call(@phases[@active_phase]['rules'], @active_phase)
187
+ if @phases[@active_phase]['phase_end_pattern'] && @phases[@active_phase]['phase_end_pattern'] =~ line
188
+ finish_phase
189
+ end
190
+ end
193
191
  apply_ruleset.call(@generic_rules, 'GENERAL')
194
192
  end
195
193
 
196
194
  private
197
195
 
196
+ def finish_phase
197
+ if @active_rule
198
+ # Active rule should be finished
199
+ # If it is still active during phase change, it means that something went wrong
200
+ UI.error("[#{@active_phase}] Could not finish active rule '#{@active_rule}'. Aborting it.")
201
+ @active_rule = nil
202
+ end
203
+ UI.verbose("--- Ending #{@active_phase} phase ---")
204
+ @active_phase = nil
205
+ @context.clear
206
+ @rule_lines_buffer.clear
207
+ end
208
+
198
209
  def rules_path
199
210
  path = ENV["U3D_RULES_PATH"]
200
211
  unless path.nil?
@@ -30,24 +30,22 @@ module U3d
30
30
  def run(installation, args, raw_logs: false)
31
31
  log_file = find_and_prepare_logfile(installation, args)
32
32
 
33
- tail_thread = Thread.new do
34
- begin
35
- if raw_logs
36
- pipe(log_file) { |l| UI.message l.rstrip }
37
- else
38
- analyzer = LogAnalyzer.new
39
- pipe(log_file) { |l| analyzer.parse_line l }
40
- end
41
- rescue => e
42
- UI.error "Failure while trying to pipe #{log_file}: #{e.message}"
43
- e.backtrace.each { |l| UI.error " #{l}" }
33
+ if raw_logs
34
+ output_callback = proc do |line|
35
+ UI.command_output(line.rstrip)
36
+ end
37
+ else
38
+ analyzer = LogAnalyzer.new
39
+ output_callback = proc do |line|
40
+ analyzer.parse_line(line)
44
41
  end
45
42
  end
46
43
 
47
- # Wait for tail_thread setup to be complete
48
- sleep 0.5 while tail_thread.status == 'run'
49
- return unless tail_thread.status
50
- tail_thread.run
44
+ if log_file
45
+ tail_thread = start_tail_thread(log_file, output_callback)
46
+ return unless tail_thread.status
47
+ tail_thread.run
48
+ end
51
49
 
52
50
  begin
53
51
  args.unshift(installation.exe_path)
@@ -57,16 +55,20 @@ module U3d
57
55
  args.map!(&:shellescape)
58
56
  end
59
57
 
60
- U3dCore::CommandExecutor.execute(command: args, print_all: true)
58
+ U3dCore::CommandExecutor.execute_command(command: args, output_callback: output_callback)
61
59
  ensure
62
- sleep 1
63
- Thread.kill(tail_thread)
60
+ if tail_thread
61
+ sleep 1
62
+ Thread.kill(tail_thread)
63
+ end
64
64
  end
65
65
  end
66
66
 
67
67
  def find_and_prepare_logfile(installation, args)
68
68
  log_file = Runner.find_logFile_in_args(args)
69
69
 
70
+ return nil if log_file == '/dev/stdout'
71
+
70
72
  if log_file # we wouldn't want to do that for the default log file.
71
73
  File.delete(log_file) if File.file?(log_file) # We only delete real files
72
74
  else
@@ -100,6 +102,21 @@ module U3d
100
102
 
101
103
  private
102
104
 
105
+ def start_tail_thread(log_file, output_callback)
106
+ tail_thread = Thread.new do
107
+ begin
108
+ pipe(log_file) { |line| output_callback.call(line) }
109
+ rescue => e
110
+ UI.error "Failure while trying to pipe #{log_file}: #{e.message}"
111
+ e.backtrace.each { |l| UI.error " #{l}" }
112
+ end
113
+ end
114
+
115
+ # Wait for tail_thread setup to be complete
116
+ sleep 0.5 while tail_thread.status == 'run'
117
+ tail_thread
118
+ end
119
+
103
120
  def pipe(file)
104
121
  File.open(file, 'r') do |f|
105
122
  f.extend File::Tail
@@ -26,14 +26,15 @@ module U3d
26
26
  class UnityVersionDefinition
27
27
  attr_accessor :version, :os, :url, :ini
28
28
 
29
- def initialize(version, os, cached_versions)
29
+ def initialize(version, os, cached_versions, offline: false)
30
30
  @version = version
31
31
  @os = os
32
32
  # Cache is assumed to be correct
33
33
  @url = cached_versions ? cached_versions[version] : nil
34
34
  begin
35
- @ini = INIparser.load_ini(version, cached_versions, os: os)
35
+ @ini = INIparser.load_ini(version, cached_versions, os: os, offline: offline)
36
36
  rescue => e
37
+ # FIXME: weird that we catch this here
37
38
  UI.error "Could not load INI file for version #{@version} on #{@os}: #{e}"
38
39
  @ini = nil
39
40
  end
@@ -48,7 +49,8 @@ module U3d
48
49
  @ini[key]
49
50
  end
50
51
 
51
- def size_in_kb(package)
52
+ def size_in_bytes(package)
53
+ return nil unless @ini
52
54
  return -1 unless @ini[package] && @ini[package]['size']
53
55
  @os == :win ? @ini[package]['size'] * 1024 : @ini[package]['size']
54
56
  end
@@ -128,6 +128,12 @@ module U3d
128
128
  end
129
129
 
130
130
  def save_package_size(version, url)
131
+ uvd = UnityVersionDefinition.new(version, :linux, nil, offline: true)
132
+ if (size = uvd.size_in_bytes('Unity'))
133
+ UI.verbose "Package size for version #{version} already cached: #{size}"
134
+ return
135
+ end
136
+ UI.verbose "Finding out package size for version #{version}"
131
137
  size = Utils.get_url_content_length(url)
132
138
  if size
133
139
  UnityVersionDefinition.create_fake(version, size, url)
@@ -27,6 +27,7 @@ require 'u3d_core/helper'
27
27
 
28
28
  module U3d
29
29
  # Several different utility methods
30
+ # rubocop:disable ModuleLength
30
31
  module Utils
31
32
  # Regex to capture each part of a version string (0.0.0x0)
32
33
  CSIDL_LOCAL_APPDATA = 0x001c
@@ -58,13 +59,50 @@ module U3d
58
59
  end
59
60
  end
60
61
 
62
+ def download_file(path, url, size: nil)
63
+ File.open(path, 'wb') do |f|
64
+ uri = URI(url)
65
+ current = 0
66
+ last_print_update = 0
67
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
68
+ request = Net::HTTP::Get.new uri
69
+ http.request request do |response|
70
+ begin
71
+ size ||= Integer(response['Content-Length'])
72
+ rescue ArgumentError
73
+ UI.verbose 'Unable to get length of file in download'
74
+ end
75
+ started_at = Time.now.to_i - 1
76
+ response.read_body do |segment|
77
+ f.write(segment)
78
+ current += segment.length
79
+ # wait for Net::HTTP buffer on slow networks
80
+ # FIXME revisits, this slows down download on fast network
81
+ # sleep 0.08 # adjust to reduce CPU
82
+ next unless UI.interactive?
83
+ next unless Time.now.to_f - last_print_update > 0.5
84
+ last_print_update = Time.now.to_f
85
+ if size
86
+ Utils.print_progress(current, size, started_at)
87
+ else
88
+ Utils.print_progress_nosize(current, started_at)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ print "\n" if UI.interactive?
94
+ end
95
+ end
96
+
61
97
  def get_url_content_length(url)
98
+ UI.verbose "get_url_content_length #{url}"
62
99
  uri = URI(url)
63
100
  size = nil
64
101
  Net::HTTP.start(uri.host, uri.port) do |http|
65
102
  response = http.request_head url
66
103
  size = Integer(response['Content-Length'])
67
104
  end
105
+ UI.verbose "get_url_content_length #{url}: #{size}"
68
106
  size
69
107
  end
70
108
 
@@ -128,4 +166,5 @@ module U3d
128
166
  end
129
167
  end
130
168
  end
169
+ # rubocop:enable ModuleLength
131
170
  end
@@ -21,7 +21,7 @@
21
21
  ## --- END LICENSE BLOCK ---
22
22
 
23
23
  module U3d
24
- VERSION = '1.0.1'.freeze
24
+ VERSION = '1.0.2'.freeze
25
25
  DESCRIPTION = 'Provides numerous tools for installing, managing and running the Unity3D game engine from command line.'.freeze
26
26
  UNITY_VERSIONS_NOTE = "Unity3d uses the following version formatting: 0.0.0x0. The \'x\' can takes different values:\n"\
27
27
  "\t. 'f' are the main release candidates for Unity3d\n"\
@@ -53,26 +53,43 @@ module U3dCore
53
53
  # @param print_command [Boolean] Should we print the command that's being executed
54
54
  # @param error [Block] A block that's called if an error occurs
55
55
  # @param prefix [Array] An array containg a prefix + block which might get applied to the output
56
- # @param loading [String] A loading string that is shown before the first output
57
56
  # @param admin [Boolean] Do we need admin privilege for this command?
58
- # @param keychain [Boolean] Should we fetch admin rights from the keychain on OSX
59
57
  # @return [String] All the output as string
60
- def execute(command: nil, print_all: false, print_command: true, error: nil, prefix: nil, loading: nil, admin: false)
58
+ # @deprecated
59
+ def execute(command: nil, print_all: false, print_command: true, error: nil, prefix: nil, admin: false)
61
60
  print_all = true if U3dCore::Globals.verbose?
62
61
  prefix ||= {}
63
62
 
63
+ output_callback = nil
64
+ if print_all
65
+ output_callback = proc do |line|
66
+ # Prefix the current line with a string
67
+ prefix.each do |element|
68
+ line = element[:prefix] + line if element[:block] && element[:block].call(line)
69
+ end
70
+ UI.command_output(line)
71
+ end
72
+ end
73
+
74
+ execute_command(command: command, output_callback: output_callback, print_command: print_command, error_callback: error, admin: admin)
75
+ end
76
+
77
+ # @param command [String] The command to be executed
78
+ # @param output_callback [Block] the command to pass to print output
79
+ # @param print_command [Boolean] Should we print the command that's being executed
80
+ # @param error_callback [Block] A block that's called if an error occurs
81
+ # @param admin [Boolean] Do we need admin privilege for this command?
82
+ # @return [String] All the output as string
83
+ def execute_command(command: nil, output_callback: nil, print_command: true, error_callback: nil, admin: false)
64
84
  command = command.join(' ') if command.is_a?(Array)
65
85
  UI.command(command) if print_command
66
86
 
67
- # this is only used to show the "Loading text"...
68
- UI.command_output(loading) if print_all && loading
69
-
70
87
  command = grant_admin_privileges(command) if admin
71
88
 
72
- execute_command(command: command, print_all: print_all, error: error, prefix: prefix)
89
+ execute_command_low(command: command, output_callback: output_callback, error_callback: error_callback)
73
90
  end
74
91
 
75
- def execute_command(command: nil, print_all: nil, error: nil, prefix: nil)
92
+ def execute_command_low(command: nil, output_callback: nil, error_callback: nil)
76
93
  output = []
77
94
  begin
78
95
  status = U3dCore::Runner.run(command) do |stdin, _stdout, _pid|
@@ -80,14 +97,7 @@ module U3dCore
80
97
  line = l.strip # strip so that \n gets removed
81
98
  output << line
82
99
 
83
- next unless print_all
84
-
85
- # Prefix the current line with a string
86
- prefix.each do |element|
87
- line = element[:prefix] + line if element[:block] && element[:block].call(line)
88
- end
89
-
90
- UI.command_output(line)
100
+ output_callback.call(l) if output_callback
91
101
  end
92
102
  end
93
103
  raise "Exit status: #{status}".red if !status.nil? && status.nonzero?
@@ -99,8 +109,8 @@ module U3dCore
99
109
  output << ex.to_s
100
110
  o = output.join("\n")
101
111
  UI.verbose o
102
- raise ex unless error
103
- error.call(o, nil)
112
+ raise ex unless error_callback
113
+ error_callback.call(o, nil)
104
114
  end
105
115
  return output.join("\n")
106
116
  end
@@ -141,6 +151,6 @@ module U3dCore
141
151
  end
142
152
  end
143
153
 
144
- private_class_method :execute_command
154
+ private_class_method :execute_command_low
145
155
  end
146
156
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: u3d
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerome Lacoste
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-08-31 00:00:00.000000000 Z
12
+ date: 2017-09-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: commander