Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3d8483

Browse files
Kangiehololeap
authored andcommitted
1 parentdd747b2 commite3d8483

File tree

13 files changed

+1479
-41
lines changed

13 files changed

+1479
-41
lines changed

‎ShellCheck.cabal‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ library
9797
ShellCheck.Regex
9898
other-modules:
9999
Paths_ShellCheck
100+
ShellCheck.PortageAutoInternalVariables
100101
default-language: Haskell98
101102

102103
executableshellcheck

‎portage/get_vars.py‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
# Copyright 2019 The ChromiumOS Authors
4+
# All rights reserved.
5+
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are
8+
# met:
9+
10+
# * Redistributions of source code must retain the above copyright
11+
# notice, this list of conditions and the following disclaimer.
12+
# * Redistributions in binary form must reproduce the above
13+
# copyright notice, this list of conditions and the following disclaimer
14+
# in the documentation and/or other materials provided with the
15+
# distribution.
16+
# * Neither the name of Google LLC nor the names of its
17+
# contributors may be used to endorse or promote products derived from
18+
# this software without specific prior written permission.
19+
20+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
# Binary License Terms
32+
33+
"""Extract eclass variable names into Haskell list format."""
34+
from __future__importprint_function
35+
importdatetime
36+
importos
37+
importre
38+
importsys
39+
importtextwrap
40+
# Matches a line that declares a variable in an eclass.
41+
VAR_RE=re.compile(r'@(?:ECLASS-)?VARIABLE:\s*(\w+)$')
42+
# Matches a line that declares inheritance.
43+
INHERIT_RE=re.compile(r'^[^#]*\binherit((?:\s+[\w-]+)+)$')
44+
VAR_FILE_HEADER="""module ShellCheck.PortageAutoInternalVariables (
45+
portageAutoInternalVariables
46+
) where
47+
-- This file contains the variables generated by
48+
-- portage/get_vars.py"""
49+
PORTAGE_AUTO_VAR_NAME='portageAutoInternalVariables'
50+
classEclass:
51+
"""Container for eclass information"""
52+
def__init__(self,name,eclass_vars,inheritances):
53+
self.name=name
54+
self.vars=eclass_vars
55+
self.inheritances=inheritances
56+
defcalculate_eclass_vars(self,eclasses):
57+
whileself.inheritances:
58+
name=self.inheritances.pop()
59+
try:
60+
sub_eclass=eclasses[name]
61+
new_vars=sub_eclass.calculate_eclass_vars(eclasses).vars
62+
self.vars=self.vars.union(new_vars)
63+
exceptException:
64+
pass
65+
returnself
66+
defprint_var_list(eclass,eclass_vars):
67+
var_list=' '.join(['"%s",'%vforvinsorted(eclass_vars)])
68+
print(' -- %s\n%s'%
69+
(eclass,
70+
textwrap.fill(
71+
var_list,80,initial_indent=' ',subsequent_indent=' ')))
72+
defprocess_file(eclass_path):
73+
eclass_name=os.path.splitext(os.path.basename(eclass_path))[0]
74+
withopen(eclass_path,'r')asf:
75+
eclass_vars=set()
76+
eclass_inheritances=set()
77+
forlineinf:
78+
line=line.strip()
79+
ifnotline:
80+
continue
81+
whileline[-1]=='\\':
82+
line=line[:-1]+next(f).strip()
83+
match=VAR_RE.search(line)
84+
ifmatch:
85+
var_name=match.group(1)
86+
eclass_vars.add(var_name.strip())
87+
else:
88+
match=INHERIT_RE.search(line)
89+
ifmatch:
90+
forinheritanceinre.split(r'\s+',match.group(1)):
91+
ifinheritance.strip():
92+
eclass_inheritances.add(inheritance.strip())
93+
returnEclass(eclass_name,eclass_vars,eclass_inheritances)
94+
defformat_eclasses_as_haskell_map(eclasses):
95+
map_entries= []
96+
join_string='", "'
97+
forvalueinsorted(eclasses,key=(lambdax:x.name)):
98+
ifvalue.vars:
99+
var_list_string=f'"{join_string.join(sorted(list(value.vars)))}"'
100+
map_entries.append(
101+
textwrap.fill(
102+
f'("{value.name}", [{var_list_string}])',
103+
80,
104+
initial_indent=' ',
105+
subsequent_indent=' '))
106+
return_string=',\n\n'.join(map_entries)
107+
return_string=f""" Data.Map.fromList
108+
[
109+
{return_string}
110+
]"""
111+
returnf"""{VAR_FILE_HEADER}\n\n
112+
-- Last Generated:{datetime.datetime.now().strftime("%x")}
113+
import qualified Data.Map
114+
{PORTAGE_AUTO_VAR_NAME} =
115+
{return_string}"""
116+
defmain(argv):
117+
eclasses= {}
118+
forpathinsorted(argv,key=os.path.basename):
119+
ifnotpath.endswith('.eclass'):
120+
continue
121+
new_eclass=process_file(path)
122+
eclasses[new_eclass.name]=new_eclass
123+
eclasses_list= [
124+
value.calculate_eclass_vars(eclasses)forkey,valueineclasses.items()
125+
]
126+
print(format_eclasses_as_haskell_map(eclasses_list))
127+
if__name__=='__main__':
128+
sys.exit(main(sys.argv[1:]))

