Skip to content

Commit

Permalink
Report for cookbooks without recipes
Browse files Browse the repository at this point in the history
Summary: Cookbooks that don't evaluate Ruby outside of recipes presumably are easier to remove from other cookbook dependencies, since without an include_recipe call to a recipe they will be unlikely to have any purpose (though this is not a substitute for checking for other usage).

Differential Revision: D52215844

fbshipit-source-id: 876dacc0e686168fdda72f2064949e25ce61c998
  • Loading branch information
dafyddcrosby authored and facebook-github-bot committed Jan 2, 2024
1 parent 0f6aab9 commit e17c840
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2023-present, Meta, Inc.
# 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.
description 'Determines all cookbooks that do not evaluate Ruby code on load'
needs_rules %w{
MetadatarbExists
AttributeExists
LibraryExists
ResourceExists
ProviderExists
}

def to_a
cookbooks = Set.new(@kb.cookbooks.keys)
cookbooks.subtract(Set.new(@kb.attributes.map { |_, c| c['cookbook'] }))
cookbooks.subtract(Set.new(@kb.libraries.map { |_, c| c['cookbook'] }))
cookbooks.subtract(Set.new(@kb.resources.map { |_, c| c['cookbook'] }))
cookbooks.subtract(Set.new(@kb.providers.map { |_, c| c['cookbook'] }))
cookbooks.to_a.sort
end

def output
to_a
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2022-present, Meta, Inc.
# 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.
description 'Helper rule to show existence of an attributes file'
keys %w{
attribute
}

def output
true
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2022-present, Meta, Inc.
# 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.
description 'Helper rule to show existence of a library file'
keys %w{
library
}

def output
true
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2022-present, Meta, Inc.
# 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.
description 'Helper rule to show existence of a metadata.rb file'
keys %w{
metadatarb
}

def output
true
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2022-present, Meta, Inc.
# 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.
description 'Helper rule to show existence of a provider file'
keys %w{
provider
}

def output
true
end
22 changes: 22 additions & 0 deletions cookbooks/fb_bookworm/files/default/bookworm/rules/RecipeExists.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2022-present, Meta, Inc.
# 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.
description 'Helper rule to show existence of a recipe'
keys %w{
recipe
}

def output
true
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2022-present, Meta, Inc.
# 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.
description 'Helper rule to show existence of a resource file'
keys %w{
resource
}

def output
true
end

0 comments on commit e17c840

Please sign in to comment.