fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
16cd457b
main
1"""Tests for passing configuration to cargo_dep_env rules""" 2 3_SH_WRITER = """\ 4#!/usr/bin/env bash 5set -euo pipefail 6echo content > $@ 7""" 8 9_BAT_WRITER = """\ 10@ECHO OFF 11echo content > %* 12""" 13 14def _create_dep_dir_impl ( ctx ): 15is_windows = ctx . attr . platform . values ()[ 0 ] == "windows" 16writer = ctx . actions . declare_file ( "{}.writer.{}" . format ( 17ctx . label . name , 18".bat" if is_windows else ".sh" , 19)) 20ctx . actions . write ( 21output = writer , 22content = _BAT_WRITER if is_windows else _SH_WRITER , 23is_executable = True , 24) 25 26out = ctx . actions . declare_directory ( "{}.dep_dir" . format ( ctx . label . name )) 27ctx . actions . run ( 28executable = writer , 29outputs = [ out ], 30arguments = [ 31 "{}\\a_file ".format(out.path) if is_windows else " {} / a_file ". format ( out . path ), 32], 33) 34 35return [ DefaultInfo ( files = depset ( direct = [ out ]))] 36 37_create_dep_dir = rule ( 38implementation = _create_dep_dir_impl , 39attrs = { 40"platform" : attr . label_keyed_string_dict ( 41doc = "The name of the exec platform" , 42cfg = "exec" , 43mandatory = True , 44), 45}, 46) 47 48def create_dep_dir ( name , ** kwargs ): 49native . filegroup ( 50name = "{}_" . format ( name ), 51) 52_create_dep_dir ( 53name = name , 54platform = select ({ 55"@platforms//os:windows" : { ":{}_" . format ( name ): "windows" }, 56"//conditions:default" : { ":{}_" . format ( name ): "unix" }, 57}), 58** kwargs 59)