Skip to content

Commit 9f278bf

Browse files
authored
feat(internal/config,rust): add ignore field to RustPackageDependency (#3110)
Add support for the ignore codec to prevent a package from being mapped to an external crate.
1 parent d80a685 commit 9f278bf

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

internal/config/language.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ type RustPackageDependency struct {
102102
// Name is the dependency name.
103103
Name string `yaml:"name"`
104104

105+
// Ignore prevents this package from being mapped to an external crate.
106+
// When true, references to this package stay as `crate::` instead of being
107+
// mapped to the external crate name. This is used for self-referencing
108+
// packages like location and longrunning.
109+
Ignore bool `yaml:"ignore,omitempty"`
110+
105111
// Package is the package name.
106112
Package string `yaml:"package"`
107113

internal/librarian/internal/rust/codec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,8 @@ func formatPackageDependency(dep *config.RustPackageDependency) string {
160160
if dep.Feature != "" {
161161
parts = append(parts, "feature="+dep.Feature)
162162
}
163+
if dep.Ignore {
164+
parts = append(parts, "ignore=true")
165+
}
163166
return strings.Join(parts, ",")
164167
}

internal/librarian/internal/rust/codec_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,17 @@ func TestFormatPackageDependency(t *testing.T) {
529529
ForceUsed: true,
530530
UsedIf: "feature = \"async\"",
531531
Feature: "async",
532+
Ignore: true,
532533
},
533-
want: "package=tokio,source=1.0,force-used=true,used-if=feature = \"async\",feature=async",
534+
want: "package=tokio,source=1.0,force-used=true,used-if=feature = \"async\",feature=async,ignore=true",
535+
},
536+
{
537+
name: "with ignore for self-referencing package",
538+
dep: config.RustPackageDependency{
539+
Name: "longrunning",
540+
Ignore: true,
541+
},
542+
want: "ignore=true",
534543
},
535544
} {
536545
t.Run(test.name, func(t *testing.T) {

0 commit comments

Comments
 (0)