‎portage/get_vars_diff.py‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2020 The ChromiumOS Authors
3+
# All rights reserved.
4+
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are
7+
# met:
8+
9+
# * Redistributions of source code must retain the above copyright
10+
# notice, this list of conditions and the following disclaimer.
11+
# * Redistributions in binary form must reproduce the above
12+
# copyright notice, this list of conditions and the following disclaimer
13+
# in the documentation and/or other materials provided with the
14+
# distribution.
15+
# * Neither the name of Google LLC nor the names of its
16+
# contributors may be used to endorse or promote products derived from
17+
# this software without specific prior written permission.
18+
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
# Binary License Terms
31+
32+
"""Generates diff of vars from get_vars.py and those existing in Data.hs."""
33+
importitertools
34+
frompathlibimportPath
35+
importsubprocess
36+
SCRIPT=Path(__file__).resolve()
37+
THIRD_PARTY=SCRIPT.parent.parent.parent.parent.parent
38+
# List of relative directories in which to find the eclasses.
39+
eclass_rel_dirs= (
40+
THIRD_PARTY/'chromiumos-overlay'/'eclass',
41+
THIRD_PARTY/'portage-stable'/'eclass',
42+
THIRD_PARTY/'eclass-overlay'/'eclass',
43+
)
44+
# Runs get_vars.py with the eclass paths and store the output.
45+
cmd= [SCRIPT.with_name('get_vars.py')]+list(
46+
itertools.chain(*(x.glob('*')forxineclass_rel_dirs)))
47+
new_output=subprocess.check_output(cmd,encoding='utf-8').splitlines()
48+
new= []
49+
forlineinnew_output:
50+
if'--'inline:
51+
new.append(line.strip())
52+
elifnotline.strip():
53+
continue
54+
else:
55+
new+= (line.replace('"','').replace('\n','').split(','))
56+
# Reads the Data.hs relevant area and store the lines.
57+
data_hs=THIRD_PARTY/'shellcheck'/'src'/'ShellCheck'/'Data.hs'
58+
withdata_hs.open('r',encoding='utf-8')asfp:
59+
record=False
60+
old= []
61+
forlineinfp:
62+
ifline.strip()=='-- autotest.eclass declared incorrectly':
63+
break
64+
ifline.strip()=='-- generic ebuilds':
65+
record=True
66+
ifrecord:
67+
if'--'inline:
68+
old.append(line.strip())
69+
elifnotline.strip():
70+
continue
71+
else:
72+
old+=line.replace('"','').replace('\n','').split(',')
73+
# Cleans up empty bits as a result of parsing difficulties.
74+
new= [x.strip()forxinnewifx.strip()]
75+
old= [x.strip()forxinoldifx.strip()]
76+
all_eclasses=set()
77+
old_vars= {}
78+
new_vars= {}
79+
current_eclass=''
80+
foriteminold:
81+
if'--'initem:
82+
# It's an eclass comment line.
83+
current_eclass=item[3:]
84+
all_eclasses.add(current_eclass)
85+
continue
86+
else:
87+
# It's a var, so add it to the dict of the current eclass.
88+
old_vars.setdefault(current_eclass, []).append(item)
89+
foriteminnew:
90+
if'--'initem:
91+
# It's an eclass comment line.
92+
current_eclass=item[3:]
93+
all_eclasses.add(current_eclass)
94+
continue
95+
else:
96+
# It's a var, so add it to the dict of the current eclass.
97+
new_vars.setdefault(current_eclass, []).append(item)
98+
foreclassinsorted(all_eclasses):
99+
ifeclassinold_vars:
100+
ifeclassnotinnew_vars:
101+
# Checks if the entire eclass is removed.
102+
print(f'{eclass} not present in new variables.')
103+
forvarinold_vars[eclass]:
104+
print(f'\t-{var}')
105+
print()
106+
else:
107+
# Eclass isn't removed, so check for added or removed vars.
108+
toprint='\n'.join(
109+
[f'\t-{x}'forxinold_vars[eclass]ifxnotinnew_vars[eclass]]+
110+
[f'\t+{x}'forxinnew_vars[eclass]ifxnotinold_vars[eclass]])
111+
iftoprint:
112+
print(eclass)
113+
print(toprint)
114+
ifeclassinnew_vars:
115+
ifeclassnotinold_vars:
116+
# Checks if entire eclass is new.
117+
print(f'{eclass} added in new variables.')
118+
forvarinnew_vars[eclass]:
119+
print(f'\t+{var}')
120+
print()

