Skip to content

Commit

Permalink
Add "--comment" support to tools/bro.cc. Add build script to build to…
Browse files Browse the repository at this point in the history
…ols/bro.cc
  • Loading branch information
brendan-duncan committed Feb 8, 2021
1 parent a933e15 commit 1a16703
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 10 deletions.
18 changes: 10 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
*.o
*.pyc
*.txt.uncompressed
*.bro
*.unbro
tools/bro
build/
dist/
*.o
*.pyc
*.txt.uncompressed
*.bro
*.unbro
tools/bro
build/
dist/
cmake/
commits.txt
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 2.8.6)
project(brotli)

set(CMAKE_BUILD_TYPE Release)

FILE(GLOB_RECURSE enc enc/*.cc)
FILE(GLOB_RECURSE dec dec/*.c)
list(FILTER dec EXCLUDE REGEX ".*dec[/]dictionary[.]c$") # this is a duplicate of definitions in enc

add_executable(brotli ${enc} ${dec} tools/bro.cc)
45 changes: 45 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Controls running cmake, building, and copying files to the dist folder for the various
# platforms.
import os
import shutil
import sys
import subprocess

# build the brotli exe using cmake
if not os.path.exists('cmake'):
os.mkdir('cmake')

os.chdir('cmake')

if sys.platform == 'win32':
os.system('cmake -G "NMake Makefiles" ..')
os.system('nmake')
else:
os.system('cmake -G "Unix Makefiles" ..')
os.system('make')

os.chdir('..')

# Copy the build to the dist folder
if not os.path.exists('dist'):
os.mkdir('dist')

if sys.platform == 'win32':
if not os.path.exists('dist/win_x86_64'):
os.mkdir('dist/win_x86_64')
shutil.copy2('cmake/brotli.exe', 'dist/win_x86_64/brotli.exe')
elif sys.platform == 'darwin':
if not os.path.exists('dist/macos_x86_64'):
os.mkdir('dist/macos_x86_64')
shutil.copy2('cmake/brotli', 'dist/macos_x86_64/brotli')
else:
if not os.path.exists('dist/linux_x86_64'):
os.mkdir('dist/linux_x86_64')
shutil.copy2('cmake/brotli', 'dist/linux_x86_64/brotli')


# Create the commits.txt file
commits = open('dist/commits.txt', 'w')
subprocess.run('git config --get remote.origin.url', shell=True, stdout=commits)
subprocess.run('git rev-parse HEAD', shell=True, stdout=commits)
commits.close()
16 changes: 14 additions & 2 deletions tools/bro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ static void ParseArgv(int argc, char **argv,
int *decompress,
int *repeat,
int *verbose,
int *lgwin) {
int *lgwin,
char **comment) {
*force = 0;
*input_path = 0;
*output_path = 0;
*repeat = 1;
*verbose = 0;
*comment = 0;
*lgwin = 22;
{
size_t argv0_len = strlen(argv[0]);
Expand Down Expand Up @@ -125,6 +127,13 @@ static void ParseArgv(int argc, char **argv,
*output_path = argv[k + 1];
++k;
continue;
} else if (!strcmp("--comment", argv[k])) {
if (*comment != 0) {
goto error;
}
*comment = argv[k + 1];
++k;
continue;
} else if (!strcmp("--quality", argv[k]) ||
!strcmp("-q", argv[k])) {
if (!ParseQuality(argv[k + 1], quality)) {
Expand Down Expand Up @@ -158,6 +167,7 @@ static void ParseArgv(int argc, char **argv,
fprintf(stderr,
"Usage: %s [--force] [--quality n] [--decompress]"
" [--input filename] [--output filename] [--repeat iters]"
" [--comment commment]"
" [--verbose] [--window n]\n",
argv[0]);
exit(1);
Expand Down Expand Up @@ -275,8 +285,9 @@ int main(int argc, char** argv) {
int repeat = 1;
int verbose = 0;
int lgwin = 0;
char *comment = 0;
ParseArgv(argc, argv, &input_path, &output_path, &force,
&quality, &decompress, &repeat, &verbose, &lgwin);
&quality, &decompress, &repeat, &verbose, &lgwin, &comment);
const clock_t clock_start = clock();
for (int i = 0; i < repeat; ++i) {
FILE* fin = OpenInputFile(input_path);
Expand All @@ -287,6 +298,7 @@ int main(int argc, char** argv) {
brotli::BrotliParams params;
params.lgwin = lgwin;
params.quality = quality;
params.comment = comment;
try {
brotli::BrotliFileIn in(fin, 1 << 16);
brotli::BrotliFileOut out(fout);
Expand Down

0 comments on commit 1a16703

Please sign in to comment.