Skip to content

Commit ec3a770

Browse files
authored
Merge pull request conan-io#5 from uilianries/feature/size-limit
Check recipe folder size
2 parents 2fac600 + db35f57 commit ec3a770

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

hooks/conan-center.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ def test(out):
139139
if all([char in line for char in ("@", "[", "]")]):
140140
out.error("Possible use of version ranges, line %s:\n %s" % (num, line))
141141

142+
@run_test("RECIPE FOLDER SIZE", output)
143+
def test(out):
144+
max_folder_size = int(os.getenv("CONAN_MAX_RECIPE_FOLDER_SIZE_KB", 256))
145+
dir_path = os.path.dirname(conanfile_path)
146+
total_size = 0
147+
for path, dirs, files in os.walk(dir_path):
148+
for files_it in files:
149+
file_path = os.path.join(path, files_it)
150+
total_size += os.path.getsize(file_path)
151+
total_size_kb = total_size / 1024
152+
out.info("total_size_kb: %sKB" % total_size_kb)
153+
if total_size_kb > max_folder_size:
154+
out.error("The size of your recipe folder ({}KB) is larger than the maximum allowed"
155+
" size ({}KB).".format(total_size_kb, max_folder_size))
142156

143157
@raise_if_error_output
144158
def pre_source(output, conanfile, conanfile_path, **kwargs):

tests/test_hooks/test_conan-center.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AConan(ConanFile):
2525
def _get_environ(self, **kwargs):
2626
kwargs = super(ConanCenterTests, self)._get_environ(**kwargs)
2727
kwargs.update({'CONAN_HOOKS': os.path.join(os.path.dirname(__file__), '..', '..', 'hooks',
28-
'conan-center_reviewer')})
28+
'conan-center')})
2929
return kwargs
3030

3131
def test_conanfile(self):
@@ -40,7 +40,7 @@ def test_conanfile(self):
4040
self.assertIn("[LIBCXX] OK", output)
4141
self.assertIn("[MATCHING CONFIGURATION] OK", output)
4242
self.assertIn("[SHARED ARTIFACTS] OK", output)
43-
self.assertIn("ERROR: [PACKAGE LICENSE] No package licenses found", output)
43+
self.assertIn("ERROR: [PACKAGE LICENSE] No 'licenses' folder found in package", output)
4444
self.assertIn("[DEFAULT PACKAGE LAYOUT] OK", output)
4545
self.assertIn("[SHARED ARTIFACTS] OK", output)
4646
print(output)
@@ -57,7 +57,7 @@ def test_conanfile_header_only(self):
5757
self.assertIn("[LIBCXX] OK", output)
5858
self.assertIn("[MATCHING CONFIGURATION] OK", output)
5959
self.assertIn("[SHARED ARTIFACTS] OK", output)
60-
self.assertIn("ERROR: [PACKAGE LICENSE] No package licenses found", output)
60+
self.assertIn("ERROR: [PACKAGE LICENSE] No 'licenses' folder found in package", output)
6161
self.assertIn("[DEFAULT PACKAGE LAYOUT] OK", output)
6262
self.assertIn("[SHARED ARTIFACTS] OK", output)
6363

@@ -74,6 +74,26 @@ def test_conanfile_installer(self):
7474
self.assertIn("ERROR: [MATCHING CONFIGURATION] Built artifacts does not match the settings",
7575
output)
7676
self.assertIn("[SHARED ARTIFACTS] OK", output)
77-
self.assertIn("ERROR: [PACKAGE LICENSE] No package licenses found", output)
77+
self.assertIn("ERROR: [PACKAGE LICENSE] No 'licenses' folder found in package", output)
7878
self.assertIn("[DEFAULT PACKAGE LAYOUT] OK", output)
7979
self.assertIn("[SHARED ARTIFACTS] OK", output)
80+
81+
def test_regular_folder_size(self):
82+
tools.save('conanfile.py', content=self.conanfile_installer)
83+
output = self.conan(['export', '.', 'name/version@user/channel'])
84+
self.assertIn("[RECIPE FOLDER SIZE] OK", output)
85+
self.assertNotIn("ERROR: [RECIPE FOLDER SIZE]", output)
86+
87+
def test_larger_folder_size(self):
88+
content = " ".join(["test_recipe_folder_larger_size" for it in range(1048576)])
89+
tools.save('conanfile.py', content=self.conanfile_installer)
90+
tools.save('big_file', content=content)
91+
output = self.conan(['export', '.', 'name/version@user/channel'])
92+
self.assertIn("ERROR: [RECIPE FOLDER SIZE] The size of your recipe folder", output)
93+
94+
def test_custom_folder_size(self):
95+
with tools.environment_append({"CONAN_MAX_RECIPE_FOLDER_SIZE_KB": "0"}):
96+
content = " ".join(["test_recipe_folder_larger_size" for it in range(1048576)])
97+
tools.save('conanfile.py', content=self.conanfile_installer)
98+
output = self.conan(['export', '.', 'name/version@user/channel'])
99+
self.assertIn("ERROR: [RECIPE FOLDER SIZE] The size of your recipe folder", output)

0 commit comments

Comments
 (0)