Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 1e1e537

Browse files
Add all targets to the all commands so that they check all binaries tests and examples
1 parent 771b14c commit 1e1e537

File tree

2 files changed

+47
-39
lines changed

2 files changed

+47
-39
lines changed

lib/linter-rust.coffee

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ class LinterRust
7676
cmdPath = if cmd[0]? then path.dirname cmd[0] else __dirname
7777
args = cmd.slice 1
7878
env.PATH = cmdPath + path.delimiter + env.PATH
79-
cargoManifestFile = @locateCargo curDir
80-
cargoManifestDir = path.dirname cargoManifestFile
79+
editingDir = path.dirname textEditor.getPath()
80+
cargoWorkspaceManifestFile = @locateCargoWorkspace editingDir
81+
cargoCrateManifestFile = @locateCargoCrate editingDir
8182

8283
# we set flags only for intermediate json support
8384
if errorMode == errorModes.FLAGS_JSON_CARGO
@@ -91,8 +92,14 @@ class LinterRust
9192
stream: 'both'
9293
execOpts.timeout = Infinity if @disableExecTimeout
9394

94-
atom_linter.exec(command, args, execOpts)
95-
.then (result) =>
95+
Promise.all [atom_linter.exec(command, args, execOpts), cargoWorkspaceManifestFile]
96+
.then (promiseReturns) ->
97+
result = promiseReturns[0]
98+
cargoWorkspaceManifestFile = promiseReturns[1]
99+
100+
cargoCrateManifestDir = path.dirname cargoCrateManifestFile
101+
cargoWorkspaceManifestDir = path.dirname cargoWorkspaceManifestFile
102+
96103
{stdout, stderr, exitCode} = result
97104
# first, check if an output says specified features are invalid
98105
if stderr.indexOf('does not have these features') >= 0
@@ -120,7 +127,8 @@ class LinterRust
120127
messages.forEach (message) ->
121128
if !(path.isAbsolute message.location.file)
122129
message.location.file = path.join curDir, message.location.file if fs.existsSync path.join curDir, message.location.file
123-
message.location.file = path.join cargoManifestDir, message.location.file if fs.existsSync path.join cargoManifestDir, message.location.file
130+
message.location.file = path.join cargoCrateManifestDir, message.location.file if fs.existsSync path.join cargoCrateManifestDir, message.location.file
131+
message.location.file = path.join cargoWorkspaceManifestDir, message.location.file if fs.existsSync path.join cargoWorkspaceManifestDir, message.location.file
124132
messages
125133
else
126134
# whoops, we're in trouble -- let's output as much as we can
@@ -141,15 +149,15 @@ class LinterRust
141149

142150
initCmd: (editingFile) =>
143151
curDir = if editingFile? then path.dirname editingFile else __dirname
144-
cargoManifestPath = @locateCargo curDir
145-
if not @useCargo or not cargoManifestPath
146-
@decideErrorMode(curDir, 'rustc').then (mode) =>
147-
mode.buildArguments(this, [editingFile, cargoManifestPath]).then (cmd) ->
148-
[cmd, mode]
149-
else
150-
@decideErrorMode(curDir, 'cargo').then (mode) =>
151-
mode.buildArguments(this, cargoManifestPath).then (cmd) ->
152-
[cmd, mode]
152+
@locateCargo(curDir).then (cargoManifestPath) =>
153+
if not @useCargo or not cargoManifestPath
154+
@decideErrorMode(curDir, 'rustc').then (mode) =>
155+
mode.buildArguments(this, [editingFile, cargoManifestPath]).then (cmd) ->
156+
[cmd, mode]
157+
else
158+
@decideErrorMode(curDir, 'cargo').then (mode) =>
159+
mode.buildArguments(this, cargoManifestPath).then (cmd) ->
160+
[cmd, mode]
153161

154162
compilationFeatures: (cargo) =>
155163
if @specifiedFeatures.length > 0
@@ -200,34 +208,34 @@ class LinterRust
200208
@cachedErrorMode = result
201209
result
202210

203-
locateCargo: (curDir) =>
211+
locateCargoCrate: (curDir) =>
204212
root_dir = if /^win/.test process.platform then /^.:\\$/ else /^\/$/
205213
directory = path.resolve curDir
206-
manifest_name = @cargoManifestFilename
207-
208214
loop
209-
if fs.existsSync path.join directory, manifest_name
210-
crate_level_manifest = path.join directory , manifest_name
211-
212-
if @useWorkspaceManifest
213-
execOpts =
214-
env: JSON.parse JSON.stringify process.env
215-
cwd: curDir
216-
stream: 'both'
217-
218-
atom_linter.exec('cargo', ['locate-project', '--workspace', '--manifest-path=' + crate_level_manifest], execOpts)
219-
.then (result) =>
220-
{stdout, stderr, exitCode} = result
221-
json = JSON.parse stdout
222-
return json.root
223-
.catch (error) ->
224-
return crate_level_manifest
225-
else
226-
return crate_level_manifest
227-
228-
return path.join directory , manifest_name if fs.existsSync path.join directory, manifest_name
215+
return path.join directory , @cargoManifestFilename if fs.existsSync path.join directory, @cargoManifestFilename
229216
break if root_dir.test directory
230217
directory = path.resolve path.join(directory, '..')
231218
return false
232219

220+
locateCargoWorkspace: (curDir) =>
221+
crate_level_manifest = @locateCargoCrate(curDir)
222+
if @useWorkspaceManifest and @useCargo
223+
execOpts =
224+
env: JSON.parse JSON.stringify process.env
225+
cwd: curDir
226+
stream: 'both'
227+
228+
return atom_linter.exec('cargo', ['locate-project', '--workspace', '--manifest-path=' + crate_level_manifest], execOpts)
229+
.then (result) =>
230+
{stdout, stderr, exitCode} = result
231+
json = JSON.parse stdout
232+
return json.root
233+
.catch (error) ->
234+
return crate_level_manifest
235+
else
236+
return crate_level_manifest
237+
238+
locateCargo: (curDir) =>
239+
return @locateCargoWorkspace curDir
240+
233241
module.exports = LinterRust

lib/mode.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ buildCargoArguments = (linter, cargoManifestPath) ->
175175

176176
cargoArgs = switch linter.cargoCommand
177177
when 'check' then ['check']
178-
when 'check all' then ['check', '--all']
178+
when 'check all' then ['check', '--all', '--all-targets']
179179
when 'check tests' then ['check', '--tests']
180180
when 'test' then ['test', '--no-run']
181-
when 'test all' then ['test', '--no-run', '--all']
181+
when 'test all' then ['test', '--no-run', '--all', '--all-targets']
182182
when 'rustc' then ['rustc', '--color', 'never']
183183
when 'clippy' then ['clippy']
184184
when 'clippy all' then ['clippy', '--workspace', '--all-targets']

0 commit comments

Comments
 (0)