Skip to content

Commit f065e1a

Browse files
committed
Reorganize Bazel and BUCK parser code #1678
* Add Bazel and BUCK parser code back to build.py since the parsers are just subclasses of StarlarkManifestPackage * Add Bazel and BUCK test data to build directory and update tests Signed-off-by: Jono Yang <[email protected]>
1 parent 95cc0de commit f065e1a

File tree

26 files changed

+71
-212
lines changed

26 files changed

+71
-212
lines changed

src/packagedcode/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
models.IsoImagePackage,
8686
models.SquashfsPackage,
8787
chef.ChefPackage,
88-
bazel.BazelPackage,
89-
buck.BuckPackage,
88+
build.BazelPackage,
89+
build.BuckPackage,
9090
build.AutotoolsPackage,
9191
conda.CondaPackage,
9292
]

src/packagedcode/bazel.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/packagedcode/buck.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/packagedcode/build.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,13 @@ class StarlarkManifestPackage(BaseBuildManifestPackage):
109109
def recognize(cls, location):
110110
if not cls._is_build_manifest(location):
111111
return
112-
build_rules = defaultdict(list)
112+
113113
# Thanks to Starlark being a Python dialect, we can use the `ast`
114114
# library to parse it
115115
with open(location, 'rb') as f:
116116
tree = ast.parse(f.read())
117+
118+
build_rules = defaultdict(list)
117119
for statement in tree.body:
118120
# We only care about function calls or assignments to functions whose
119121
# names ends with one of the strings in `rule_types`
@@ -174,3 +176,15 @@ def compute_normalized_license(self):
174176
license_expressions.extend(licenses.get('license_expressions', []))
175177

176178
return combine_expressions(license_expressions)
179+
180+
181+
@attr.s()
182+
class BazelPackage(StarlarkManifestPackage):
183+
metafiles = ('BUILD',)
184+
default_type = 'bazel'
185+
186+
187+
@attr.s()
188+
class BuckPackage(StarlarkManifestPackage):
189+
metafiles = ('BUCK',)
190+
default_type = 'buck'

tests/packagedcode/data/bazel/end2end-expected.json renamed to tests/packagedcode/data/build/bazel/end2end-expected.json

File renamed without changes.
File renamed without changes.

tests/packagedcode/data/bazel/end2end/subdir/dir/file1 renamed to tests/packagedcode/data/build/bazel/end2end/subdir/dir/file1

File renamed without changes.
File renamed without changes.

tests/packagedcode/data/bazel/end2end/subdir2/BUILD renamed to tests/packagedcode/data/build/bazel/end2end/subdir2/BUILD

File renamed without changes.

tests/packagedcode/data/bazel/end2end/subdir2/file2 renamed to tests/packagedcode/data/build/bazel/end2end/subdir2/file2

File renamed without changes.

0 commit comments

Comments
 (0)