Beispiel #1
0
 def validate(self) -> None:
     if self[PexEntryPointField].value is not None and self[
             PexScriptField].value is not None:
         raise InvalidTargetException(
             f"The `{self.alias}` target {self.address} cannot set both the "
             f"`{self[PexEntryPointField].alias}` and `{self[PexScriptField].alias}` fields at "
             "the same time. To fix, please remove one.")
Beispiel #2
0
 def validate(self) -> None:
     if (self[PythonGoogleCloudFunctionRuntime].value is None
             and not self[PexCompletePlatformsField].value):
         raise InvalidTargetException(
             f"The `{self.alias}` target {self.address} must specify either a "
             f"`{self[PythonGoogleCloudFunctionRuntime].alias}` or "
             f"`{self[PexCompletePlatformsField].alias}` or both.")
Beispiel #3
0
 def validate(self) -> None:
     if not self.address.is_generated_target:
         raise InvalidTargetException(
             f"The `{self.alias}` target type should not be manually created in BUILD "
             f"files, but it was created for {self.address}.\n\n"
             "Instead, add a `go_mod` target where you have your `go.mod` file, which will "
             f"generate `{self.alias}` targets for you.")
Beispiel #4
0
 def validate(self) -> None:
     if (self[PythonRequirementModulesField].value
             and self[PythonRequirementTypeStubModulesField].value):
         raise InvalidTargetException(
             f"The `{self.alias}` target {self.address} cannot set both the "
             f"`{self[PythonRequirementModulesField].alias}` and "
             f"`{self[PythonRequirementTypeStubModulesField].alias}` fields at the same time. "
             "To fix, please remove one.")
Beispiel #5
0
 def validate(self) -> None:
     if self[PythonAwsLambdaRuntime].value is None and not self[PexCompletePlatformsField].value:
         raise InvalidTargetException(
             softwrap(
                 f"""
                 The `{self.alias}` target {self.address} must specify either a
                 `{self[PythonAwsLambdaRuntime].alias}` or
                 `{self[PexCompletePlatformsField].alias}` or both.
                 """
             )
         )
Beispiel #6
0
def _coordinate_from_target(tgt: Target) -> Coordinate:
    group = tgt[JvmArtifactGroupField].value
    if not group:
        raise InvalidTargetException(
            f"The `group` field of {tgt.alias} target {tgt.address} must be set."
        )

    artifact = tgt[JvmArtifactArtifactField].value
    if not artifact:
        raise InvalidTargetException(
            f"The `artifact` field of {tgt.alias} target {tgt.address} must be set."
        )

    version = tgt[JvmArtifactVersionField].value
    if not version:
        raise InvalidTargetException(
            f"The `version` field of {tgt.alias} target {tgt.address} must be set."
        )

    return Coordinate(
        group=group,
        artifact=artifact,
        version=version,
    )
Beispiel #7
0
async def find_nearest_go_mod(request: OwningGoModRequest) -> OwningGoMod:
    # We don't expect `go_mod` targets to be generated, so we can use UnexpandedTargets.
    candidate_targets = await Get(
        UnexpandedTargets,
        AddressSpecs([AscendantAddresses(request.address.spec_path)]))

    # Sort by address.spec_path in descending order so the nearest go_mod target is sorted first.
    go_mod_targets = sorted(
        (tgt for tgt in candidate_targets if tgt.has_field(GoModSourcesField)),
        key=lambda tgt: tgt.address.spec_path,
        reverse=True,
    )
    if not go_mod_targets:
        raise InvalidTargetException(
            f"The target {request.address} does not have a `go_mod` target in its BUILD file or "
            "any ancestor BUILD files. To fix, please make sure your project has a `go.mod` file "
            f"and add a `go_mod` target (you can run `{bin_name()} tailor` to do this)."
        )
    nearest_go_mod_target = go_mod_targets[0]
    return OwningGoMod(nearest_go_mod_target.address)
