| # Copyright 2022 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| from PB.recipes.fuchsia.contrib.winsdk import InputProperties |
| |
| DEPS = [ |
| "fuchsia/cipd_util", |
| "fuchsia/docker", |
| "fuchsia/gitiles", |
| "fuchsia/status_check", |
| "recipe_engine/cipd", |
| "recipe_engine/context", |
| "recipe_engine/file", |
| "recipe_engine/path", |
| "recipe_engine/platform", |
| "recipe_engine/properties", |
| "recipe_engine/step", |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| # TODO(fxbug.dev/99600): Replace it with CIPD prebuilt once we build this script and upload it to CIPD. |
| WINSDK_REPO = "fuchsia.googlesource.com" |
| WINSDK_PROJECT = "fuchsia" |
| WINSDK_REF = "refs/heads/main" |
| WINSDK_PATH = "tools/winsdk/winsdk.go" |
| |
| |
| def RunSteps(api, props): |
| # This recipe only works under windows. |
| if not api.platform.is_win: |
| raise api.step.InfraFailure("This recipe only works on windows") |
| |
| winsdk_temp_dir = api.path.mkdtemp("windsdk_docker") |
| api.file.ensure_directory("ensure working directory", winsdk_temp_dir) |
| api.file.copy( |
| "copy dockerfile", |
| api.resource("Dockerfile"), |
| winsdk_temp_dir.join("Dockerfile"), |
| ) |
| # Logging wrapper from MS. Though we don't keep these logs |
| # but docker build will fail with error code 3010 if this |
| # wrapper is not used. |
| api.file.copy( |
| "copy install.cmd", |
| api.resource("Install.cmd"), |
| winsdk_temp_dir.join("Install.cmd"), |
| ) |
| |
| # Fetch winsdk packer tool from CIPD |
| pkgs = api.cipd.EnsureFile() |
| pkgs.add_package("infra/3pp/tools/go/windows-amd64", "latest") |
| api.cipd.ensure(winsdk_temp_dir, pkgs) |
| script_data = api.gitiles.fetch( |
| host=WINSDK_REPO, |
| project=WINSDK_PROJECT, |
| path=WINSDK_PATH, |
| ref=WINSDK_REF, |
| step_name="fetch winsdk script", |
| default_test_data="", |
| ) |
| api.file.write_raw( |
| "write winsdk script file", winsdk_temp_dir.join("winsdk.go"), script_data |
| ) |
| |
| api.step( |
| "build winsdk script", |
| [ |
| winsdk_temp_dir.join("bin", "go.exe"), |
| "build", |
| "-o", |
| winsdk_temp_dir.join("winsdk.exe"), |
| winsdk_temp_dir.join("winsdk.go"), |
| ], |
| ) |
| |
| with api.context(cwd=winsdk_temp_dir): |
| api.docker.build( |
| dockerfile=winsdk_temp_dir.join("Dockerfile"), |
| tags=["vs2022"], |
| docker_args=[ |
| "-m", |
| "2GB", |
| ], |
| ) |
| |
| api.docker.run( |
| image="vs2022:latest", |
| cmd_args=[ |
| "C:\\TEMP\\winsdk\\winsdk.exe", |
| "--dryrun" if props.dry_run else "--output=C:\\TEMP\\winsdk\\winsdk", |
| ], |
| dir_mapping=[(winsdk_temp_dir, "C:\\TEMP\\winsdk")], |
| step_name="pack winsdk", |
| ) |
| api.docker.cleanup() |
| |
| if not props.dry_run: |
| sdk_dir = winsdk_temp_dir.join("winsdk") |
| lockfile = api.file.read_json( |
| name="read lockfile", |
| source=sdk_dir.join("content.lock"), |
| test_data={ |
| "updated": "2022-07-22T15:30:52.3133295-07:00", |
| "hash": "3bf53ee8f76154537b0903095a7c402de0c67d8a58f85a2105113460db491a73", |
| }, |
| ) |
| api.cipd_util.upload_package( |
| props.cipd_path, |
| sdk_dir, |
| search_tag={"lock_hash": lockfile["hash"]}, |
| metadata=[("updated", lockfile["updated"])], |
| ) |
| |
| |
| def GenTests(api): |
| default_properties = api.properties( |
| dry_run=False, |
| cipd_path="fuchsia/test/winsdk", |
| ) |
| dryrun_properties = api.properties( |
| dry_run=True, |
| ) |
| yield api.status_check.test("default", status="infra_failure") + default_properties |
| yield api.status_check.test("win_x64") + default_properties + api.platform.name( |
| "win" |
| ) |
| yield api.status_check.test( |
| "win_x64_dry_run" |
| ) + dryrun_properties + api.platform.name("win") |