{"action":"created","issue":{"url":"https://api.github.com/repos/bazelbuild/bazel/issues/1698","repository_url":"https://api.github.com/repos/bazelbuild/bazel","labels_url":"https://api.github.com/repos/bazelbuild/bazel/issues/1698/labels{/name}","comments_url":"https://api.github.com/repos/bazelbuild/bazel/issues/1698/comments","events_url":"https://api.github.com/repos/bazelbuild/bazel/issues/1698/events","html_url":"https://github.com/bazelbuild/bazel/issues/1698","id":173693673,"number":1698,"title":"Feature request: allow attrs accept selects.","user":{"login":"ahyangyi","id":700956,"avatar_url":"https://avatars.githubusercontent.com/u/700956?v=3","gravatar_id":"","url":"https://api.github.com/users/ahyangyi","html_url":"https://github.com/ahyangyi","followers_url":"https://api.github.com/users/ahyangyi/followers","following_url":"https://api.github.com/users/ahyangyi/following{/other_user}","gists_url":"https://api.github.com/users/ahyangyi/gists{/gist_id}","starred_url":"https://api.github.com/users/ahyangyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahyangyi/subscriptions","organizations_url":"https://api.github.com/users/ahyangyi/orgs","repos_url":"https://api.github.com/users/ahyangyi/repos","events_url":"https://api.github.com/users/ahyangyi/events{/privacy}","received_events_url":"https://api.github.com/users/ahyangyi/received_events","type":"User","site_admin":false},"labels":[{"id":287828494,"url":"https://api.github.com/repos/bazelbuild/bazel/labels/category:%20extensibility%20%3E%20skylark","name":"category: extensibility > skylark","color":"d4c5f9","default":false},{"id":192364241,"url":"https://api.github.com/repos/bazelbuild/bazel/labels/P3","name":"P3","color":"fbca04","default":false},{"id":106503261,"url":"https://api.github.com/repos/bazelbuild/bazel/labels/type:%20feature%20request","name":"type: feature request","color":"0052cc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-08-29T04:21:59Z","updated_at":"2016-12-02T08:40:33Z","closed_at":null,"body":"I tried to put a `select` of lists of `string`s to a `rule`'s `attr` expecting a `string_list` or a `label_list`, but that didn't work. This seems an important feature missing, since without `selects` we have absolutely no flexibility to write `BUILD`s that work under different configurations.\n\nThanks.\n"},"comment":{"url":"https://api.github.com/repos/bazelbuild/bazel/issues/comments/264402149","html_url":"https://github.com/bazelbuild/bazel/issues/1698#issuecomment-264402149","issue_url":"https://api.github.com/repos/bazelbuild/bazel/issues/1698","id":264402149,"user":{"login":"ahyangyi","id":700956,"avatar_url":"https://avatars.githubusercontent.com/u/700956?v=3","gravatar_id":"","url":"https://api.github.com/users/ahyangyi","html_url":"https://github.com/ahyangyi","followers_url":"https://api.github.com/users/ahyangyi/followers","following_url":"https://api.github.com/users/ahyangyi/following{/other_user}","gists_url":"https://api.github.com/users/ahyangyi/gists{/gist_id}","starred_url":"https://api.github.com/users/ahyangyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahyangyi/subscriptions","organizations_url":"https://api.github.com/users/ahyangyi/orgs","repos_url":"https://api.github.com/users/ahyangyi/repos","events_url":"https://api.github.com/users/ahyangyi/events{/privacy}","received_events_url":"https://api.github.com/users/ahyangyi/received_events","type":"User","site_admin":false},"created_at":"2016-12-02T08:40:33Z","updated_at":"2016-12-02T08:40:33Z","body":"@ulfjack Thanks. That's a good question. I revisited this feature request and tested and can confirm that said rules can indeed accept selects.\r\n\r\nMy original intention, however, was to set the default value of an attr to a select. For example:\r\n```\r\ndef _cat_impl(ctx):\r\n    srcs = ctx.files.srcs\r\n    output = ctx.outputs.cat\r\n\r\n    ctx.action(\r\n        command = \"cat %s > %s\" % (\" \".join([x.path for x in srcs]), output.path),\r\n        inputs = srcs,\r\n        outputs = [output],\r\n        )\r\n\r\ncat = rule(\r\n    implementation = _cat_impl,\r\n    attrs = {\r\n        \"srcs\": attr.label_list(allow_files=True, default=select({\"//conditions:default\": []})),\r\n        },\r\n    outputs = {\r\n        \"cat\": \"%{name}.cat\",\r\n        },\r\n)\r\n```\r\n\r\nThis fails:\r\n```\r\nERROR: /home/<redacted-but-thats-me>/test/cat/cat.bzl:14:17: Traceback (most recent call last):\r\n        File \"/home/<redacted-but-thats-me>/test/cat/cat.bzl\", line 11\r\n                rule(implementation = _cat_impl, attrs ...\": []}))}, ...\"})\r\n        File \"/home/<redacted-but-thats-me>/test/cat/cat.bzl\", line 14, in rule\r\n                attr.label_list(allow_files = True, default = sele...\": []}))\r\nexpected sequence of Labels or sequence of Labels-returning function for 'default' while calling label_list but got select of list instead: selector({\"//conditions:default\": []}).\r\nERROR: error loading package 'cat': Extension file 'cat/cat.bzl' has errors.\r\n```\r\n\r\nBut I wish that could be accepted."}}
{"actor":{"display_login":"ahyangyi"}}