2021-10-26 01:51:48 +02:00
|
|
|
// Copyright 2021 Google LLC
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package compliance
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SourceSharePrivacyConflict describes an individual conflict between a source-sharing
|
|
|
|
// condition and a source privacy condition
|
|
|
|
type SourceSharePrivacyConflict struct {
|
|
|
|
SourceNode *TargetNode
|
|
|
|
ShareCondition LicenseCondition
|
|
|
|
PrivacyCondition LicenseCondition
|
|
|
|
}
|
|
|
|
|
|
|
|
// Error returns a string describing the conflict.
|
|
|
|
func (conflict SourceSharePrivacyConflict) Error() string {
|
2022-01-10 22:50:57 +01:00
|
|
|
return fmt.Sprintf("%s %s and must share from %s condition\n", conflict.SourceNode.name,
|
|
|
|
conflict.PrivacyCondition.Name(), conflict.ShareCondition.Name())
|
2021-10-26 01:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsEqualTo returns true when `conflict` and `other` describe the same conflict.
|
|
|
|
func (conflict SourceSharePrivacyConflict) IsEqualTo(other SourceSharePrivacyConflict) bool {
|
|
|
|
return conflict.SourceNode.name == other.SourceNode.name &&
|
2022-01-10 22:50:57 +01:00
|
|
|
conflict.ShareCondition == other.ShareCondition &&
|
|
|
|
conflict.PrivacyCondition == other.PrivacyCondition
|
2021-10-26 01:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConflictingSharedPrivateSource lists all of the targets where conflicting conditions to
|
|
|
|
// share the source and to keep the source private apply to the target.
|
|
|
|
func ConflictingSharedPrivateSource(lg *LicenseGraph) []SourceSharePrivacyConflict {
|
|
|
|
|
2022-01-10 22:50:57 +01:00
|
|
|
ResolveTopDownConditions(lg)
|
2021-10-26 01:51:48 +02:00
|
|
|
// combined is the combination of source-sharing and source privacy.
|
2022-01-10 22:50:57 +01:00
|
|
|
combined := WalkActionsForCondition(lg, ImpliesShared.Union(ImpliesPrivate))
|
2021-10-26 01:51:48 +02:00
|
|
|
|
|
|
|
// size is the size of the result
|
|
|
|
size := 0
|
2022-09-22 04:36:59 +02:00
|
|
|
for actsOn, cs := range combined {
|
|
|
|
if actsOn.pure && !actsOn.LicenseConditions().MatchesAnySet(ImpliesShared) {
|
|
|
|
// no need to share code to build "a distribution medium"
|
|
|
|
continue
|
|
|
|
}
|
2022-01-10 22:50:57 +01:00
|
|
|
size += cs.Intersection(ImpliesShared).Len() * cs.Intersection(ImpliesPrivate).Len()
|
2021-10-26 01:51:48 +02:00
|
|
|
}
|
|
|
|
if size == 0 {
|
2022-01-10 22:50:57 +01:00
|
|
|
return nil
|
2021-10-26 01:51:48 +02:00
|
|
|
}
|
|
|
|
result := make([]SourceSharePrivacyConflict, 0, size)
|
2022-01-10 22:50:57 +01:00
|
|
|
for actsOn, cs := range combined {
|
2022-09-22 04:36:59 +02:00
|
|
|
if actsOn.pure { // no need to share code for "a distribution medium"
|
|
|
|
continue
|
|
|
|
}
|
2022-01-10 22:50:57 +01:00
|
|
|
pconditions := cs.Intersection(ImpliesPrivate).AsList()
|
|
|
|
ssconditions := cs.Intersection(ImpliesShared).AsList()
|
2021-10-26 01:51:48 +02:00
|
|
|
|
|
|
|
// report all conflicting condition combinations
|
|
|
|
for _, p := range pconditions {
|
|
|
|
for _, ss := range ssconditions {
|
|
|
|
result = append(result, SourceSharePrivacyConflict{actsOn, ss, p})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|