1
+ """
2
+ Update generated files related to Go in the repo. Using --force will regenerate all files from scratch.
3
+
4
+ In particular the script will:
5
+ 1. update the `vendor` dir with `go work vendor` (using a go toolchain provided by bazel)
6
+ 2. update `BUILD.bazel` files using gazelle
7
+ 3. update `ql/lib/go.dbscheme` using a compiled `go-dbschemegen`
8
+ """
9
+
1
10
import sys
2
11
import pathlib
3
12
import subprocess
7
16
from python .runfiles import runfiles
8
17
9
18
def options ():
10
- p = argparse .ArgumentParser (description = "Update generated checked in files in the Go pack " )
19
+ p = argparse .ArgumentParser (description = "Update generated files related to Go in the repo " )
11
20
p .add_argument ("--force" , "-f" , action = "store_true" , help = "Regenerate all files from scratch rather than updating them" )
12
- p .add_argument ("generators " , nargs = 3 )
21
+ p .add_argument ("executables " , nargs = 3 , help = "Internally provided executables" )
13
22
return p .parse_args ()
14
23
15
24
opts = options ()
@@ -23,7 +32,7 @@ def options():
23
32
go_extractor_dir = workspace_dir / "go" / "extractor"
24
33
go_dbscheme = workspace_dir / "go" / "ql" / "lib" / "go.dbscheme"
25
34
r = runfiles .Create ()
26
- go , gazelle , go_gen_dbscheme = map (r .Rlocation , opts .generators )
35
+ go , gazelle , go_gen_dbscheme = map (r .Rlocation , opts .executables )
27
36
28
37
29
38
if opts .force :
@@ -43,13 +52,16 @@ def options():
43
52
print ("running gazelle" )
44
53
subprocess .check_call ([gazelle ])
45
54
55
+ # we want to stamp all newly generated `BUILD.bazel` files with a header
46
56
build_files_to_update = set (go_extractor_dir .glob ("*/**/BUILD.bazel" ))
57
+ # if --force, all files are new
47
58
if not opts .force :
59
+ # otherwise, subtract the files that existed at the start
48
60
build_files_to_update -= existing_build_files
49
- # these are always refreshed
61
+ # but bring back the `vendor` ones, as the vendor update step always clears them
50
62
build_files_to_update .update (go_extractor_dir .glob ("vendor/**/BUILD.bazel" ))
51
63
52
- print ("adding header to generated BUILD files" )
64
+ print ("adding header to newly generated BUILD files" )
53
65
for build_file in build_files_to_update :
54
66
contents = build_file .read_text ()
55
67
build_file .write_text (f"# generated running `bazel run //go/gazelle`, do not edit\n \n { contents } " )
0 commit comments