Beispiel #8
0
async def package_pyoxidizer_binary(
    pyoxidizer: PyOxidizer,
    field_set: PyOxidizerFieldSet,
    runner_script: PyoxidizerRunnerScript,
    bash: BashBinary,
) -> BuiltPackage:
    direct_deps = await Get(Targets,
                            DependenciesRequest(field_set.dependencies))
    deps_field_sets = await Get(
        FieldSetsPerTarget,
        FieldSetsPerTargetRequest(PackageFieldSet, direct_deps))
    built_packages = await MultiGet(
        Get(BuiltPackage, PackageFieldSet, field_set)
        for field_set in deps_field_sets.field_sets)
    wheel_paths = [
        artifact.relpath for built_pkg in built_packages
        for artifact in built_pkg.artifacts
        if artifact.relpath is not None and artifact.relpath.endswith(".whl")
    ]
    if not wheel_paths:
        raise InvalidTargetException(
            softwrap(f"""
                The `{PyOxidizerTarget.alias}` target {field_set.address} must include
                in its `dependencies` field at least one `python_distribution` target that produces a
                `.whl` file. For example, if using `{GenerateSetupField.alias}=True`, then make sure
                `{WheelField.alias}=True`. See {doc_url('python-distributions')}.
                """))

    config_template = None
    if field_set.template.value is not None:
        config_template_source = await Get(
            HydratedSources, HydrateSourcesRequest(field_set.template))
        digest_contents = await Get(DigestContents, Digest,
                                    config_template_source.snapshot.digest)
        config_template = digest_contents[0].content.decode("utf-8")

    config = PyOxidizerConfig(
        executable_name=field_set.address.target_name,
        entry_point=field_set.entry_point.value,
        wheels=wheel_paths,
        template=config_template,
        unclassified_resources=(None if
                                not field_set.unclassified_resources.value else
                                list(field_set.unclassified_resources.value)),
    )
    rendered_config = config.render()
    logger.debug(
        f"Configuration used for {field_set.address}: {rendered_config}")

    pyoxidizer_pex, config_digest = await MultiGet(
        Get(Pex, PexRequest, pyoxidizer.to_pex_request()),
        Get(
            Digest,
            CreateDigest([
                FileContent("pyoxidizer.bzl", rendered_config.encode("utf-8"))
            ])),
    )
    input_digest = await Get(
        Digest,
        MergeDigests((
            config_digest,
            runner_script.digest,
            *(built_package.digest for built_package in built_packages),
        )),
    )
    pex_process = await Get(
        Process,
        PexProcess(
            pyoxidizer_pex,
            argv=("build", *pyoxidizer.args),
            description=f"Building {field_set.address} with PyOxidizer",
            input_digest=input_digest,
            level=LogLevel.INFO,
            output_directories=("build", ),
        ),
    )
    process_with_caching = dataclasses.replace(
        pex_process,
        argv=(bash.path, runner_script.path, *pex_process.argv),
        append_only_caches={
            **pex_process.append_only_caches,
            "pyoxidizer":
            runner_script.CACHE_PATH,
        },
    )

    result = await Get(ProcessResult, Process, process_with_caching)

    stripped_digest = await Get(Digest,
                                RemovePrefix(result.output_digest, "build"))
    final_snapshot = await Get(
        Snapshot,
        AddPrefix(stripped_digest,
                  field_set.output_path.value_or_default(file_ending=None)),
    )
    return BuiltPackage(
        final_snapshot.digest,
        artifacts=tuple(
            BuiltPackageArtifact(file) for file in final_snapshot.files),
    )
Beispiel #9
0
 def validate(self) -> None:
     if self[JvmArtifactJarSourceField].value and self[
             JvmArtifactUrlField].value:
         raise InvalidTargetException(
             f"You cannot specify both the `url` and `jar` fields, but both were set on the "
             f"`{self.alias}` target {self.address}.")
Beispiel #10
0
 def validate(self) -> None:
     if self[FortranVersion].value == "bad":
         raise InvalidTargetException("Bad!")