Skip to content

Commit

Permalink
[engine] Add support for vendor_path
Browse files Browse the repository at this point in the history
Confirmed that the digest is enforced for vendored packages. While the
version is required, it is effectively ignored.

Change-Id: I96df2b906920d6d0bd681d2c1b1ef36a66bdefb5
Reviewed-on: https://fuchsia-review.googlesource.com/c/shac-project/shac/+/912874
Reviewed-by: Oliver Newman <olivernewman@google.com>
Fuchsia-Auto-Submit: Marc-Antoine Ruel <maruel@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
  • Loading branch information
Marc-Antoine Ruel authored and CQ Bot committed Sep 8, 2023
1 parent 40d47c5 commit 69fcc69
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 5 deletions.
1 change: 0 additions & 1 deletion internal/engine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func (doc *Document) Validate() error {
if path.Clean(doc.VendorPath) != doc.VendorPath {
return fmt.Errorf("vendor_path %s is not clean", doc.VendorPath)
}
return errors.New("vendor_path is not yet supported")
}
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/engine/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ func TestDocument_Validate(t *testing.T) {
"vendor_path: \"\"\n",
"",
},
{
"vendor_path: \"foo\"\n",
"",
},
{
"min_shac_version: \"1000\"\n",
func() string {
Expand All @@ -274,10 +278,6 @@ func TestDocument_Validate(t *testing.T) {
"vendor_path: \"foo/../bar\"\n",
"vendor_path foo/../bar is not clean",
},
{
"vendor_path: \"foo\"\n",
"vendor_path is not yet supported",
},
{
"requirements {\n" +
" indirect {\n" +
Expand Down
24 changes: 24 additions & 0 deletions internal/engine/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,30 @@ func (p *PackageManager) RetrievePackages(ctx context.Context, root string, doc
depslists = [][]*Dependency{doc.Requirements.Direct, doc.Requirements.Indirect}
}

if doc.VendorPath != "" {
// Use the vendored versions.
vendorRoot := filepath.Join(root, doc.VendorPath)
for _, deps := range depslists {
// Do it serially for now, decided if parallelism helps performance later.
for _, d := range deps {
// url is believed to be vetted at this point.
dir := filepath.Join(vendorRoot, d.Url)
if err := isDir(dir); err != nil {
return packages, fmt.Errorf("vendored %w", err)
}
f, err := p.verifyDir(dir, d.Url, d.Version, doc.Sum.Digest(d.Url, d.Version))
if err != nil {
return packages, fmt.Errorf("%s couldn't be fetched: %w", d.Url, err)
}
packages[d.Url] = f
if d.Alias != "" {
packages[d.Alias] = f
}
}
}
return packages, nil
}

eg, ctx := errgroup.WithContext(ctx)
eg.SetLimit(pkgConcurrency)
for _, deps := range depslists {
Expand Down
4 changes: 4 additions & 0 deletions internal/engine/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,10 @@ func TestRun_FilesystemSandbox(t *testing.T) {
testStarlarkPrint(t, root, "ctx-os-exec-filesystem_sandbox.star", false, want)
}

func TestRun_Vendored(t *testing.T) {
testStarlarkPrint(t, "testdata/vendored", "shac.star", false, "[//shac.star:17] True\n")
}

// Utilities

// testStarlarkPrint test a starlark file that calls print().
Expand Down
17 changes: 17 additions & 0 deletions internal/engine/testdata/vendored/shac.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 The Shac Authors
#
# 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.

load("@example.com/foo//pkg.star", "Awesomeness")

print(Awesomeness)
32 changes: 32 additions & 0 deletions internal/engine/testdata/vendored/shac.textproto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2023 The Shac Authors
#
# 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.

min_shac_version: "0.0.0"
allow_network: False
vendor_path: "vendor"
requirements {
direct {
url: "example.com/foo"
version: "unspecified"
}
}
sum {
known {
url: "example.com/foo"
seen {
version: "unspecified"
digest: "h1:mMeUDgNiVbXSAAycH71G2ZqOgTMRe5ujBGSSymGUlj0="
}
}
}
16 changes: 16 additions & 0 deletions internal/engine/testdata/vendored/vendor/example.com/foo/pkg.star

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions shac.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ allow_network: False
ignore: "/vendor/"
# Vendored code for test data only.
ignore: "/internal/engine/testdata/ut/"
ignore: "/internal/engine/testdata/vendored/"
# TODO(olivernewman): Make root non-writable once we can use caches and
# pass-throughs to avoid having checks install tools and do Go builds within the
# checkout directory.
Expand Down

0 comments on commit 69fcc69

Please sign in to comment.