Skip to content

Commit

Permalink
NFC: Cleanups and Formatting
Browse files Browse the repository at this point in the history
Also enable starlark linting in CI
  • Loading branch information
ob committed May 14, 2020
1 parent 026f3f7 commit 0637a17
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 152 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
integration_tests:
name: Build and Test
runs-on: macOS-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v1
- name: Select Xcode 11.2
Expand All @@ -21,18 +21,18 @@ jobs:
with:
name: bazel-testlogs
path: bazel-testlogs
check_docs:
buildifier:
name: Check Starlark
runs-on: macOS-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v1
- name: Select Xcode 11.2
run: sudo xcode-select -s /Applications/Xcode_11.2.app
- name: Install buildifier
run: brew install buildifier
- name: buildifier
run: find . -type f \( -name 'WORKSPACE' -o -name '*.bzl' -o -name '*.bazel' \) | xargs buildifier --mode=diff
buildifier:
run: find . -type f \( -name 'WORKSPACE' -o -name '*.bzl' -o -name '*.bazel' \) | xargs buildifier -lint=fix && git diff --exit-code
check_docs:
name: Check Docs
runs-on: macOS-latest
steps:
Expand Down
12 changes: 12 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"bazelbuild.vscode-bazel",
"github.vscode-pull-request-github",
"ms-vscode.cpptools",
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.exclude": {
"bazel-*": true
},
"editor.formatOnSave": true,
}
5 changes: 2 additions & 3 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package(default_visibility = ["//visibility:private"])

load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

package(default_visibility = ["//visibility:private"])

