Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add a make_single_file script, used for CI. #1916

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ jobs:
$(pkg-config --cflags --libs libsodium opus vpx)
- name: Run the test
run: "./send_message_test | grep 'tox clients connected'"
- name: Build amalgamation file with TCC
run:
other/make_single_file
auto_tests/send_message_test.c
testing/misc_tools.c |
tcc -
-o send_message_test
-Wall -Werror
-bench -g
$(pkg-config --cflags --libs libsodium opus vpx)
- name: Run the test again
run: "./send_message_test | grep 'tox clients connected'"

build-compcert:
runs-on: ubuntu-latest
Expand Down
56 changes: 56 additions & 0 deletions other/make_single_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env perl
#
# This script can be used to create a single .c file with all of toxcore in it
# as well as your code or test file. It does not depend on any header files
# anymore, as those are emitted directly into the .c file.
#
# Example:
#
# other/make_single_file testing/misc_tools.c auto_tests/send_message_test.c | \
# tcc -o send_message_test - $(pkg-config --cflags --libs libsodium opus vpx)

use strict;
use warnings;

use Cwd 'abs_path';

sub relative_to {
my ($rel, $fn) = @_;
my @path = split "/", $rel;
pop @path;
abs_path(join "/", @path, $fn)
}

my %seen;
sub emit {
my ($fn) = @_;
return if $seen{$fn};
$seen{$fn} = 1;

open my $fh, "<", $fn or die "$fn: $!";
my $line = 1;
print "#line $line \"$fn\"\n";
while (<$fh>) {
if (/^#include "([^"]*)"/) {
emit(relative_to($fn, $1), $1);
++$line;
print "#line $line \"$fn\"\n";
} else {
print;
++$line;
}
}
}

if (@ARGV and $ARGV[0] eq "-core") {
shift @ARGV;
for my $fn (<toxcore/*.c>) {
emit(abs_path $fn);
}
} else {
for my $fn (<toxav/*.c>, <toxcore/*.c>, <toxencryptsave/*.c>) {
emit(abs_path $fn);
}
}

emit(abs_path $_) for @ARGV;