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

Commit

Permalink
Add all targets to the all commands so that they check all binaries t…
Browse files Browse the repository at this point in the history
…ests and examples
  • Loading branch information
QuantumEntangledAndy committed Aug 3, 2021
1 parent 771b14c commit 1e1e537
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
82 changes: 45 additions & 37 deletions lib/linter-rust.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ class LinterRust
cmdPath = if cmd[0]? then path.dirname cmd[0] else __dirname
args = cmd.slice 1
env.PATH = cmdPath + path.delimiter + env.PATH
cargoManifestFile = @locateCargo curDir
cargoManifestDir = path.dirname cargoManifestFile
editingDir = path.dirname textEditor.getPath()
cargoWorkspaceManifestFile = @locateCargoWorkspace editingDir
cargoCrateManifestFile = @locateCargoCrate editingDir

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

atom_linter.exec(command, args, execOpts)
.then (result) =>
Promise.all [atom_linter.exec(command, args, execOpts), cargoWorkspaceManifestFile]
.then (promiseReturns) ->
result = promiseReturns[0]
cargoWorkspaceManifestFile = promiseReturns[1]

cargoCrateManifestDir = path.dirname cargoCrateManifestFile
cargoWorkspaceManifestDir = path.dirname cargoWorkspaceManifestFile

{stdout, stderr, exitCode} = result
# first, check if an output says specified features are invalid
if stderr.indexOf('does not have these features') >= 0
Expand Down Expand Up @@ -120,7 +127,8 @@ class LinterRust
messages.forEach (message) ->
if !(path.isAbsolute message.location.file)
message.location.file = path.join curDir, message.location.file if fs.existsSync path.join curDir, message.location.file
message.location.file = path.join cargoManifestDir, message.location.file if fs.existsSync path.join cargoManifestDir, message.location.file
message.location.file = path.join cargoCrateManifestDir, message.location.file if fs.existsSync path.join cargoCrateManifestDir, message.location.file
message.location.file = path.join cargoWorkspaceManifestDir, message.location.file if fs.existsSync path.join cargoWorkspaceManifestDir, message.location.file
messages
else
# whoops, we're in trouble -- let's output as much as we can
Expand All @@ -141,15 +149,15 @@ class LinterRust

initCmd: (editingFile) =>
curDir = if editingFile? then path.dirname editingFile else __dirname
cargoManifestPath = @locateCargo curDir
if not @useCargo or not cargoManifestPath
@decideErrorMode(curDir, 'rustc').then (mode) =>
mode.buildArguments(this, [editingFile, cargoManifestPath]).then (cmd) ->
[cmd, mode]
else
@decideErrorMode(curDir, 'cargo').then (mode) =>
mode.buildArguments(this, cargoManifestPath).then (cmd) ->
[cmd, mode]
@locateCargo(curDir).then (cargoManifestPath) =>
if not @useCargo or not cargoManifestPath
@decideErrorMode(curDir, 'rustc').then (mode) =>
mode.buildArguments(this, [editingFile, cargoManifestPath]).then (cmd) ->
[cmd, mode]
else
@decideErrorMode(curDir, 'cargo').then (mode) =>
mode.buildArguments(this, cargoManifestPath).then (cmd) ->
[cmd, mode]

compilationFeatures: (cargo) =>
if @specifiedFeatures.length > 0
Expand Down Expand Up @@ -200,34 +208,34 @@ class LinterRust
@cachedErrorMode = result
result

locateCargo: (curDir) =>
locateCargoCrate: (curDir) =>
root_dir = if /^win/.test process.platform then /^.:\\$/ else /^\/$/
directory = path.resolve curDir
manifest_name = @cargoManifestFilename

loop
if fs.existsSync path.join directory, manifest_name
crate_level_manifest = path.join directory , manifest_name

if @useWorkspaceManifest
execOpts =
env: JSON.parse JSON.stringify process.env
cwd: curDir
stream: 'both'

atom_linter.exec('cargo', ['locate-project', '--workspace', '--manifest-path=' + crate_level_manifest], execOpts)
.then (result) =>
{stdout, stderr, exitCode} = result
json = JSON.parse stdout
return json.root
.catch (error) ->
return crate_level_manifest
else
return crate_level_manifest

return path.join directory , manifest_name if fs.existsSync path.join directory, manifest_name
return path.join directory , @cargoManifestFilename if fs.existsSync path.join directory, @cargoManifestFilename
break if root_dir.test directory
directory = path.resolve path.join(directory, '..')
return false

locateCargoWorkspace: (curDir) =>
crate_level_manifest = @locateCargoCrate(curDir)
if @useWorkspaceManifest and @useCargo
execOpts =
env: JSON.parse JSON.stringify process.env
cwd: curDir
stream: 'both'

return atom_linter.exec('cargo', ['locate-project', '--workspace', '--manifest-path=' + crate_level_manifest], execOpts)
.then (result) =>
{stdout, stderr, exitCode} = result
json = JSON.parse stdout
return json.root
.catch (error) ->
return crate_level_manifest
else
return crate_level_manifest

locateCargo: (curDir) =>
return @locateCargoWorkspace curDir

module.exports = LinterRust
4 changes: 2 additions & 2 deletions lib/mode.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ buildCargoArguments = (linter, cargoManifestPath) ->

cargoArgs = switch linter.cargoCommand
when 'check' then ['check']
when 'check all' then ['check', '--all']
when 'check all' then ['check', '--all', '--all-targets']
when 'check tests' then ['check', '--tests']
when 'test' then ['test', '--no-run']
when 'test all' then ['test', '--no-run', '--all']
when 'test all' then ['test', '--no-run', '--all', '--all-targets']
when 'rustc' then ['rustc', '--color', 'never']
when 'clippy' then ['clippy']
when 'clippy all' then ['clippy', '--workspace', '--all-targets']
Expand Down

0 comments on commit 1e1e537

Please sign in to comment.