_RULES = [
"app",
"framework",
Expand Down
18 changes: 18 additions & 0 deletions docs/hmap_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,21 @@ regardless of the package structure being used.
| namespace | The prefix to be used for header imports when flatten_headers is true | String | required | |


<a name="#HeaderMapInfo"></a>

## HeaderMapInfo

<pre>
HeaderMapInfo(<a href="#HeaderMapInfo-files">files</a>)
</pre>

Propagates header maps

**FIELDS**


| Name | Description |
| :-------------: | :-------------: |
| files | depset with headermaps |


81 changes: 5 additions & 76 deletions docs/library_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ Writes out a file verbatim
| destination | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |


<a name="#PrivateHeaders"></a>
<a name="#PrivateHeadersInfo"></a>

## PrivateHeaders
## PrivateHeadersInfo

<pre>
PrivateHeaders(<a href="#PrivateHeaders-headers">headers</a>)
PrivateHeadersInfo(<a href="#PrivateHeadersInfo-headers">headers</a>)
</pre>

Propagates private headers, so they can be accessed if necessary
Expand Down Expand Up @@ -82,81 +82,10 @@ reasonable defaults that mimic Xcode's behavior.
| :-------------: | :-------------: | :-------------: |
| name | The base name for all of the underlying targets. | none |
| library_tools | An optional dictionary containing overrides for default behaviors. | <code>{}</code> |
| export_private_headers | Whether private headers should be exported via a <code>PrivateHeaders</code> provider. | <code>True</code> |
| export_private_headers | Whether private headers should be exported via a <code>PrivateHeadersInfo</code> provider. | <code>True</code> |
| namespace_is_module_name | Whether the module name should be used as the namespace for header imports, instead of the target name. | <code>True</code> |
| default_xcconfig_name | The name of a default xcconfig to be applied to this target. | <code>None</code> |
| xcconfig | A dictionary of Xcode build settings to be applied to this target in the form of different <code>copt</code> attributes. | <code>{}</code> |
| kwargs | <p align="center"> - </p> | none |


<a name="#generate_resource_bundles"></a>

## generate_resource_bundles

<pre>
generate_resource_bundles(<a href="#generate_resource_bundles-name">name</a>, <a href="#generate_resource_bundles-library_tools">library_tools</a>, <a href="#generate_resource_bundles-module_name">module_name</a>, <a href="#generate_resource_bundles-resource_bundles">resource_bundles</a>, <a href="#generate_resource_bundles-kwargs">kwargs</a>)
</pre>



**PARAMETERS**


| Name | Description | Default Value |
| :-------------: | :-------------: | :-------------: |
| name | <p align="center"> - </p> | none |
| library_tools | <p align="center"> - </p> | none |
| module_name | <p align="center"> - </p> | none |
| resource_bundles | <p align="center"> - </p> | none |
| kwargs | <p align="center"> - </p> | none |


<a name="#write_modulemap"></a>

## write_modulemap

<pre>
write_modulemap(<a href="#write_modulemap-name">name</a>, <a href="#write_modulemap-library_tools">library_tools</a>, <a href="#write_modulemap-umbrella_header">umbrella_header</a>, <a href="#write_modulemap-public_headers">public_headers</a>, <a href="#write_modulemap-private_headers">private_headers</a>, <a href="#write_modulemap-module_name">module_name</a>,
<a href="#write_modulemap-framework">framework</a>, <a href="#write_modulemap-kwargs">kwargs</a>)
</pre>



**PARAMETERS**


| Name | Description | Default Value |
| :-------------: | :-------------: | :-------------: |
| name | <p align="center"> - </p> | none |
| library_tools | <p align="center"> - </p> | none |
| umbrella_header | <p align="center"> - </p> | <code>None</code> |
| public_headers | <p align="center"> - </p> | <code>[]</code> |
| private_headers | <p align="center"> - </p> | <code>[]</code> |
| module_name | <p align="center"> - </p> | <code>None</code> |
| framework | <p align="center"> - </p> | <code>False</code> |
| kwargs | <p align="center"> - </p> | none |


<a name="#write_umbrella_header"></a>

## write_umbrella_header

<pre>
write_umbrella_header(<a href="#write_umbrella_header-name">name</a>, <a href="#write_umbrella_header-library_tools">library_tools</a>, <a href="#write_umbrella_header-public_headers">public_headers</a>, <a href="#write_umbrella_header-private_headers">private_headers</a>, <a href="#write_umbrella_header-module_name">module_name</a>, <a href="#write_umbrella_header-kwargs">kwargs</a>)
</pre>



**PARAMETERS**


| Name | Description | Default Value |
| :-------------: | :-------------: | :-------------: |
| name | <p align="center"> - </p> | none |
| library_tools | <p align="center"> - </p> | none |
| public_headers | <p align="center"> - </p> | <code>[]</code> |
| private_headers | <p align="center"> - </p> | <code>[]</code> |
| module_name | <p align="center"> - </p> | <code>None</code> |
| kwargs | <p align="center"> - </p> | none |
| kwargs | keyword arguments. | none |


12 changes: 7 additions & 5 deletions rules/framework.bzl
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""Framework rules"""

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//lib:types.bzl", "types")
load("@build_bazel_rules_swift//swift:swift.bzl", "SwiftInfo", "swift_common")
load("//rules:library.bzl", "PrivateHeaders", "apple_library")
load("//rules:library.bzl", "PrivateHeadersInfo", "apple_library")

def apple_framework(name, apple_library = apple_library, **kwargs):
"""Builds and packages an Apple framework.
Args:
name: The name of the framework.
apple_library: The macro used to package sources into a library.
kwargs: Arguments passed to the apple_library and apple_framework_packaging rules as appropriate.
**kwargs: Arguments passed to the apple_library and apple_framework_packaging rules as appropriate.
"""

library = apple_library(name = name, **kwargs)
apple_framework_packaging(
name = name,
Expand Down Expand Up @@ -126,8 +128,8 @@ def _apple_framework_packaging_impl(ctx):
arch + ".swiftdoc",
)]

if PrivateHeaders in dep:
for hdr in dep[PrivateHeaders].headers.to_list():
if PrivateHeadersInfo in dep:
for hdr in dep[PrivateHeadersInfo].headers.to_list():
private_header_in.append(hdr)
destination = paths.join(framework_dir, "PrivateHeaders", hdr.basename)
private_header_out.append(destination)
Expand Down
2 changes: 2 additions & 0 deletions rules/framework/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@rules_python//python:defs.bzl", "py_binary")

py_binary(
name = "framework_packaging",
srcs = ["framework_packaging.py"],
Expand Down
6 changes: 3 additions & 3 deletions rules/framework/framework_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _clean(framework_root, manifest_file, output_manifest_file):
dirs_to_keep = set((framework_root,))
for file in manifest_lines:
files_to_keep.add(file)

dir = os.path.dirname(file)
while dir not in dirs_to_keep:
dirs_to_keep.add(dir)
Expand Down Expand Up @@ -130,7 +130,7 @@ def output(self):
def main():
"""Main function."""
actions = {
"header":
"header":
lambda args: _copy_headers(args.framework_root, args.inputs),
"private_header":
lambda args: _copy_private_headers(args.framework_root, args.inputs),
Expand All @@ -153,7 +153,7 @@ def main():
parser.add_argument('--inputs', type = str, nargs='*')
parser.add_argument('--outputs', type = str, nargs='*')
args = parser.parse_args(namespace=Args())

action = actions[args.action]
action(args)

Expand Down
52 changes: 24 additions & 28 deletions rules/hmap.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "SwiftInfo")
"""Header Map rules"""

HeaderMapInfo = provider(
doc = "Propagates header maps",
fields = {
"files": "depset with headermaps",
},
)

def _make_headermap_input_file(namespace, hdrs, flatten_headers):
"""Create a string representing the mappings from headers to their
"""Create a header map input file.
This function creates a string representing the mappings from headers to their
namespaced include versions. The format is
virtual_header_path|real_header_path
Expand All @@ -18,8 +27,8 @@ def _make_headermap_input_file(namespace, hdrs, flatten_headers):
:return: string with all the headers in the above mentioned
format. This can be saved to a file and read by the hmapbuild tool
included here to create a header map file.
"""

entries = []
for hdr in hdrs:
namespaced_key = namespace + "/" + hdr.basename
Expand All @@ -29,15 +38,16 @@ def _make_headermap_input_file(namespace, hdrs, flatten_headers):
return "\n".join(entries) + "\n"

def _make_headermap_impl(ctx):
"""Implementation of the headermap() rule. It creates a text file with
"""Implementation of the headermap() rule.
It creates a text file with
the mappings and creates an action that calls out to the hmapbuild
tool included here to create the actual .hmap file.
:param ctx: context for this rule. See
https://docs.bazel.build/versions/master/skylark/lib/ctx.html
:return: provider with the info for this rule
"""

# Write a file for *this* headermap, this is a temporary file
Expand All @@ -58,24 +68,8 @@ def _make_headermap_impl(ctx):
)

# Add a list of headermaps in text or hmap format
merge_hmaps = {}
inputs = [input_f]
args = []

if merge_hmaps:
paths = []
for hdr in merge_hmaps.keys():
inputs.append(hdr)
paths.append(hdr.path)
merge_hmaps_file = ctx.actions.declare_file(ctx.label.name + ".merge_hmaps")
inputs.append(merge_hmaps_file)
ctx.actions.write(
content = "\n".join(paths) + "\n",
output = merge_hmaps_file,
)
args += ["--merge-hmaps", merge_hmaps_file.path]

args += [input_f.path, ctx.outputs.headermap.path]
args = [input_f.path, ctx.outputs.headermap.path]
ctx.actions.run(
inputs = inputs,
mnemonic = "HmapCreate",
Expand All @@ -87,12 +81,14 @@ def _make_headermap_impl(ctx):
header = depset([ctx.outputs.headermap]),
)
cc_info_provider = CcInfo(compilation_context = objc_provider.compilation_context)
return struct(
files = depset([ctx.outputs.headermap]),
providers = [objc_provider, cc_info_provider],
objc = objc_provider,
headers = depset([ctx.outputs.headermap]),
)

return [
HeaderMapInfo(
files = depset([ctx.outputs.headermap]),
),
objc_provider,
cc_info_provider,
]

# Derive a headermap from transitive headermaps
# hdrs: a file group containing headers for this rule
Expand Down
2 changes: 2 additions & 0 deletions rules/hmap/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Google
IndentWidth: 4
2 changes: 2 additions & 0 deletions rules/hmap/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")

HMAP_COPTS = [
"-DHASH_FUNCTION=HASH_MUR",
"-DHASH_USING_NO_STRICT_ALIASING",
Expand Down
1 change: 1 addition & 0 deletions rules/hmap/hmap.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "hmap.h"

#include <assert.h>
#include <ctype.h>
#include <fcntl.h>
Expand Down
20 changes: 10 additions & 10 deletions rules/hmap/hmapdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#include "hmap.h"

int main(int ac, char** av) {
if (ac < 2) {
fprintf(stderr, "usage: hmapdump <file>\n");
return 1;
}
if (ac < 2) {
fprintf(stderr, "usage: hmapdump <file>\n");
return 1;
}

HeaderMap* hmap = hmap_open(av[1], "r");
if (!hmap) {
fprintf(stderr, "hmap failed for '%s': %s\n", av[1], strerror(errno));
}
hmap_dump(hmap);
hmap_close(hmap);
HeaderMap* hmap = hmap_open(av[1], "r");
if (!hmap) {
fprintf(stderr, "hmap failed for '%s': %s\n", av[1], strerror(errno));
}
hmap_dump(hmap);
hmap_close(hmap);
}
Loading

0 comments on commit 0637a17

Please sign in to comment.