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

Publish stripped libraries in default AAR #123

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- run: npm run start
- run:
name: compress dist
command: tar -czf dist.tgz dist
command: tar -czf dist.tgz dist dist.unstripped
- store_artifacts:
path: dist.tgz
- run:
Expand Down
22 changes: 11 additions & 11 deletions lib/android-jsc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
apply plugin: 'com.android.library'

def distDir = project.findProperty("distDir") ?: ""
def jniLibsDir = project.findProperty("jniLibsDir") ?: ""
def revision = project.findProperty("revision") ?: "".replaceAll("\\s", "")
def i18n = project.findProperty("i18n") ?: ""

if (!distDir) throw new RuntimeException("expecting --project-prop distDir=??? but was empty")
if (!jniLibsDir) throw new RuntimeException("expecting --project-prop jniLibsDir=??? but was empty")
if (!revision) throw new RuntimeException("expecting --project-prop revision=??? but was empty")
if (!i18n) throw new RuntimeException("expecting --project-prop i18n=??? but was empty")

android {
compileSdkVersion 28

Expand All @@ -12,7 +22,7 @@ android {

sourceSets {
main {
jniLibs.srcDirs = ["${rootDir}/../build/compiled"]
jniLibs.srcDirs = ["${jniLibsDir}"]
}
}

Expand All @@ -26,16 +36,6 @@ dependencies {}
apply plugin: 'maven'

task createAAR(type: Upload) {
def distDir = "${rootDir}/../dist"

def revision = project.findProperty("revision") ?: "".replaceAll("\\s", "")
def i18n = project.findProperty("i18n") ?: ""

doFirst {
if (!revision) throw new RuntimeException("expecting --project-prop revision=??? but was empty")
if (!i18n) throw new RuntimeException("expecting --project-prop i18n=??? but was empty")
}

project.group = "org.webkit"
def artifactName = Boolean.valueOf(i18n) ? "android-jsc-intl" : "android-jsc"
project.version = "r${revision}"
Expand Down
18 changes: 9 additions & 9 deletions lib/cppruntime/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
apply plugin: 'com.android.library'

def distDir = project.findProperty("distDir") ?: ""
def jniLibsDir = project.findProperty("jniLibsDir") ?: ""
def revision = project.findProperty("revision") ?: "".replaceAll("\\s", "")

if (!distDir) throw new RuntimeException("expecting --project-prop distDir=??? but was empty")
if (!jniLibsDir) throw new RuntimeException("expecting --project-prop jniLibsDir=??? but was empty")
if (!revision) throw new RuntimeException("expecting --project-prop revision=??? but was empty")

android {
compileSdkVersion 28

Expand All @@ -12,7 +20,7 @@ android {

sourceSets {
main {
jniLibs.srcDirs = ["${rootDir}/../build/cppruntime"]
jniLibs.srcDirs = ["${jniLibsDir}"]
}
}
}
Expand All @@ -22,14 +30,6 @@ dependencies {}
apply plugin: 'maven'

task createAAR(type: Upload) {
def distDir = "${rootDir}/../dist"

def revision = project.findProperty("revision") ?: "".replaceAll("\\s", "")

doFirst {
if (!revision) throw new RuntimeException("expecting --project-prop revision=??? but was empty")
}

project.group = "org.webkit"
project.version = "r${revision}"

Expand Down
4 changes: 2 additions & 2 deletions scripts/compile/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ compile_arch() {
echo -e '\033]2;'"compiling toolchain for $JSC_ARCH $FLAVOR"'\007'
printf "\n\n\n\t\t=================== compiling toolchain for $JSC_ARCH $FLAVOR ===================\n\n\n"
$SCRIPT_DIR/toolchain.sh

echo -e '\033]2;'"compiling icu for $JSC_ARCH $FLAVOR"'\007'
printf "\n\n\n\t\t=================== compiling icu for $JSC_ARCH $FLAVOR ===================\n\n\n"
$SCRIPT_DIR/icu.sh

echo -e '\033]2;'"compiling jsc for $JSC_ARCH $FLAVOR"'\007'
printf "\n\n\n\t\t=================== compiling jsc for $JSC_ARCH $FLAVOR ===================\n\n\n"
$SCRIPT_DIR/jsc.sh
Expand Down
12 changes: 6 additions & 6 deletions scripts/compile/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CROSS_COMPILE_PLATFORM=${!var}
TOOLCHAIN_DIR=$TARGETDIR/toolchains/$CROSS_COMPILE_PLATFORM

# settings
TOOLCHAIN_BIN_STRIP_arm="$TOOLCHAIN_DIR/bin/arm-linux-androideabi-strip"
TOOLCHAIN_LINK_DIR_arm="$TOOLCHAIN_DIR/$CROSS_COMPILE_PLATFORM/lib/armv7-a"
PLATFORM_CFLAGS_arm=" \
-march=armv7-a \
Expand All @@ -56,12 +57,14 @@ PLATFORM_LDFLAGS_arm=" \
"
JNI_ARCH_arm=armeabi-v7a

TOOLCHAIN_BIN_STRIP_arm64="$TOOLCHAIN_DIR/bin/aarch64-linux-android-strip"
TOOLCHAIN_LINK_DIR_arm64="$TOOLCHAIN_DIR/$CROSS_COMPILE_PLATFORM/lib"
PLATFORM_LDFLAGS_arm64=" \
-L$TOOLCHAIN_LINK_DIR_arm64 \
"
JNI_ARCH_arm64=arm64-v8a

TOOLCHAIN_BIN_STRIP_x86="$TOOLCHAIN_DIR/bin/i686-linux-android-strip"
TOOLCHAIN_LINK_DIR_x86="$TOOLCHAIN_DIR/$CROSS_COMPILE_PLATFORM/lib"
PLATFORM_CFLAGS_x86=" \
-march=i686 \
Expand All @@ -75,6 +78,7 @@ PLATFORM_LDFLAGS_x86=" \
"
JNI_ARCH_x86=x86

TOOLCHAIN_BIN_STRIP_x86_64="$TOOLCHAIN_DIR/bin/x86_64-linux-android-strip"
TOOLCHAIN_LINK_DIR_x86_64="$TOOLCHAIN_DIR/$CROSS_COMPILE_PLATFORM/lib64"
PLATFORM_CFLAGS_x86_64=" \
-march=x86-64 \
Expand All @@ -95,6 +99,8 @@ var="PLATFORM_LDFLAGS_$JSC_ARCH"
PLATFORM_LDFLAGS=${!var}
var="JNI_ARCH_$JSC_ARCH"
JNI_ARCH=${!var}
var="TOOLCHAIN_BIN_STRIP_$JSC_ARCH"
TOOLCHAIN_BIN_STRIP=${!var}
var="TOOLCHAIN_LINK_DIR_$JSC_ARCH"
TOOLCHAIN_LINK_DIR=${!var}

Expand Down Expand Up @@ -170,9 +176,3 @@ $PLATFORM_LDFLAGS \

JSC_LDFLAGS="$COMMON_LDFLAGS"
JSC_CFLAGS="$COMMON_CFLAGS -DU_STATIC_IMPLEMENTATION=1 -DU_SHOW_CPLUSPLUS_API=0"

INSTALL_DIR=$ROOTDIR/build/compiled/$JNI_ARCH
mkdir -p $INSTALL_DIR

INSTALL_CPPRUNTIME_DIR=$ROOTDIR/build/cppruntime/$JNI_ARCH
mkdir -p $INSTALL_CPPRUNTIME_DIR
6 changes: 5 additions & 1 deletion scripts/compile/jsc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,9 @@ $TARGETDIR/webkit/Tools/Scripts/build-webkit \
$BUILD_TYPE_FLAGS \
"

cp $TARGETDIR/webkit/WebKitBuild/$BUILD_TYPE/lib/libjsc.so $INSTALL_DIR
mkdir -p $INSTALL_UNSTRIPPED_DIR_I18N/$JNI_ARCH
mkdir -p $INSTALL_DIR_I18N/$JNI_ARCH
cp $TARGETDIR/webkit/WebKitBuild/$BUILD_TYPE/lib/libjsc.so $INSTALL_UNSTRIPPED_DIR_I18N/$JNI_ARCH
cp $TARGETDIR/webkit/WebKitBuild/$BUILD_TYPE/lib/libjsc.so $INSTALL_DIR_I18N/$JNI_ARCH
$TOOLCHAIN_BIN_STRIP $INSTALL_DIR_I18N/$JNI_ARCH/libjsc.so
mv $TARGETDIR/webkit/WebKitBuild $TARGETDIR/webkit/${CROSS_COMPILE_PLATFORM}-${FLAVOR}
3 changes: 2 additions & 1 deletion scripts/compile/toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ $ANDROID_NDK/build/tools/make_standalone_toolchain.py \
--arch $ARCH \
--stl libc++

cp $TOOLCHAIN_LINK_DIR/libc++_shared.so $INSTALL_CPPRUNTIME_DIR
mkdir -p $INSTALL_CPPRUNTIME_DIR/$JNI_ARCH
cp $TOOLCHAIN_LINK_DIR/libc++_shared.so $INSTALL_CPPRUNTIME_DIR/$JNI_ARCH
21 changes: 21 additions & 0 deletions scripts/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash -e

export ROOTDIR=$PWD

# Intermediated build target dir
export TARGETDIR=$ROOTDIR/build/target

# JSC shared library install dir
export INSTALL_DIR=$ROOTDIR/build/compiled

# JSC unstripped shared library install dir
export INSTALL_UNSTRIPPED_DIR=$ROOTDIR/build/compiled.unstripped

# CPP runtime shared library install dir
export INSTALL_CPPRUNTIME_DIR=$ROOTDIR/build/cppruntime

# Install dir for i18n build variants
export INSTALL_DIR_I18N_true=$INSTALL_DIR/intl
export INSTALL_DIR_I18N_false=$INSTALL_DIR/nointl
export INSTALL_UNSTRIPPED_DIR_I18N_true=$INSTALL_UNSTRIPPED_DIR/intl
export INSTALL_UNSTRIPPED_DIR_I18N_false=$INSTALL_UNSTRIPPED_DIR/nointl
4 changes: 2 additions & 2 deletions scripts/info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export REVISION=$(svn info "${URL}" | sed -n 's/^Last Changed Rev: //p')
CONFIG=$(node -e "console.log(require('$ROOTDIR/package.json').config)")
APPLE_VERSION=$(svn cat "${URL}/Source/WebCore/Configurations/Version.xcconfig" | grep 'MAJOR_VERSION\s=\|MINOR_VERSION\s=\|TINY_VERSION\s=\|MICRO_VERSION\s=\|NANO_VERSION\s=')

if [ -d "$ROOTDIR/build/compiled" ]; then
SIZE=$(du -ah $ROOTDIR/build/compiled)
if [ -d "$INSTALL_DIR_I18N_false" ]; then
SIZE=$(du -ah $INSTALL_DIR_I18N_false)
else
SIZE="0"
fi
Expand Down
86 changes: 86 additions & 0 deletions scripts/publish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env python
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all scripts are in js or bash, is introducing python here really necessary?
If you don't want to deal with cmd parsing in bash you could always pass everything by env instead.

import argparse
import json
import os
import shutil
import subprocess
import sys

ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))


class PackageConfigPatcher:
def __init__(self, suffix=''):
self._suffix = suffix
self._config_path = os.path.join(ROOT_DIR, 'package.json')
self._orig_config = ''

def __enter__(self):
with open(self._config_path, 'r') as f:
self._orig_config = f.read()
patched_config = self._create_patched_config(self._orig_config)
with open(self._config_path, 'w') as f:
f.write(patched_config)

def __exit__(self, exc_type, exc_value, traceback):
with open(self._config_path, 'w') as f:
f.write(self._orig_config)

def _create_patched_config(self, config):
patched_config = json.loads(config)
if self._suffix:
patched_config[
'version'] = patched_config['version'] + '-' + self._suffix
return json.dumps(patched_config, indent=2)


def parse_args():
arg_parser = argparse.ArgumentParser()

arg_parser.add_argument(
'--dry-run', action='store_true', help='Dry run mode for npm publish')
arg_parser.add_argument(
'--tag', '-T', type=str, required=True, help='NPM published tag')
arg_parser.add_argument(
'dist_tar_file', action='store', help='dist.tgz created from CI')

args = arg_parser.parse_args()
if not args.dist_tar_file:
arg_parser.print_help()
sys.exit(1)
return args


def main():
args = parse_args()

workdir = os.path.join(ROOT_DIR, 'build', 'publish')
if not os.path.exists(workdir):
os.makedirs(workdir)
distdir = os.path.join(ROOT_DIR, 'dist')
dryrun = '--dry-run' if args.dry_run else ''

print('\n\n========== Publish standard package ==========')
with PackageConfigPatcher(''):
if os.path.exists(distdir):
shutil.rmtree(distdir)
subprocess.check_call(
['tar', '-xf', args.dist_tar_file, '-C', workdir])
shutil.move(os.path.join(workdir, 'dist'), distdir)
subprocess.check_call(['npm', 'publish', dryrun, '--tag', args.tag])

print('\n\n========== Publish unstripped package ==========')
with PackageConfigPatcher('unstripped'):
if os.path.exists(distdir):
shutil.rmtree(distdir)
subprocess.check_call(
['tar', '-xf', args.dist_tar_file, '-C', workdir])
shutil.move(os.path.join(workdir, 'dist.unstripped'), distdir)
subprocess.check_call(
['npm', 'publish', dryrun, '--tag', args.tag + '-unstripped'])

shutil.rmtree(workdir)


if __name__ == '__main__':
main()
49 changes: 35 additions & 14 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
export ANDROID_API_FOR_ABI_32=16
export ANDROID_API_FOR_ABI_64=21
export ROOTDIR=$PWD
export TARGETDIR=$ROOTDIR/build/target

source $ROOTDIR/scripts/env.sh
source $ROOTDIR/scripts/info.sh
export JSC_VERSION=${npm_package_version}
export BUILD_TYPE=Release
Expand Down Expand Up @@ -64,38 +65,58 @@ prep() {

compile() {
printf "\n\n\t\t===================== starting to compile all archs for i18n="${I18N}" =====================\n\n"
rm -rf $ROOTDIR/build/compiled
local var="INSTALL_DIR_I18N_${I18N}"
export INSTALL_DIR_I18N=${!var}
local var="INSTALL_UNSTRIPPED_DIR_I18N_${I18N}"
export INSTALL_UNSTRIPPED_DIR_I18N=${!var}
rm -rf $INSTALL_DIR_I18N
rm -rf $INSTALL_UNSTRIPPED_DIR_I18N
$ROOTDIR/scripts/compile/all.sh
}

createAAR() {
TARGET=$1
printf "\n\n\t\t===================== create aar :$TARGET: =====================\n\n"
local target=$1
local distDir=$2
local jniLibsDir=$3
local i18n=$4
printf "\n\n\t\t===================== create aar :${target}: =====================\n\n"
cd $ROOTDIR/lib
./gradlew clean :$TARGET:createAAR --project-prop revision="$REVISION" --project-prop i18n="${I18N}"
./gradlew clean :${target}:createAAR \
--project-prop distDir="${distDir}" \
--project-prop jniLibsDir="${jniLibsDir}" \
--project-prop revision="$REVISION" \
--project-prop i18n="${i18n}"
cd $ROOTDIR
unset TARGET
}

copyHeaders() {
printf "\n\n\t\t===================== adding headers to $ROOTDIR/dist/include =====================\n\n"
mkdir -p $ROOTDIR/dist/include
cp -Rf $TARGETDIR/webkit/Source/JavaScriptCore/API/*.h $ROOTDIR/dist/include
local distDir=$1
printf "\n\n\t\t===================== adding headers to ${distDir}/include =====================\n\n"
mkdir -p ${distDir}/include
cp -Rf $TARGETDIR/webkit/Source/JavaScriptCore/API/*.h ${distDir}/include
}

export I18N=false
prep
compile
createAAR "android-jsc"

export I18N=true
prep
compile
createAAR "android-jsc"

createAAR "cppruntime"

copyHeaders
export DISTDIR=${ROOTDIR}/dist
printf "\n\n\t\t===================== create stripped distributions =====================\n\n"
createAAR "android-jsc" ${DISTDIR} ${INSTALL_DIR_I18N_false} "false"
createAAR "android-jsc" ${DISTDIR} ${INSTALL_DIR_I18N_true} "true"
createAAR "cppruntime" ${DISTDIR} ${INSTALL_CPPRUNTIME_DIR} "false"
copyHeaders ${DISTDIR}

printf "\n\n\t\t===================== create unstripped distributions =====================\n\n"
export DISTDIR=${ROOTDIR}/dist.unstripped
createAAR "android-jsc" ${DISTDIR} ${INSTALL_UNSTRIPPED_DIR_I18N_false} "false"
createAAR "android-jsc" ${DISTDIR} ${INSTALL_UNSTRIPPED_DIR_I18N_true} "true"
createAAR "cppruntime" ${DISTDIR} ${INSTALL_CPPRUNTIME_DIR} "false"
copyHeaders ${DISTDIR}

npm run info

Expand Down