Skip to content

Commit

Permalink
various changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas0610 committed Jun 25, 2017
1 parent 0a30fe2 commit 233559a
Showing 1 changed file with 96 additions and 70 deletions.
166 changes: 96 additions & 70 deletions aabs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,22 @@
// check if ROM is supported
__validate_rom($rom);

__cmd();
?>#!/bin/bash
cd "<?php echo AABS_SOURCE_BASEDIR . "/{$rom}"; ?>"
repo sync -c -d --force-sync --no-clone-bundle --jobs=<?php echo AABS_SYNC_JOBS; ?>
<?php
__cmd_end();
$__assert = "";
$__assert .= 'ret=$?' . "\n";
$__assert .= 'if [ ! $ret -eq 0 ]; then' . "\n";
$__assert .= "\t" . 'exit $ret' . "\n";
$__assert .= 'fi' . "\n";
$__assert .= "\n";

$command = "";
$command .= '#!/bin/bash' . "\n";
$command .= "\n";
$command .= 'cd "' . AABS_SOURCE_BASEDIR . "/{$rom}" . '"' . "\n" . $__assert;
$command .= "\n";
$command .= 'repo sync -c -d --force-sync --no-clone-bundle --jobs=' . AABS_SYNC_JOBS . "\n" . $__assert;
$command .= "\n";

__exec($command);
}

function aabs_build($rom, $device_prefix, $main_device, $targets_combinations) {
Expand All @@ -86,47 +96,54 @@ repo sync -c -d --force-sync --no-clone-bundle --jobs=<?php echo AABS_SYNC_JOBS;
// check if ROM is supported
__validate_rom($rom);

$output_match_path = "out/target/product/{$main_device}/" . __get_output_match($rom, $device);

__cmd();
?>#!/bin/bash

cd "<?php echo AABS_SOURCE_BASEDIR . "/{$rom}"; ?>"

export RR_BUILDTYPE=Unofficial
export WITH_ROOT_METHOD="magisk"

source build/envsetup.sh

rm -fv <?php echo $output_match_path; ?>

rm -fv <?php echo $output_match_path; ?>.bak

<?php
foreach($targets_combinations as $device => $cmd) {
// check if device is disabled
if (AABS_DEVICES != "*" && strpos(AABS_DEVICES, "{$device} ") === false) {
continue;
}

$targets = isset($cmd['targets']) ? $cmd['targets'] : "bacon";
$clobber = isset($cmd['clobber']) ? $cmd['clobber'] : false;
$jobs = isset($cmd['jobs']) ? $cmd['jobs'] : AABS_BUILD_JOBS;
?>

lunch <?php echo $device_prefix; ?>_<?php echo $device; ?>-userdebug

<?php if ($clobber) { ?>
make clobber -j<?php echo $jobs; ?>
<?php } ?>

make <?php echo $targets;?> -j<?php echo $jobs; ?>

<?php } ?>

<?php
__cmd_end();
}
$output_match_path = "out/target/product/{$main_device}/" . __get_output_match($rom, $main_device);

$__assert = "";
$__assert .= 'ret=$?' . "\n";
$__assert .= 'if [ ! $ret -eq 0 ]; then' . "\n";
$__assert .= "\t" . 'exit $ret' . "\n";
$__assert .= 'fi' . "\n";
$__assert .= "\n";

$command = "";
$command .= '#!/bin/bash' . "\n";
$command .= "\n";
$command .= 'cd "' . AABS_SOURCE_BASEDIR . "/{$rom}" . '"' . "\n" . $__assert;
$command .= "\n";
$command .= 'rm -fv ' . $output_match_path . "\n" . $__assert;
$command .= 'rm -fv ' . $output_match_path . '.bak' . "\n" . $__assert;
$command .= "\n";
$command .= 'export RR_BUILDTYPE=Unofficial' . "\n";
$command .= 'export WITH_ROOT_METHOD="magisk"' . "\n";
$command .= "\n";
$command .= 'source build/envsetup.sh' . "\n";
$command .= "\n";
$command .= 'rm -fv "' . $output_match_path . '"' . "\n" . $__assert;
$command .= 'rm -fv "' . $output_match_path . '.bak"' . "\n" . $__assert;
$command .= "\n";

