FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/go/gen.py at codeql-cli/v2.19.1 · github/codeql · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10k
Code
Issues
998
Pull requests
467
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
go
/
gen.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (51 loc) · 2.23 KB
Breadcrumbs
codeql
/
go
/
gen.py
Copy path
File metadata and controls
66 lines (51 loc) · 2.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Update generated files related to Go in the repo. Using --force will regenerate all files from scratch.
In particular the script will:
1. update the `vendor` dir with `go mod vendor` (using a go toolchain provided by bazel)
2. update `BUILD.bazel` files using gazelle
3. update `ql/lib/go.dbscheme` using a compiled `go-dbschemegen`
"""
import
sys
import
pathlib
import
subprocess
import
os
import
argparse
import
shutil
from
python
.
runfiles
import
runfiles
def
options
():
p
=
argparse
.
ArgumentParser
(
description
=
"Update generated files related to Go in the repo"
)
p
.
add_argument
(
"--force"
,
"-f"
,
action
=
"store_true"
,
help
=
"Regenerate all files from scratch rather than updating them"
)
p
.
add_argument
(
"executables"
,
nargs
=
3
,
help
=
"Internally provided executables"
)
return
p
.
parse_args
()
opts
=
options
()
try
:
workspace_dir
=
pathlib
.
Path
(
os
.
environ
[
'BUILD_WORKSPACE_DIRECTORY'
])
except
KeyError
:
print
(
"this should be run with bazel run"
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
go_extractor_dir
=
workspace_dir
/
"go"
/
"extractor"
if
not
go_extractor_dir
.
exists
():
# internal repo?
workspace_dir
/=
"ql"
go_extractor_dir
=
workspace_dir
/
"go"
/
"extractor"
go_dbscheme
=
workspace_dir
/
"go"
/
"ql"
/
"lib"
/
"go.dbscheme"
r
=
runfiles
.
Create
()
go
,
gazelle
,
go_gen_dbscheme
=
map
(
r
.
Rlocation
,
opts
.
executables
)
existing_build_files
=
set
(
go_extractor_dir
.
glob
(
"*/**/BUILD.bazel"
))
if
opts
.
force
:
print
(
"clearing generated BUILD files"
)
for
build_file
in
existing_build_files
:
build_file
.
unlink
()
print
(
"running gazelle"
,
gazelle
,
go_extractor_dir
)
subprocess
.
check_call
([
gazelle
,
"go/extractor"
],
cwd
=
workspace_dir
)
# we want to stamp all newly generated `BUILD.bazel` files with a header
build_files_to_update
=
set
(
go_extractor_dir
.
glob
(
"*/**/BUILD.bazel"
))
# if --force, all files are new
if
not
opts
.
force
:
# otherwise, subtract the files that existed at the start
build_files_to_update
-=
existing_build_files
print
(
"adding header to newly generated BUILD files"
)
for
build_file
in
build_files_to_update
:
contents
=
build_file
.
read_text
()
build_file
.
write_text
(
f"# generated running `bazel run //go/gazelle`, do not edit
\n
\n
{
contents
}
"
)
subprocess
.
check_call
([
go_gen_dbscheme
,
go_dbscheme
])
Back
|
FazBrowse Home
|
New Git URL