‎shellcheck.1.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ not warn at all, as `ksh` supports decimals in arithmetic contexts.
8787

8888
: Specify Bourne shell dialect. Valid values are*sh*,*bash*,*dash* and*ksh*.
8989
The default is to deduce the shell from the file's`shell` directive,
90-
shebang, or`.bash/.bats/.dash/.ksh` extension, in that order.*sh* refers to
91-
POSIX`sh` (not the system's), and will warn of portability issues.
90+
shebang, or`.bash/.bats/.dash/.ksh/.ebuild/.eclass` extension, in that
91+
order.*sh* refers to POSIX`sh` (not the system's), and will warn of
92+
portability issues.
9293

9394
**-S**\*SEVERITY*,\**--severity=***severity*
9495

‎src/ShellCheck/ASTLib.hs‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ import Numeric (showHex)
3636

3737
importTest.QuickCheck
3838

39-
arguments (T_SimpleCommand _ _ (cmd:args))= args
40-
4139
-- Is this a type of loop?
4240
isLoop t=case tof
4341
T_WhileExpression {}->True
@@ -559,11 +557,29 @@ getCommandNameFromExpansion t =
559557
extract (T_Pipeline _ _ [cmd])= getCommandName cmd
560558
extract _=Nothing
561559

560+
-- If a command substitution is a single command, get its argument Tokens.
561+
-- Return an empty list if there are no arguments or the token is not a command substitution.
562+
-- $(date +%s) = ["+%s"]
563+
getArgumentsFromExpansion::Token-> [Token]
564+
getArgumentsFromExpansion t=
565+
case tof
566+
T_DollarExpansion _ [c]-> extract c
567+
T_Backticked _ [c]-> extract c
568+
T_DollarBraceCommandExpansion _ [c]-> extract c
569+
_->[]
570+
where
571+
extract (T_Pipeline _ _ [cmd])= arguments cmd
572+
extract _=[]
573+
562574
-- Get the basename of a token representing a command
563575
getCommandBasename=fmap basename. getCommandName
564576

565577
basename=reverse.takeWhile (/='/').reverse
566578

579+
-- Get the arguments to a command
580+
arguments (T_SimpleCommand _ _ (cmd:args))= args
581+
arguments t=maybe[] arguments (getCommand t)
582+
567583
isAssignment t=
568584
case tof
569585
T_Redirecting _ _ w-> isAssignment w

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp