Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
buildstream
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
BuildStream
buildstream
Commits
b37d79c3
Commit
b37d79c3
authored
6 years ago
by
Phil Dawson
Browse files
Options
Downloads
Patches
Plain Diff
Add --force / -f option to source-checkout command
parent
c4718b60
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
buildstream/_frontend/cli.py
+4
-1
4 additions, 1 deletion
buildstream/_frontend/cli.py
buildstream/_stream.py
+7
-6
7 additions, 6 deletions
buildstream/_stream.py
tests/frontend/source_checkout.py
+17
-0
17 additions, 0 deletions
tests/frontend/source_checkout.py
with
28 additions
and
7 deletions
buildstream/_frontend/cli.py
+
4
−
1
View file @
b37d79c3
...
...
@@ -684,6 +684,8 @@ def checkout(app, element, location, force, deps, integrate, hardlinks, tar):
# Source Checkout Command #
##################################################################
@cli.command
(
name
=
'
source-checkout
'
,
short_help
=
'
Checkout sources for an element
'
)
@click.option
(
'
--force
'
,
'
-f
'
,
default
=
False
,
is_flag
=
True
,
help
=
"
Allow files to be overwritten
"
)
@click.option
(
'
--except
'
,
'
except_
'
,
multiple
=
True
,
type
=
click
.
Path
(
readable
=
False
),
help
=
"
Except certain dependencies
"
)
...
...
@@ -699,12 +701,13 @@ def checkout(app, element, location, force, deps, integrate, hardlinks, tar):
type
=
click
.
Path
(
readable
=
False
))
@click.argument
(
'
location
'
,
type
=
click
.
Path
())
@click.pass_obj
def
source_checkout
(
app
,
element
,
location
,
deps
,
fetch_
,
except_
,
tar
):
def
source_checkout
(
app
,
element
,
location
,
force
,
deps
,
fetch_
,
except_
,
tar
):
"""
Checkout sources of an element to the specified location
"""
with
app
.
initialized
():
app
.
stream
.
source_checkout
(
element
,
location
=
location
,
force
=
force
,
deps
=
deps
,
fetch
=
fetch_
,
except_targets
=
except_
,
...
...
This diff is collapsed.
Click to expand it.
buildstream/_stream.py
+
7
−
6
View file @
b37d79c3
...
...
@@ -449,12 +449,13 @@ class Stream():
#
def
source_checkout
(
self
,
target
,
*
,
location
=
None
,
force
=
False
,
deps
=
'
none
'
,
fetch
=
False
,
except_targets
=
(),
tar
=
False
):
self
.
_check_location_writable
(
location
,
tar
=
tar
)
self
.
_check_location_writable
(
location
,
force
=
force
,
tar
=
tar
)
elements
,
_
=
self
.
_load
((
target
,),
(),
selection
=
deps
,
...
...
@@ -468,7 +469,7 @@ class Stream():
# Stage all sources determined by scope
try
:
self
.
_source_checkout
(
elements
,
location
,
deps
,
fetch
,
tar
)
self
.
_source_checkout
(
elements
,
location
,
force
,
deps
,
fetch
,
tar
)
except
BstError
as
e
:
raise
StreamError
(
"
Error while writing sources
"
"
:
'
{}
'"
.
format
(
e
),
detail
=
e
.
detail
,
reason
=
e
.
reason
)
from
e
...
...
@@ -1189,6 +1190,7 @@ class Stream():
# Helper function for source_checkout()
def
_source_checkout
(
self
,
elements
,
location
=
None
,
force
=
False
,
deps
=
'
none
'
,
fetch
=
False
,
tar
=
False
):
...
...
@@ -1204,7 +1206,7 @@ class Stream():
if
tar
:
self
.
_create_tarball
(
temp_source_dir
.
name
,
location
)
else
:
self
.
_move_directory
(
temp_source_dir
.
name
,
location
)
self
.
_move_directory
(
temp_source_dir
.
name
,
location
,
force
)
except
OSError
as
e
:
raise
StreamError
(
"
Failed to checkout sources to {}: {}
"
.
format
(
location
,
e
))
from
e
...
...
@@ -1212,10 +1214,9 @@ class Stream():
with
suppress
(
FileNotFoundError
):
temp_source_dir
.
cleanup
()
# Move a directory src to dest. This will work across devices and
# may optionaly overwrite existing files.
def
_move_directory
(
self
,
src
,
dest
):
def
_move_directory
(
self
,
src
,
dest
,
force
=
False
):
def
is_empty_dir
(
path
):
return
os
.
path
.
isdir
(
dest
)
and
not
os
.
listdir
(
dest
)
...
...
@@ -1225,7 +1226,7 @@ class Stream():
except
OSError
:
pass
if
is_empty_dir
(
dest
):
if
force
or
is_empty_dir
(
dest
):
try
:
utils
.
link_files
(
src
,
dest
)
except
utils
.
UtilError
as
e
:
...
...
This diff is collapsed.
Click to expand it.
tests/frontend/source_checkout.py
+
17
−
0
View file @
b37d79c3
import
os
import
pytest
import
tarfile
from
pathlib
import
Path
from
tests.testutils
import
cli
...
...
@@ -47,6 +48,22 @@ def test_source_checkout(datafiles, tmpdir_factory, cli, with_workspace):
assert
os
.
path
.
exists
(
os
.
path
.
join
(
checkout
,
'
checkout-deps
'
,
'
etc
'
,
'
buildstream
'
,
'
config
'
))
@pytest.mark.datafiles
(
DATA_DIR
)
@pytest.mark.parametrize
(
'
force_flag
'
,
[
'
--force
'
,
'
-f
'
])
def
test_source_checkout_force
(
datafiles
,
cli
,
force_flag
):
project
=
os
.
path
.
join
(
datafiles
.
dirname
,
datafiles
.
basename
)
checkout
=
os
.
path
.
join
(
cli
.
directory
,
'
source-checkout
'
)
target
=
'
checkout-deps.bst
'
os
.
makedirs
(
os
.
path
.
join
(
checkout
,
'
some-thing
'
))
# Path(os.path.join(checkout, 'some-file')).touch()
result
=
cli
.
run
(
project
=
project
,
args
=
[
'
source-checkout
'
,
force_flag
,
target
,
'
--deps
'
,
'
none
'
,
checkout
])
result
.
assert_success
()
assert
os
.
path
.
exists
(
os
.
path
.
join
(
checkout
,
'
checkout-deps
'
,
'
etc
'
,
'
buildstream
'
,
'
config
'
))
@pytest.mark.datafiles
(
DATA_DIR
)
def
test_source_checkout_tar
(
datafiles
,
cli
):
project
=
os
.
path
.
join
(
datafiles
.
dirname
,
datafiles
.
basename
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment