Skip to content

Commit

Permalink
Merge pull request #316 from jingjingxyk/experiment_v4.8.x
Browse files Browse the repository at this point in the history
同步experiment分支
  • Loading branch information
jingjingxyk authored Jul 31, 2023
2 parents 014dc62 + 2653f21 commit 0bb6cf6
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 40 deletions.
3 changes: 1 addition & 2 deletions prepare.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@
$p->setLogicalProcessors('$(nproc 2> /dev/null)');
}

$p->setExtraCflags('-fno-ident -Os');
$p->withPreInstallCommand('set -x');
$p->setExtraCflags(' -Os');

// Generate make.sh
$p->execute();
8 changes: 5 additions & 3 deletions sapi/src/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Library extends Project

public bool $enableBuildLibraryCached = true;

public string $preInstallCommand = '';
public array $preInstallCommands = [];

public bool $enableBuildLibraryHttpProxy = false;

Expand Down Expand Up @@ -160,9 +160,11 @@ public function withCleanPreInstallDirectory(string $preInstallDir): static
return $this;
}

public function withPreInstallCommand(string $preInstallCommand): static
public function withPreInstallCommand(string $os, string $preInstallCommand): static
{
$this->preInstallCommand = $preInstallCommand;
if (!empty($os) && in_array($os, ['alpine','debian','ubuntu','macos']) && !empty($preInstallCommand)) {
$this->preInstallCommands[$os][] = $preInstallCommand;
}
return $this;
}

Expand Down
37 changes: 26 additions & 11 deletions sapi/src/Preprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ class Preprocessor

protected array $exportVariables = [];

protected array $preInstallCommands = [];
protected array $preInstallCommands = [
'alpine' => [],
'debian' => [],
'ubuntu' => [],
'macos' => []
];

/**
* default value : CPU logical processors
* @var string
Expand Down Expand Up @@ -432,11 +438,8 @@ protected function downloadFile(string $url, string $file, string $md5sum, strin
* @param string $downloadScript
* @return void
*/
protected function downloadFileWithScript(
string $file,
string $md5sum,
string $downloadScript,
): void {
protected function downloadFileWithScript(string $file, string $md5sum, string $downloadScript): void
{
echo PHP_EOL;
echo $downloadScript;
echo PHP_EOL;
Expand Down Expand Up @@ -565,8 +568,16 @@ public function addLibrary(Library $lib): void
if (empty($lib->license)) {
throw new Exception("require license");
}
if (!empty($lib->preInstallCommand)) {
$this->preInstallCommands[] = $lib->preInstallCommand;

if (!empty($lib->preInstallCommands)) {
foreach (['alpine', 'debian', 'ubuntu', 'macos'] as $os) {
if (!empty($lib->preInstallCommands[$os])) {
$this->preInstallCommands[$os] = array_merge(
$this->preInstallCommands[$os],
$lib->preInstallCommands[$os]
);
}
}
}

$this->libraryList[] = $lib;
Expand Down Expand Up @@ -671,7 +682,9 @@ public function addExtension(Extension $ext): void
$this->mkdirIfNotExists($dst_dir, 0777, true);
$cached = $dst_dir . '/.completed';
if (file_exists($cached) && $ext->enableBuildLibraryCached) {
echo 'ext/' . $ext_name . ' cached ';
if (in_array($this->buildType, ['dev', 'debug'])) {
echo '[ext/' . $ext_name . '] cached ' . PHP_EOL;
}
} else {
echo `tar --strip-components=1 -C $dst_dir -xf {$ext->path}`;
if ($ext->enableBuildLibraryCached) {
Expand Down Expand Up @@ -724,9 +737,11 @@ public function withExportVariable(string $key, string $value): static
return $this;
}

public function withPreInstallCommand(string $preInstallCommand): static
public function withPreInstallCommand(string $os, string $preInstallCommand): static
{
$this->preInstallCommands[] = $preInstallCommand;
if (!empty($os) && in_array($os, ['alpine', 'debian', 'ubuntu', 'macos']) && !empty($preInstallCommand)) {
$this->preInstallCommands[$os][] = $preInstallCommand;
}
return $this;
}

Expand Down
39 changes: 21 additions & 18 deletions sapi/src/builder/library/dav1d.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,6 @@

return function (Preprocessor $p) {
$dav1d_prefix = DAV1D_PREFIX;
$linux_pre_install=<<<EOF
# library dav1d :
apk add ninja python3 py3-pip nasm yasm
pip3 install meson
EOF;
$macos_pre_install=<<<EOF
export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_NO_AUTO_UPDATE=1
brew install ninja python3 nasm
# python3 -m pip install --upgrade pip
pip3 install meson
# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
EOF;
$pre_install = $p->getOsType()=='macos' ? $macos_pre_install : $linux_pre_install;
$p->addLibrary(
(new Library('dav1d'))
->withHomePage('https://code.videolan.org/videolan/dav1d/')
Expand All @@ -40,7 +23,27 @@
->withBuildLibraryCached(true)
->withCleanBuildDirectory()
->withCleanPreInstallDirectory($dav1d_prefix)
->withPreInstallCommand($pre_install)
->withPreInstallCommand(
'alpine',
<<<EOF
apk add ninja python3 py3-pip nasm yasm
pip3 install meson
EOF
)
->withPreInstallCommand(
'macos',
<<<EOF
export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_NO_AUTO_UPDATE=1
brew install ninja python3 nasm yasm
# python3 -m pip install --upgrade pip
pip3 install meson
# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
EOF
)
->withBuildScript(
<<<EOF
Expand Down
9 changes: 8 additions & 1 deletion sapi/src/builder/library/svt_av1.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@
->withManual('https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/Build-Guide.md')
->withPrefix($svt_av1_prefix)
->withPreInstallCommand(
'alpine',
<<<EOF
apk add yasm nasm
apk add yasm nasm
EOF
)
->withPreInstallCommand(
'macos',
<<<EOF
brew install yasm nasm
EOF
)
->withBuildScript(
Expand Down
59 changes: 54 additions & 5 deletions sapi/src/template/make-install-deps.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,56 @@
echo " install deps "

__CURRENT_DIR__=$(cd "$(dirname "$0")";pwd)
#!/usr/bin/env bash
<?php if (in_array($this->buildType, ['dev','debug'])) : ?>
set -x
set -x
<?php endif; ?>
<?= implode(PHP_EOL, $this->preInstallCommands) .PHP_EOL ?>

__CURRENT_DIR__=$(cd "$(dirname "$0")";pwd)

echo " install deps "

<?php if ($this->osType == 'macos') : ?>
<?php foreach ($this->preInstallCommands['macos'] as $item) :?>
<?= $item . PHP_EOL ?>
<?php endforeach ;?>
<?php endif ;?>

<?php if ($this->osType == 'linux') : ?>
OS_RELEASE=$(awk -F= '/^ID=/{print $2}' /etc/os-release |tr -d '\n' | tr -d '\"')



function os_alpine_release() {
echo "${OS_RELEASE}"
<?php foreach ($this->preInstallCommands['alpine'] as $item) :?>
<?= $item . PHP_EOL ?>
<?php endforeach ;?>
return 0
}

function os_debian_release() {
echo "${OS_RELEASE}"
<?php foreach ($this->preInstallCommands['debian'] as $item) :?>
<?= $item . PHP_EOL ?>
<?php endforeach ;?>
return 0
}

function os_ubuntu_release() {
echo "${OS_RELEASE}"
<?php foreach ($this->preInstallCommands['ubuntu'] as $item) :?>
<?= $item . PHP_EOL ?>
<?php endforeach ;?>
return 0
}


if [ "$OS_RELEASE" = 'alpine' ]; then
os_alpine_release
elif [ "$OS_RELEASE" = 'debian' ]; then
os_debian_release
elif [ "$OS_RELEASE" = 'ubuntu' ]; then
os_ubuntu_release
else
echo 'no support OS'
fi

<?php endif ;?>

0 comments on commit 0bb6cf6

Please sign in to comment.