| # Copyright 2018 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. |
| """Recipe for building FFmpeg and uploading it and required source files.""" |
| |
| from PB.recipes.fuchsia.contrib.ffmpeg import InputProperties |
| |
| PYTHON_VERSION_COMPATIBILITY = "PY3" |
| |
| DEPS = [ |
| "fuchsia/build", |
| "fuchsia/buildbucket_util", |
| "fuchsia/checkout", |
| "fuchsia/cipd_util", |
| "recipe_engine/context", |
| "recipe_engine/file", |
| "recipe_engine/path", |
| "recipe_engine/properties", |
| "recipe_engine/step", |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| # Patterns of source code to include in the archive that this recipe produces. |
| # All relative to third_party/ffmpeg. |
| SOURCE_PATTERNS = ["fuchsia/config/**/*", "lib*/*.h"] |
| |
| |
| def RunSteps(api, props): |
| checkout = api.checkout.fuchsia_with_options( |
| manifest=props.manifest, |
| remote=props.remote, |
| ) |
| |
| staging_dir = api.path.mkdtemp("ffmpeg") |
| pkg_dir = staging_dir.join("root") |
| prebuilt_variants = set() |
| |
| # Build and archive for all targets before uploading any to avoid an |
| # incomplete upload. |
| for build in props.builds: |
| with api.step.nest(build.target): |
| build_results = api.build.with_options( |
| checkout=checkout, fint_params_path=build.fint_params_path |
| ) |
| with api.context(infra_steps=True): |
| shared_build_dir = build_results.build_dir.join( |
| "%s-novariant-shared" % build.target |
| ) |
| lib_dir = pkg_dir.join("arch", build.target, "lib") |
| api.file.ensure_directory("create lib dir", lib_dir) |
| api.file.copy( |
| "copy libffmpeg.so", shared_build_dir.join("libffmpeg.so"), lib_dir |
| ) |
| debug_dir = pkg_dir.join("arch", build.target, "debug") |
| api.file.ensure_directory("create debug dir", debug_dir) |
| api.file.copy( |
| "copy libffmpeg.so (debug)", |
| shared_build_dir.join("lib.unstripped", "libffmpeg.so"), |
| debug_dir, |
| ) |
| |
| for variant in build_results.set_metadata.variants: |
| prebuilt_variants.add(variant) |
| with api.step.nest(variant): |
| shared_variant_build_dir = build_results.build_dir.join( |
| "%s-%s-shared" % (build.target, variant) |
| ) |
| lib_variant_dir = lib_dir.join(variant) |
| api.file.ensure_directory("create lib dir", lib_variant_dir) |
| api.file.copy( |
| "copy libffmpeg.so", |
| shared_variant_build_dir.join("libffmpeg.so"), |
| lib_variant_dir, |
| ) |
| debug_variant_dir = debug_dir.join(variant) |
| api.file.ensure_directory("create debug dir", debug_variant_dir) |
| api.file.copy( |
| "copy libffmpeg.so (debug)", |
| shared_variant_build_dir.join( |
| "lib.unstripped", "libffmpeg.so" |
| ), |
| debug_variant_dir, |
| ) |
| |
| ffmpeg_dir = checkout.root_dir.join("third_party", "ffmpeg") |
| api.step( |
| "copy files", |
| cmd=[ |
| "python", |
| "-u", |
| api.resource("copy_files.py"), |
| ffmpeg_dir, |
| pkg_dir.join("pkg", "ffmpeg", "include"), |
| ] |
| + SOURCE_PATTERNS, |
| ) |
| docs_dir = pkg_dir.join("pkg", "ffmpeg", "docs") |
| api.file.ensure_directory("create docs dir", docs_dir) |
| api.file.copy( |
| "copy license", ffmpeg_dir.join("LICENSE.md"), docs_dir.join("LICENSE.md") |
| ) |
| |
| # Create prebuilt_variants.json that includes a list of prebuilt variants. |
| prebuilt_variants_dest = pkg_dir.join("prebuilt_variants.json") |
| api.file.write_json( |
| "create prebuilt_variants.json", |
| prebuilt_variants_dest, |
| {"prebuilt_variants": sorted(prebuilt_variants)}, |
| ) |
| |
| if api.buildbucket_util.is_tryjob: |
| return |
| |
| with api.context(infra_steps=True): |
| project = checkout.project("integration") |
| |
| api.cipd_util.upload_package( |
| "fuchsia/lib/ffmpeg/fuchsia", |
| pkg_dir, |
| search_tag={"git_revision": project["revision"]}, |
| repository=project["remote"], |
| ) |
| |
| |
| def GenTests(api): |
| def properties(): |
| return api.properties( |
| manifest="third_party/ffmpeg", |
| remote="https://fuchsia.googlesource.com/integration", |
| builds=[ |
| { |
| "target": "arm64", |
| "fint_params_path": "fint_params/ffmpeg-arm64.textproto", |
| }, |
| { |
| "target": "x64", |
| "fint_params_path": "fint_params/ffmpeg-x64.textproto", |
| }, |
| ], |
| ) |
| |
| yield ( |
| api.buildbucket_util.test("default", repo="third_party/ffmpeg") + properties() |
| ) |
| yield ( |
| api.buildbucket_util.test("cq", tryjob=True, repo="third_party/ffmpeg") |
| + properties() |
| ) |