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
cb44803e
Commit
cb44803e
authored
6 years ago
by
Jürg Billeter
Browse files
Options
Downloads
Patches
Plain Diff
buildelement.py: Support batching for integration and build commands
parent
a60b49b4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
buildstream/buildelement.py
+39
-22
39 additions, 22 deletions
buildstream/buildelement.py
tests/integration/sandbox-bwrap.py
+1
-1
1 addition, 1 deletion
tests/integration/sandbox-bwrap.py
with
40 additions
and
23 deletions
buildstream/buildelement.py
+
39
−
22
View file @
cb44803e
...
...
@@ -127,8 +127,9 @@ artifact collection purposes.
"""
import
os
from
.
import
Element
,
Scope
,
ElementError
from
.
import
Element
,
Scope
from
.
import
SandboxFlags
from
.
import
utils
# This list is preserved because of an unfortunate situation, we
...
...
@@ -207,6 +208,9 @@ class BuildElement(Element):
# Setup environment
sandbox
.
set_environment
(
self
.
get_environment
())
# Active sandbox batch context manager
self
.
__sandbox_batch_cm
=
None
# pylint: disable=attribute-defined-outside-init
def
stage
(
self
,
sandbox
):
# Stage deps in the sandbox root
...
...
@@ -215,7 +219,7 @@ class BuildElement(Element):
# Run any integration commands provided by the dependencies
# once they are all staged and ready
with
s
elf
.
timed_activity
(
"
Integrating sandbox
"
):
with
s
andbox
.
batch
(
0
,
label
=
"
Integrating sandbox
"
):
for
dep
in
self
.
dependencies
(
Scope
.
BUILD
):
dep
.
integrate
(
sandbox
)
...
...
@@ -223,16 +227,24 @@ class BuildElement(Element):
self
.
stage_sources
(
sandbox
,
self
.
get_variable
(
'
build-root
'
))
def
assemble
(
self
,
sandbox
):
# Use the batch context manager from prepare(), if available
batch_cm
=
self
.
__sandbox_batch_cm
self
.
__sandbox_batch_cm
=
None
# pylint: disable=attribute-defined-outside-init
# Run commands
for
command_name
in
_command_steps
:
commands
=
self
.
__commands
[
command_name
]
if
not
commands
or
command_name
==
'
configure-commands
'
:
continue
if
not
batch_cm
:
batch_cm
=
sandbox
.
batch
(
SandboxFlags
.
ROOT_READ_ONLY
,
collect
=
self
.
get_variable
(
'
install-root
'
))
with
batch_cm
:
# Run commands
for
command_name
in
_command_steps
:
commands
=
self
.
__commands
[
command_name
]
if
not
commands
or
command_name
==
'
configure-commands
'
:
continue
with
s
elf
.
timed_activity
(
"
Running {}
"
.
format
(
command_name
)):
for
cmd
in
commands
:
self
.
__run_command
(
sandbox
,
cmd
,
command_name
)
with
s
andbox
.
batch
(
SandboxFlags
.
ROOT_READ_ONLY
,
label
=
"
Running {}
"
.
format
(
command_name
)):
for
cmd
in
commands
:
self
.
__run_command
(
sandbox
,
cmd
,
command_name
)
# %{install-root}/%{build-root} should normally not be written
# to - if an element later attempts to stage to a location
...
...
@@ -252,11 +264,20 @@ class BuildElement(Element):
return
self
.
get_variable
(
'
install-root
'
)
def
prepare
(
self
,
sandbox
):
commands
=
self
.
__commands
[
'
configure-commands
'
]
if
commands
:
with
self
.
timed_activity
(
"
Running configure-commands
"
):
for
cmd
in
commands
:
self
.
__run_command
(
sandbox
,
cmd
,
'
configure-commands
'
)
batch_cm
=
sandbox
.
batch
(
SandboxFlags
.
ROOT_READ_ONLY
,
collect
=
self
.
get_variable
(
'
install-root
'
))
# Allow use of single batch context manager across prepare and assemble
batch_cm
=
utils
.
_SplitContextManager
(
batch_cm
)
with
batch_cm
:
commands
=
self
.
__commands
[
'
configure-commands
'
]
if
commands
:
with
sandbox
.
batch
(
SandboxFlags
.
ROOT_READ_ONLY
,
label
=
"
Running configure-commands
"
):
for
cmd
in
commands
:
self
.
__run_command
(
sandbox
,
cmd
,
'
configure-commands
'
)
self
.
__sandbox_batch_cm
=
batch_cm
# pylint: disable=attribute-defined-outside-init
def
generate_script
(
self
):
script
=
""
...
...
@@ -282,13 +303,9 @@ class BuildElement(Element):
return
commands
def
__run_command
(
self
,
sandbox
,
cmd
,
cmd_name
):
self
.
status
(
"
Running {}
"
.
format
(
cmd_name
),
detail
=
cmd
)
# Note the -e switch to 'sh' means to exit with an error
# if any untested command fails.
#
exitcode
=
sandbox
.
run
([
'
sh
'
,
'
-c
'
,
'
-e
'
,
cmd
+
'
\n
'
],
SandboxFlags
.
ROOT_READ_ONLY
)
if
exitcode
!=
0
:
raise
ElementError
(
"
Command
'
{}
'
failed with exitcode {}
"
.
format
(
cmd
,
exitcode
),
collect
=
self
.
get_variable
(
'
install-root
'
))
sandbox
.
run
([
'
sh
'
,
'
-c
'
,
'
-e
'
,
cmd
+
'
\n
'
],
SandboxFlags
.
ROOT_READ_ONLY
,
label
=
cmd
)
This diff is collapsed.
Click to expand it.
tests/integration/sandbox-bwrap.py
+
1
−
1
View file @
cb44803e
...
...
@@ -58,5 +58,5 @@ def test_sandbox_bwrap_return_subprocess(cli, tmpdir, datafiles):
})
result
=
cli
.
run
(
project
=
project
,
args
=
[
'
build
'
,
element_name
])
result
.
assert_task_error
(
error_domain
=
ErrorDomain
.
ELEMENT
,
error_reason
=
None
)
result
.
assert_task_error
(
error_domain
=
ErrorDomain
.
SANDBOX
,
error_reason
=
"
command-failed
"
)
assert
"
sandbox-bwrap/command-exit-42.bst|Command
'
exit 42
'
failed with exitcode 42
"
in
result
.
stderr
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