<commit_before># Copyright 2014 The Bazel Authors. 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.

def _go_host_sdk_impl(ctx):
  path = _detect_host_sdk(ctx)
  _local_sdk(ctx, path)
  _sdk_build_file(ctx, path)

go_host_sdk = repository_rule(_go_host_sdk_impl, environ = ["GOROOT"])
"""go_host_sdk is a specialization of go_sdk just to add the GOROOT dependancy"""

def _go_sdk_impl(ctx):
  if ctx.attr.url:
    if ctx.attr.path:
      fail("url and path cannot both be set on go_sdk, got {} and {}".format(ctx.attr.url, ctx.attr.path))
    _remote_sdk(ctx, ctx.attr.url, ctx.attr.strip_prefix, ctx.attr.sha256)
    _sdk_build_file(ctx, str(ctx.path(".")))
  elif ctx.attr.path:
    _local_sdk(ctx, ctx.attr.path)
    _sdk_build_file(ctx, ctx.attr.path)
  else:
    path = _detect_host_sdk(ctx)
    _local_sdk(ctx, path)
    _sdk_build_file(ctx, path)
    
  # Build the standard library for valid cross compile platforms
  #TODO: fix standard library cross compilation
  if ctx.name.endswith("linux_amd64") and ctx.os.name == "linux":
    _cross_compile_stdlib(ctx, "windows", "amd64")
  if ctx.name.endswith("darwin_amd64") and ctx.os.name == "mac os x":
    _cross_compile_stdlib(ctx, "linux", "amd64")

go_sdk = repository_rule(
    implementation = _go_sdk_impl, 
    attrs = {
        "path": attr.string(),
        "url": attr.string(),
        "strip_prefix": attr.string(default="go"),
        "sha256": attr.string(),
    },
)
"""
    go_sdk is a rule for adding a new go SDK to the available set.
    This does not make the sdk available for use directly, it needs to be exposed through a toolchain.
    If you do not specify url or path, then it will attempt to detect the installed version of go.
"""<commit_msg>Fix redundant SDK download (#794)<commit_after># Copyright 2014 The Bazel Authors. 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.

def _go_host_sdk_impl(ctx):
  path = _detect_host_sdk(ctx)
  _local_sdk(ctx, path)
  _sdk_build_file(ctx, path)

go_host_sdk = repository_rule(_go_host_sdk_impl, environ = ["GOROOT"])
"""go_host_sdk is a specialization of go_sdk just to add the GOROOT dependancy"""

def _go_sdk_impl(ctx):
  if ctx.attr.url:
    if ctx.attr.path:
      fail("url and path cannot both be set on go_sdk, got {} and {}".format(ctx.attr.url, ctx.attr.path))
    _sdk_build_file(ctx, str(ctx.path(".")))
    _remote_sdk(ctx, ctx.attr.url, ctx.attr.strip_prefix, ctx.attr.sha256)
  elif ctx.attr.path:
    _sdk_build_file(ctx, ctx.attr.path)
    _local_sdk(ctx, ctx.attr.path)
  else:
    path = _detect_host_sdk(ctx)
    _sdk_build_file(ctx, path)
    _local_sdk(ctx, path)
    
  # Build the standard library for valid cross compile platforms
  #TODO: fix standard library cross compilation
  if ctx.name.endswith("linux_amd64") and ctx.os.name == "linux":
    _cross_compile_stdlib(ctx, "windows", "amd64")
  if ctx.name.endswith("darwin_amd64") and ctx.os.name == "mac os x":
    _cross_compile_stdlib(ctx, "linux", "amd64")

go_sdk = repository_rule(
    implementation = _go_sdk_impl, 
    attrs = {
        "path": attr.string(),
        "url": attr.string(),
        "strip_prefix": attr.string(default="go"),
        "sha256": attr.string(),
    },
)
"""
    go_sdk is a rule for adding a new go SDK to the available set.
    This does not make the sdk available for use directly, it needs to be exposed through a toolchain.
    If you do not specify url or path, then it will attempt to detect the installed version of go.
"""
{'fraction_non_alphanumeric': 0.10536823425022183, 'fraction_numerical': 0.010425909494232475, 'mean_word_length': 3.8745945945945945, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7285986', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1427, 'n_words': 498}