foreach($targets_combinations as $device => $cmd) {
// check if device is disabled
if (AABS_DEVICES != "*" && strpos(AABS_DEVICES, "{$device} ") === false) {
continue;
}

$targets = isset($cmd['targets']) ? $cmd['targets'] : "bacon";
$clobber = isset($cmd['clobber']) ? $cmd['clobber'] : false;
$jobs = isset($cmd['jobs']) ? $cmd['jobs'] : AABS_BUILD_JOBS;

$command .= 'lunch ' . $device_prefix . '_' . $device . '-userdebug' . "\n" . $__assert;

if ($clobber) {
$command .= 'make clobber -j' . $jobs . "\n" . $__assert;
}

$command .= 'make ' . $targets . ' -j' . $jobs . "\n" . $__assert;
$command .= "\n";
}

__exec($command);
}

function aabs_patch($rom, $device, $targets = array( )) {
if (is_array($device)) {
Expand Down Expand Up @@ -441,10 +458,14 @@ make <?php echo $targets;?> -j<?php echo $jobs; ?>
echo "Switching to passive-mode...\n";
if (!ftp_pasv($ftp_conn, true))
die("aabs_upload: failed to switch to passive-mode");


echo "Creating upload-directory...\n";
if (!ftp_mksubdirs($ftp_conn, "/", $upload_dir))
die("aabs_upload: failed to create upload-directory \"${upload_dir}\"");

echo "Uploading...\n";
if (!ftp_put($ftp_conn, "${upload_dir}/.${upload_file}", $output_path, FTP_BINARY))
die("aabs_upload: failed to upload build");
die("aabs_upload: failed to upload build to \"${upload_dir}/.${upload_file}\"");

echo "Make build visible...\n";
if (!ftp_rename($ftp_conn, "$upload_dir/.$upload_file", "$upload_dir/$upload_file"))
Expand All @@ -458,21 +479,6 @@ make <?php echo $targets;?> -j<?php echo $jobs; ?>
echo "\n";
}

function __cmd() {
ob_start();
}

function __cmd_end() {
$cmd = ob_get_contents();
ob_end_clean();

$tmpfname = tempnam(sys_get_temp_dir(), 'aabs-cmd-');
file_put_contents($tmpfname, $cmd . "\n");

__exec("/bin/bash {$tmpfname}");
unlink($tmpfname);
}

function __mkdir($name) {
if(!is_dir($name))
__exec("mkdir -p {$name}");
Expand All @@ -482,12 +488,19 @@ make <?php echo $targets;?> -j<?php echo $jobs; ?>
$output = array( );
$rc = 0;
$dcmdline = $cmdline;

foreach($censoring as $censor) {
$dcmdline = str_replace($censor, "***", $dcmdline);
}

echo "{$dcmdline}\n";

if (strpos($cmdline, "\n") !== false) {
$tempfile = tempnam(sys_get_temp_dir(), "aabs-exec-");
file_put_contents($tempfile, $cmdline);
chmod($tempfile, 0777);
$dcmdline = $cmdline = "/bin/bash -c {$tempfile}";
} else {
foreach($censoring as $censor) {
$dcmdline = str_replace($censor, "***", $dcmdline);
}
}

echo "{$dcmdline}\n";
system("{$cmdline}", $rc);

if ($rc != 0) {
Expand Down Expand Up @@ -519,3 +532,16 @@ make <?php echo $targets;?> -j<?php echo $jobs; ?>
return "aokp_${device}-ota-*.zip";
}
}

// http://php.net/manual/en/function.ftp-mkdir.php#112399
function ftp_mksubdirs($ftpcon, $ftpbasedir, $ftpath) {
@ftp_chdir($ftpcon, $ftpbasedir);
$parts = explode('/', $ftpath);
foreach($parts as $part) {
if(!@ftp_chdir($ftpcon, $part)) {
@ftp_mkdir($ftpcon, $part);
@ftp_chdir($ftpcon, $part);
}
}
return true;
}

0 comments on commit 233559a

Please sign in to comment.