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
04227395
Commit
04227395
authored
6 years ago
by
Benjamin Schubert
Browse files
Options
Downloads
Patches
Plain Diff
Make sorting dependencies non recursive
parent
022a59f0
Branches
Branches containing commit
Tags
Tags containing commit
Loading
Pipeline
#47223676
passed
6 years ago
Stage: test
Stage: post
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
buildstream/_loader/loadelement.py
+1
-0
1 addition, 0 deletions
buildstream/_loader/loadelement.py
buildstream/_loader/loader.py
+26
-29
26 additions, 29 deletions
buildstream/_loader/loader.py
with
27 additions
and
29 deletions
buildstream/_loader/loadelement.py
+
1
−
0
View file @
04227395
...
...
@@ -69,6 +69,7 @@ class LoadElement():
self
.
full_name
=
None
# The element full name (with associated junction)
self
.
deps
=
None
# The list of Dependency objects
self
.
node_id
=
next
(
self
.
_counter
)
self
.
has_sorted_dependencies
=
False
# Whether the element had his dependencies sorted already
#
# Private members
...
...
This diff is collapsed.
Click to expand it.
buildstream/_loader/loader.py
+
26
−
29
View file @
04227395
...
...
@@ -19,6 +19,7 @@
import
os
from
functools
import
cmp_to_key
from
collections
import
deque
from
collections.abc
import
Mapping
import
tempfile
import
shutil
...
...
@@ -144,20 +145,12 @@ class Loader():
self
.
_check_circular_deps
(
dummy_target
)
profile_end
(
Topics
.
CIRCULAR_CHECK
,
profile_key
)
ret
=
[]
#
# Sort direct dependencies of elements by their dependency ordering
#
for
element
in
target_elements
:
loader
=
element
.
_loader
profile_start
(
Topics
.
SORT_DEPENDENCIES
,
element
.
name
)
loader
.
_sort_dependencies
(
element
)
profile_end
(
Topics
.
SORT_DEPENDENCIES
,
element
.
name
)
# Finally, wrap what we have into LoadElements and return the target
#
ret
.
append
(
loader
.
_collect_element
(
element
))
self
.
_sort_dependencies
(
target_elements
)
return
ret
return
[
element
.
_loader
.
_collect_element
(
element
)
for
element
in
target_elements
]
# cleanup():
#
...
...
@@ -337,18 +330,9 @@ class Loader():
# sorts throughout the build process.
#
# Args:
# element (LoadElement): The element to sort
# element (
list[
LoadElement
]
): The element
s
to sort
#
def
_sort_dependencies
(
self
,
element
,
visited
=
None
):
if
visited
is
None
:
visited
=
set
()
if
element
in
visited
:
return
for
dep
in
element
.
dependencies
:
dep
.
element
.
_loader
.
_sort_dependencies
(
dep
.
element
,
visited
=
visited
)
def
_sort_dependencies
(
self
,
elements
):
def
dependency_cmp
(
dep_a
,
dep_b
):
element_a
=
dep_a
.
element
element_b
=
dep_b
.
element
...
...
@@ -388,12 +372,25 @@ class Loader():
# This wont ever happen
return
0
# Now dependency sort, we ensure that if any direct dependency
# directly or indirectly depends on another direct dependency,
# it is found later in the list.
element
.
dependencies
.
sort
(
key
=
cmp_to_key
(
dependency_cmp
))
elements_to_treat
=
deque
(
elements
)
sort_key
=
cmp_to_key
(
dependency_cmp
)
profile_start
(
Topics
.
SORT_DEPENDENCIES
,
"
_
"
.
join
(
e
.
name
.
replace
(
os
.
sep
,
'
-
'
)
for
e
in
elements
))
while
elements_to_treat
:
elem
=
elements_to_treat
.
pop
()
if
elem
.
has_sorted_dependencies
:
continue
elem
.
dependencies
.
sort
(
key
=
sort_key
)
elements_to_treat
.
extend
(
dep
.
element
for
dep
in
elem
.
dependencies
if
not
dep
.
element
.
has_sorted_dependencies
)
elem
.
has_sorted_dependencies
=
True
visited
.
add
(
element
)
profile_end
(
Topics
.
SORT_DEPENDENCIES
,
"
_
"
.
join
(
e
.
name
.
replace
(
os
.
sep
,
'
-
'
)
for
e
in
element
s
)
)
# _collect_element()
#
...
...
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