Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
codeql/misc/bazel/lfs.bzl at main · github/codeql · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
github
codeql
Repository navigation
Code
Issues
1k
(1k)
Pull requests
486
(486)
Discussions
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
codeql
/
misc
/
bazel
/
lfs.bzl
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
135 lines (122 loc) · 6.16 KB
main
Breadcrumbs
codeql
/
misc
/
bazel
/
lfs.bzl
Copy path
Top
File metadata and controls
Code
Blame
135 lines (122 loc) · 6.16 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def
lfs_smudge
(
repository_ctx
,
srcs
,
*
,
extract
=
False
,
stripPrefix
=
None
,
executable
=
False
):
python
=
repository_ctx
.
which
(
"python3"
)
or
repository_ctx
.
which
(
"python"
)
if
not
python
:
fail
(
"Neither python3 nor python executables found"
)
script
=
Label
(
"//misc/bazel/internal:git_lfs_probe.py"
)
def
probe
(
srcs
,
hash_only
=
False
):
repository_ctx
.
report_progress
(
"querying LFS url(s) for: %s"
%
", "
.
join
([
src
.
basename
for
src
in
srcs
]))
cmd
=
[
python
,
script
]
if
hash_only
:
cmd
.
append
(
"--hash-only"
)
cmd
.
extend
(
srcs
)
res
=
repository_ctx
.
execute
(
cmd
,
quiet
=
True
)
if
res
.
return_code
!=
0
:
fail
(
"git LFS probing failed while instantiating @%s:
\n
%s"
%
(
repository_ctx
.
name
,
res
.
stderr
))
return
res
.
stdout
.
splitlines
()
for
src
in
srcs
:
repository_ctx
.
watch
(
src
)
infos
=
probe
(
srcs
,
hash_only
=
True
)
remote
=
[]
for
src
,
info
in
zip
(
srcs
,
infos
):
if
info
==
"local"
:
repository_ctx
.
report_progress
(
"symlinking local %s"
%
src
.
basename
)
repository_ctx
.
symlink
(
src
,
src
.
basename
)
else
:
repository_ctx
.
report_progress
(
"trying cache for remote %s"
%
src
.
basename
)
res
=
repository_ctx
.
download
([],
src
.
basename
,
sha256
=
info
,
allow_fail
=
True
,
executable
=
executable
)
if
not
res
.
success
:
remote
.
append
(
src
)
if
remote
:
infos
=
probe
(
remote
)
for
src
,
info
in
zip
(
remote
,
infos
):
sha256
,
_
,
url
=
info
.
partition
(
" "
)
repository_ctx
.
report_progress
(
"downloading remote %s"
%
src
.
basename
)
repository_ctx
.
download
(
url
,
src
.
basename
,
sha256
=
sha256
,
executable
=
executable
)
if
extract
:
for
src
in
srcs
:
repository_ctx
.
report_progress
(
"extracting %s"
%
src
.
basename
)
repository_ctx
.
extract
(
src
.
basename
,
stripPrefix
=
stripPrefix
)
repository_ctx
.
delete
(
src
.
basename
)
def
_add_build_file
(
repository_ctx
):
attr
=
repository_ctx
.
attr
if
attr
.
build_file_content
and
attr
.
build_file
:
fail
(
"You should specify only one among build_file_content and build_file for rule @%s"
%
repository_ctx
.
name
)
if
attr
.
build_file_content
:
repository_ctx
.
file
(
"BUILD.bazel"
,
attr
.
build_file_content
)
elif
attr
.
build_file
:
repository_ctx
.
symlink
(
attr
.
build_file
,
"BUILD.bazel"
)
def
_download_and_extract_lfs_archive
(
repository_ctx
):
attr
=
repository_ctx
.
attr
lfs_smudge
(
repository_ctx
, [
repository_ctx
.
path
(
attr
.
src
)],
extract
=
True
,
stripPrefix
=
attr
.
strip_prefix
)
_add_build_file
(
repository_ctx
)
def
_download_and_extract_lfs_archives
(
repository_ctx
):
for
src
in
repository_ctx
.
attr
.
srcs
:
lfs_smudge
(
repository_ctx
,
[
repository_ctx
.
path
(
src
)],
extract
=
True
,
stripPrefix
=
repository_ctx
.
attr
.
strip_prefix
,
)
_add_build_file
(
repository_ctx
)
def
_download_lfs
(
repository_ctx
):
attr
=
repository_ctx
.
attr
if
int
(
bool
(
attr
.
srcs
))
+
int
(
bool
(
attr
.
dir
))
!=
1
:
fail
(
"Exactly one between `srcs` and `dir` must be defined for @%s"
%
repository_ctx
.
name
)
if
attr
.
srcs
:
srcs
=
[
repository_ctx
.
path
(
src
)
for
src
in
attr
.
srcs
]
else
:
dir
=
repository_ctx
.
path
(
attr
.
dir
)
if
not
dir
.
is_dir
:
fail
(
"`dir` not a directory in @%s"
%
repository_ctx
.
name
)
srcs
=
[
f
for
f
in
dir
.
readdir
()
if
not
f
.
is_dir
]
lfs_smudge
(
repository_ctx
,
srcs
,
executable
=
repository_ctx
.
attr
.
executable
)
# with bzlmod the name is qualified with `+` separators, and we want the base name here
name
=
repository_ctx
.
name
.
split
(
"+"
)[
-
1
]
basenames
=
[
src
.
basename
for
src
in
srcs
]
build
=
"exports_files(%s)
\n
"
%
repr
(
basenames
)
# add a main `name` filegroup only if it doesn't conflict with existing exported files
if
name
not
in
basenames
:
build
+=
'filegroup(name = "%s", srcs = %s, visibility = ["//visibility:public"])
\n
'
%
(
name
,
basenames
,
)
repository_ctx
.
file
(
"BUILD.bazel"
,
build
)
# this is for drop-in compatibility with `http_file`
repository_ctx
.
file
(
"file/BUILD.bazel"
,
'alias(name = "file", actual = "//:%s", visibility = ["//visibility:public"])
\n
'
%
name
,
)
_lfs_archive_attrs
=
{
"build_file"
:
attr
.
label
(
doc
=
"The file to use as the BUILD file for this repository. "
+
"Either build_file or build_file_content can be specified, but not both."
),
"build_file_content"
:
attr
.
string
(
doc
=
"The content for the BUILD file for this repository. "
+
"Either build_file or build_file_content can be specified, but not both."
),
"strip_prefix"
:
attr
.
string
(
default
=
""
,
doc
=
"A directory prefix to strip from the extracted files."
),
}
lfs_archive
=
repository_rule
(
doc
=
"Export the contents from an on-demand LFS archive. The corresponding path should be added to be ignored "
+
"in `.lfsconfig`."
,
implementation
=
_download_and_extract_lfs_archive
,
attrs
=
{
"src"
:
attr
.
label
(
mandatory
=
True
,
doc
=
"Local path to the LFS archive to extract."
),
}
|
_lfs_archive_attrs
,
)
lfs_archives
=
repository_rule
(
doc
=
"Overlay the contents from on-demand LFS archives. The corresponding paths should be added to be ignored "
+
"in `.lfsconfig`."
,
implementation
=
_download_and_extract_lfs_archives
,
attrs
=
{
"srcs"
:
attr
.
label_list
(
doc
=
"Local paths to the LFS archives to extract in order."
,
mandatory
=
True
),
}
|
_lfs_archive_attrs
,
)
lfs_files
=
repository_rule
(
doc
=
"Export LFS files for on-demand download. Exactly one between `srcs` and `dir` must be defined. The "
+
"corresponding paths should be added to be ignored in `.lfsconfig`."
,
implementation
=
_download_lfs
,
attrs
=
{
"srcs"
:
attr
.
label_list
(
doc
=
"Local paths to the LFS files to export."
),
"dir"
:
attr
.
label
(
doc
=
"Local path to a directory containing LFS files to export. Only the direct contents "
+
"of the directory are exported"
),
"executable"
:
attr
.
bool
(
doc
=
"Whether files should be marked as executable"
),
},
)
You can’t perform that action at this time.