// Copyright 2014 Google Inc. All rights reserved. // // 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. package com.google.devtools.build.lib.bazel.rules.workspace; import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.Type.STRING; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.packages.RuleClass; /** * Rule definition for the new_http_archive rule. */ public class NewHttpArchiveRule implements RuleDefinition { public static final String NAME = "new_http_archive"; @Override public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) { return builder /* A URL to an archive file containing a Bazel repository. ${SYNOPSIS}
This must be an HTTP URL that ends with .zip. There is no support for authentication or redirection.
*/ .add(attr("url", STRING).mandatory()) /* The expected SHA-256 hash of the file downloaded. ${SYNOPSIS}This must match the SHA-256 hash of the file downloaded.
*/ .add(attr("sha256", STRING).mandatory()) /* A file to use as a BUILD file for this directory. ${SYNOPSIS}This path is relative to the build's workspace. The file does not need to be named BUILD, but can be (something like BUILD.new-repo-name may work well for distinguishing it from the repository's actual BUILD files.
*/ .add(attr("build_file", STRING).mandatory()) .setWorkspaceOnly() .build(); } @Override public Metadata getMetadata() { return RuleDefinition.Metadata.builder() .name(NewHttpArchiveRule.NAME) .type(RuleClass.Builder.RuleClassType.WORKSPACE) .ancestors(WorkspaceBaseRule.class) .factoryClass(WorkspaceConfiguredTargetFactory.class) .build(); } } /* ${ATTRIBUTE_SIGNATURE}Downloads a compressed archive file, decompresses it, and creates a Bazel repository by combining the archive with the provided BUILD file.
Only Zip-formatted archives with the .zip extension are supported.
${ATTRIBUTE_DEFINITION}Suppose the current repository contains the source code for a chat program, rooted at the directory ~/chat-app. It needs to depend on an SSL library which is available from http://example.com/openssl.zip. This .zip file contains the following directory structure:
src/ openssl.cc openssl.h
In the local repository, the user creates a ssl.BUILD file which contains the following target definition:
cc_library( name = "openssl-lib", srcs = ["src/openssl.cc"], hdrs = ["src/openssl.h"], )
Targets in the ~/chat-app repository can depend on this target if the following lines are added to ~/chat-app/WORKSPACE:
new_http_archive( name = "my-ssl", url = "http://example.com/openssl.zip", sha256 = "03a58ac630e59778f328af4bcc4acb4f80208ed4", build_file = "ssl.BUILD", ) bind( name = "openssl", actual = "@my-ssl//:openssl-lib", )
See Bind for how to use bound targets.
*/