titaniumsdk: fix to make it work with new android SDK and NPM packages + add titaniumsdk version 5.2

This commit is contained in:
Sander van der Burg 2016-09-01 13:25:46 +00:00
parent 29a53017a4
commit 21666526b9
8 changed files with 51 additions and 2729 deletions

View File

@ -1,4 +1,4 @@
{stdenv, androidsdk, titaniumsdk, titanium, xcodewrapper, jdk, python, which, xcodeBaseDir}:
{stdenv, androidsdk, titaniumsdk, titanium, alloy, xcodewrapper, jdk, python, nodejs, which, xcodeBaseDir}:
{ name, src, target, androidPlatformVersions ? [ "23" ], androidAbiVersions ? [ "armeabi" "armeabi-v7a" ], tiVersion ? null
, release ? false, androidKeyStore ? null, androidKeyAlias ? null, androidKeyStorePassword ? null
, iosMobileProvisioningProfile ? null, iosCertificateName ? null, iosCertificate ? null, iosCertificatePassword ? null, iosVersion ? "9.2"
@ -47,7 +47,7 @@ stdenv.mkDerivation {
name = stdenv.lib.replaceChars [" "] [""] name;
inherit src;
buildInputs = [ titanium jdk python which ] ++ stdenv.lib.optional (stdenv.system == "x86_64-darwin") xcodewrapper;
buildInputs = [ nodejs titanium alloy jdk python which ] ++ stdenv.lib.optional (stdenv.system == "x86_64-darwin") xcodewrapper;
buildPhase = ''
export HOME=$TMPDIR
@ -78,10 +78,9 @@ stdenv.mkDerivation {
javac -version
''}
titanium config --config-file $TMPDIR/config.json --no-colors android.sdk ${androidsdkComposition}/libexec/android-sdk-*
titanium config --config-file $TMPDIR/config.json --no-colors android.buildTools.selectedVersion 23.0.1
titanium config --config-file $TMPDIR/config.json --no-colors android.sdk ${androidsdkComposition}/libexec
export PATH=$(echo ${androidsdkComposition}/libexec/android-sdk-*/tools):$(echo ${androidsdkComposition}/libexec/android-sdk-*/build-tools/android-*):$PATH
export PATH=$(echo ${androidsdkComposition}/libexec/tools):$(echo ${androidsdkComposition}/libexec/build-tools/android-*):$PATH
${if release then
''titanium build --config-file $TMPDIR/config.json --no-colors --force --platform android --target dist-playstore --keystore ${androidKeyStore} --alias ${androidKeyAlias} --store-password ${androidKeyStorePassword} --output-dir $out''

View File

@ -1,3 +0,0 @@
[
"titanium"
]

View File

@ -1,15 +0,0 @@
{system ? builtins.currentSystem, pkgs ? import <nixpkgs> {
inherit system;
}, overrides ? {}}:
let
nodeEnv = import ./node-env.nix {
inherit (pkgs) stdenv fetchurl nodejs python utillinux runCommand;
};
registry = (import ./registry.nix {
inherit (nodeEnv) buildNodePackage;
inherit (pkgs) fetchurl fetchgit;
self = registry;
}) // overrides;
in
registry

View File

@ -1,309 +0,0 @@
{ stdenv, fetchurl, nodejs, python, utillinux, runCommand }:
let
# Function that generates a TGZ file from a NPM project
buildNodeSourceDist =
{ name, version, src }:
stdenv.mkDerivation {
name = "node-tarball-${name}-${version}";
inherit src;
buildInputs = [ nodejs ];
buildPhase = ''
export HOME=$TMPDIR
tgzFile=$(npm pack)
'';
installPhase = ''
mkdir -p $out/tarballs
mv $tgzFile $out/tarballs
mkdir -p $out/nix-support
echo "file source-dist $out/tarballs/$tgzFile" >> $out/nix-support/hydra-build-products
'';
};
# We must run semver to determine whether a provided dependency conforms to a certain version range
semver = buildNodePackage {
name = "semver";
version = "5.0.3";
src = fetchurl {
url = http://registry.npmjs.org/semver/-/semver-5.0.3.tgz;
sha1 = "77466de589cd5d3c95f138aa78bc569a3cb5d27a";
};
} {};
# Function that produces a deployed NPM package in the Nix store
buildNodePackage =
{ name, version, src, dependencies ? {}, buildInputs ? [], production ? true, npmFlags ? "", meta ? {}, linkDependencies ? false }:
{ providedDependencies ? {} }:
let
# Generate and import a Nix expression that determines which dependencies
# are required and which are not required (and must be shimmed).
#
# It uses the semver utility to check whether a version range matches any
# of the provided dependencies.
analysedDependencies =
if dependencies == {} then {}
else
import (stdenv.mkDerivation {
name = "${name}-${version}-analysedDependencies.nix";
buildInputs = [ semver ];
buildCommand = ''
cat > $out <<EOF
{
${stdenv.lib.concatMapStrings (dependencyName:
let
dependency = builtins.getAttr dependencyName dependencies;
versionSpecs = builtins.attrNames dependency;
in
stdenv.lib.concatMapStrings (versionSpec:
if builtins.hasAttr dependencyName providedDependencies # Search for any provided dependencies that match the required version spec. If one matches, the dependency should not be included
then
let
providedDependency = builtins.getAttr dependencyName providedDependencies;
versions = builtins.attrNames providedDependency;
# If there is a version range match, add the dependency to
# the set of shimmed dependencies.
# Otherwise, it is a required dependency.
in
''
$(latestVersion=$(semver -r '${versionSpec}' ${stdenv.lib.concatMapStrings (version: " '${version}'") versions} | tail -1 | tr -d '\n')
if semver -r '${versionSpec}' ${stdenv.lib.concatMapStrings (version: " '${version}'") versions} >/dev/null
then
echo "shimmedDependencies.\"${dependencyName}\".\"$latestVersion\" = true;"
else
echo 'requiredDependencies."${dependencyName}"."${versionSpec}" = true;'
fi)
''
else # If a dependency is not provided by an includer, we must always include it ourselves
"requiredDependencies.\"${dependencyName}\".\"${versionSpec}\" = true;\n"
) versionSpecs
) (builtins.attrNames dependencies)}
}
EOF
'';
});
requiredDependencies = analysedDependencies.requiredDependencies or {};
shimmedDependencies = analysedDependencies.shimmedDependencies or {};
# Extract the Node.js source code which is used to compile packages with native bindings
nodeSources = runCommand "node-sources" {} ''
tar --no-same-owner --no-same-permissions -xf ${nodejs.src}
mv node-* $out
'';
# Compose dependency information that this package must propagate to its
# dependencies, so that provided dependencies are not included a second time.
# This prevents cycles and wildcard version mismatches.
propagatedProvidedDependencies =
(stdenv.lib.mapAttrs (dependencyName: dependency:
builtins.listToAttrs (map (versionSpec:
{ name = dependency."${versionSpec}".version;
value = true;
}
) (builtins.attrNames dependency))
) dependencies) //
providedDependencies //
{ "${name}"."${version}" = true; };
# Create a node_modules folder containing all required dependencies of the
# package
nodeDependencies = stdenv.mkDerivation {
name = "node-dependencies-${name}-${version}";
inherit src;
buildCommand = ''
mkdir -p $out/lib/node_modules
cd $out/lib/node_modules
# Create copies of (or symlinks to) the dependencies that must be deployed in this package's private node_modules folder.
# This package's private dependencies are NPM packages that have not been provided by any of the includers.
${stdenv.lib.concatMapStrings (requiredDependencyName:
stdenv.lib.concatMapStrings (versionSpec:
let
dependency = dependencies."${requiredDependencyName}"."${versionSpec}".pkg {
providedDependencies = propagatedProvidedDependencies;
};
in
''
depPath=$(echo ${dependency}/lib/node_modules/*)
${if linkDependencies then ''
ln -s $depPath .
'' else ''
cp -r $depPath .
''}
''
) (builtins.attrNames (requiredDependencies."${requiredDependencyName}"))
) (builtins.attrNames requiredDependencies)}
'';
};
# Deploy the Node package with some tricks
self = stdenv.lib.makeOverridable stdenv.mkDerivation {
inherit src meta;
dontStrip = true;
name = "node-${name}-${version}";
buildInputs = [ nodejs python ] ++ stdenv.lib.optional (stdenv.isLinux) utillinux ++ buildInputs;
dontBuild = true;
installPhase = ''
# Move the contents of the tarball into the output folder
mkdir -p "$out/lib/node_modules/${name}"
mv * "$out/lib/node_modules/${name}"
# Enter the target directory
cd "$out/lib/node_modules/${name}"
# Patch the shebangs of the bundled modules. For "regular" dependencies
# this is step is not required, because it has already been done by the generic builder.
if [ -d node_modules ]
then
patchShebangs node_modules
fi
# Copy the required dependencies
mkdir -p node_modules
${stdenv.lib.optionalString (requiredDependencies != {}) ''
for i in ${nodeDependencies}/lib/node_modules/*
do
if [ ! -d "node_modules/$(basename $i)" ]
then
cp -a $i node_modules
fi
done
''}
# Create shims for the packages that have been provided by earlier includers to allow the NPM install operation to still succeed
${stdenv.lib.concatMapStrings (shimmedDependencyName:
stdenv.lib.concatMapStrings (versionSpec:
''
mkdir -p node_modules/${shimmedDependencyName}
cat > node_modules/${shimmedDependencyName}/package.json <<EOF
{
"name": "${shimmedDependencyName}",
"version": "${versionSpec}"
}
EOF
''
) (builtins.attrNames (shimmedDependencies."${shimmedDependencyName}"))
) (builtins.attrNames shimmedDependencies)}
# Ignore npm-shrinkwrap.json for now. Ideally, it should be supported as well
rm -f npm-shrinkwrap.json
# Some version specifiers (latest, unstable, URLs, file paths) force NPM to make remote connections or consult paths outside the Nix store.
# The following JavaScript replaces these by * to prevent that:
(
cat <<EOF
var fs = require('fs');
var url = require('url');
/*
* Replaces an impure version specification by *
*/
function replaceImpureVersionSpec(versionSpec) {
var parsedUrl = url.parse(versionSpec);
if(versionSpec == "latest" || versionSpec == "unstable" ||
versionSpec.substr(0, 2) == ".." || dependency.substr(0, 2) == "./" || dependency.substr(0, 2) == "~/" || dependency.substr(0, 1) == '/')
return '*';
else if(parsedUrl.protocol == "git:" || parsedUrl.protocol == "git+ssh:" || parsedUrl.protocol == "git+http:" || parsedUrl.protocol == "git+https:" ||
parsedUrl.protocol == "http:" || parsedUrl.protocol == "https:")
return '*';
else
return versionSpec;
}
var packageObj = JSON.parse(fs.readFileSync('./package.json'));
/* Replace dependencies */
if(packageObj.dependencies !== undefined) {
for(var dependency in packageObj.dependencies) {
var versionSpec = packageObj.dependencies[dependency];
packageObj.dependencies[dependency] = replaceImpureVersionSpec(versionSpec);
}
}
/* Replace development dependencies */
if(packageObj.devDependencies !== undefined) {
for(var dependency in packageObj.devDependencies) {
var versionSpec = packageObj.devDependencies[dependency];
packageObj.devDependencies[dependency] = replaceImpureVersionSpec(versionSpec);
}
}
/* Replace optional dependencies */
if(packageObj.optionalDependencies !== undefined) {
for(var dependency in packageObj.optionalDependencies) {
var versionSpec = packageObj.optionalDependencies[dependency];
packageObj.optionalDependencies[dependency] = replaceImpureVersionSpec(versionSpec);
}
}
/* Write the fixed JSON file */
fs.writeFileSync("package.json", JSON.stringify(packageObj));
EOF
) | node
# Deploy the Node.js package by running npm install. Since the dependencies have been symlinked, it should not attempt to install them again,
# which is good, because we want to make it Nix's responsibility. If it needs to install any dependencies anyway (e.g. because the dependency
# parameters are incomplete/incorrect), it fails.
export HOME=$TMPDIR
npm --registry http://www.example.com --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} install
# After deployment of the NPM package, we must remove the shims again
${stdenv.lib.concatMapStrings (shimmedDependencyName:
''
rm node_modules/${shimmedDependencyName}/package.json
rmdir node_modules/${shimmedDependencyName}
''
) (builtins.attrNames shimmedDependencies)}
# It makes no sense to keep an empty node_modules folder around, so delete it if this is the case
if [ -d node_modules ]
then
rmdir --ignore-fail-on-non-empty node_modules
fi
# Create symlink to the deployed executable folder, if applicable
if [ -d "$out/lib/node_modules/.bin" ]
then
ln -s $out/lib/node_modules/.bin $out/bin
fi
# Create symlinks to the deployed manual page folders, if applicable
if [ -d "$out/lib/node_modules/${name}/man" ]
then
mkdir -p $out/share
for dir in "$out/lib/node_modules/${name}/man/"*
do
mkdir -p $out/share/man/$(basename "$dir")
for page in "$dir"/*
do
ln -s $page $out/share/man/$(basename "$dir")
done
done
fi
'';
shellHook = stdenv.lib.optionalString (requiredDependencies != {}) ''
export NODE_PATH=${nodeDependencies}/lib/node_modules
'';
};
in
self;
in
{ inherit buildNodeSourceDist buildNodePackage; }

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
{pkgs, pkgs_i686, xcodeVersion ? "7.2", xcodeBaseDir ? "/Applications/Xcode.app", tiVersion ? "5.1.2.GA"}:
{pkgs, pkgs_i686, xcodeVersion ? "7.2", xcodeBaseDir ? "/Applications/Xcode.app", tiVersion ? "5.2.3.GA"}:
rec {
androidenv = pkgs.androidenv;
@ -10,6 +10,7 @@ rec {
titaniumsdk = let
titaniumSdkFile = if tiVersion == "5.1.2.GA" then ./titaniumsdk-5.1.nix
else if tiVersion == "5.2.3.GA" then ./titaniumsdk-5.2.nix
else throw "Titanium version not supported: "+tiVersion;
in
import titaniumSdkFile {
@ -17,8 +18,8 @@ rec {
};
buildApp = import ./build-app.nix {
inherit (pkgs) stdenv python which jdk;
titanium = (import ./cli { inherit (pkgs.stdenv) system; }).titanium {};
inherit (pkgs) stdenv python which jdk nodejs;
inherit (pkgs.nodePackages) titanium alloy;
inherit (androidenv) androidsdk;
inherit (xcodeenv) xcodewrapper;
inherit titaniumsdk xcodeBaseDir;

View File

@ -9,7 +9,7 @@ let
src = fetchgit {
url = https://github.com/appcelerator/KitchenSink.git;
rev = "6e9f509069fafdebfa78e15b2d14f20a27a485cc";
sha256 = "0370dc0ca78b96a7e0befbff9cb1c248695e1aff66aceea98043bbb16c5121e6";
sha256 = "049cf0d9y0ivhsi35slx621z0wry4lqf76hw0ksb315i2713v347";
};
# Rename the bundle id to something else

View File

@ -0,0 +1,42 @@
{stdenv, fetchurl, unzip, makeWrapper, python, jdk}:
stdenv.mkDerivation {
name = "mobilesdk-5.2.3.GA";
src = if (stdenv.system == "i686-linux" || stdenv.system == "x86_64-linux") then fetchurl {
url = http://builds.appcelerator.com/mobile/5_2_X/mobilesdk-5.2.3.v20160404160237-linux.zip;
sha256 = "1acvkj3nrkgf9ch4js0pnjnwq5x6ddc15pkcanshp1zlc41z16gj";
}
else if stdenv.system == "x86_64-darwin" then fetchurl {
url = http://builds.appcelerator.com/mobile/5_2_X/mobilesdk-5.2.3.v20160404160237-osx.zip;
sha256 = "04l7mrwiy3il2kzxz6sbfmczkqlkcrnwwndfzi8h5dzgh1672b7d";
}
else throw "Platform: ${stdenv.system} not supported!";
buildInputs = [ unzip makeWrapper ];
buildCommand = ''
mkdir -p $out
cd $out
(yes y | unzip $src) || true
# Rename ugly version number
cd mobilesdk/*
mv * 5.2.3.GA
cd *
# Hack to make dx.jar work with new build-tools
#sed -i -e "s|path.join(dir, 'platform-tools', 'lib', 'dx.jar')|path.join(dir, 'build-tools', 'android-6.0', 'lib', 'dx.jar')|" $out/mobilesdk/*/*/node_modules/titanium-sdk/lib/android.js
# Patch some executables
${if stdenv.system == "i686-linux" then
''
patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2 android/titanium_prep.linux32
''
else if stdenv.system == "x86_64-linux" then
''
patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2 android/titanium_prep.linux64
''
else ""}
'';
}