fix: php: handle deps without composer.json

Without composer.json in the root of a package,
composer will ignore the dependency, this is issue if
for example npm dependencies are managed via composer.
(yiisoft/yii2 2.0.46)
This commit is contained in:
Martin Toman 2022-09-19 12:15:30 -07:00
parent 685efe73de
commit 2a4dd11e44
2 changed files with 42 additions and 2 deletions

View File

@ -161,6 +161,12 @@
pushd $PKG_OUT
cp -r ${src}/* .
# create composer.json if does not exist
if [ ! -f composer.json ]
then
echo {\"name\":\"${name}\"} > composer.json
fi
# remove composer.lock if exists
rm -f composer.lock

View File

@ -76,6 +76,25 @@
args.packages
);
# Unpack dependency
cleanDependency = name: version:
stdenv.mkDerivation rec {
pname = "${l.strings.sanitizeDerivationName name}-source";
inherit version;
src = getSource name version;
dontConfigure = true;
buildPhase = ''
mkdir $out
cp -r ${src} $out
if [ ! -f $out/composer.json ]
then
echo {\"name\":\"${name}\"} > $out/composer.json
fi
'';
dontInstall = true;
dontFixup = true;
};
# Generates a derivation for a specific package name + version
makePackage = name: version: let
dependencies = getDependencies name version;
@ -89,7 +108,7 @@
intoRepository = dep: {
type = "path";
url = "${getSource dep.name dep.version}";
url = "${cleanDependency dep.name dep.version}";
options = {
versions = {
"${dep.name}" = "${dep.version}";
@ -102,6 +121,14 @@
l.toJSON
(repositories ++ [{packagist = false;}]);
dependenciesString = l.toJSON (l.listToAttrs (
map (dep: {
inherit (dep) name;
value = dep.version;
})
dependencies
));
versionString =
if version == "unknown"
then "0.0.0"
@ -136,13 +163,19 @@
# disable packagist, set path repositories
mv composer.json composer.json.orig
cat <<EOF >> $out/repositories.json
cat <<EOF > $out/repositories.json
${repositoriesString}
EOF
cat <<EOF > $out/dependencies.json
${dependenciesString}
EOF
jq \
--slurpfile repositories $out/repositories.json \
--slurpfile dependencies $out/dependencies.json \
"(.repositories = \$repositories[0]) | \
(.require = \$dependencies[0]) | \
(.\"require-dev\" = {}) | \
(.version = \"${versionString}\")" \
composer.json.orig > composer.json
@ -151,6 +184,7 @@
# cleanup
rm $out/repositories.json
rm $out/dependencies.json
popd
'';
installPhase = ''