diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index b4db2e7..71656c0 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -1,4 +1,4 @@ -name: ubuntu +name: build-and-release on: push: @@ -11,8 +11,6 @@ jobs: build: name: Build LaTeXML snap runs-on: ubuntu-latest - container: - image: snapcore/snapcraft:stable steps: - uses: actions/checkout@v3 diff --git a/README.adoc b/README.adoc index 3f72a33..65b1750 100644 --- a/README.adoc +++ b/README.adoc @@ -1,4 +1,4 @@ -image:https://github.com/metanorma/latexml-snap/workflows/ubuntu/badge.svg["Build Status", link="https://github.com/metanorma/latexml-snap/actions?query=workflow%3Aubuntu"] +image:https://github.com/metanorma/latexml-snap/workflows/build-and-release/badge.svg["Build Status", link="https://github.com/metanorma/latexml-snap/actions?query=workflow%3Abuild-and-release"] = latexml-snap: LaTeXML Snap Package diff --git a/snap/plugins/cpanm.py b/snap/plugins/cpanm.py deleted file mode 100644 index bc00051..0000000 --- a/snap/plugins/cpanm.py +++ /dev/null @@ -1,77 +0,0 @@ -import snapcraft -import logging - -import os -import shutil -import urllib.request - -logger = logging.getLogger(__name__) - - -class CpanmPlugin(snapcraft.BasePlugin): - - @classmethod - def schema(cls): - schema = super().schema() - - schema['properties']['cpanm-packages'] = { - 'type': 'array', - } - schema['properties']['run-test'] = { - 'type': 'boolean', - 'default': False - } - - schema['properties']['verbose'] = { - 'type': 'boolean', - 'default': False - } - - schema['required'] = ['cpanm-packages'] - - return schema - - def __init__(self, name, options, project): - super().__init__(name, options, project) - - self.stage_packages.extend(['perl', 'perl-base']) - self.build_packages.extend(['perl', 'build-essential']) - - self._install_cmd = ['cpanm'] - - if self.options.verbose: - self._install_cmd.append('--verbose') - - if not self.options.run_test: - self._install_cmd.append('--notest') - - def pull(self): - super().pull() - cpanm_pl = os.path.join(self.sourcedir, 'cpanminus.pl') - urllib.request.urlretrieve('http://cpanmin.us', cpanm_pl) - - self.run(['perl', '--', cpanm_pl, 'App::cpanminus']) - - def build(self): - super().build() - - for module in self.options.cpanm_packages: - self.run(self._install_cmd[:] + [module]) - - perl_inc = self.run_output(['perl', '-e', 'print "@INC"']) - perl_snap_inc = [] - for inc_path in perl_inc.split(): - if inc_path != ".": - perl_snap_inc.append('$SNAP' + inc_path) - - perl5lib_sh = os.path.join(self.installdir, - 'usr', 'bin', 'perl5lib.sh') - with open(perl5lib_sh, "w") as text_file: - text_file.write( - "env PERL5LIB={} env PATH=$SNAP/usr/local/bin:$PATH $@" - .format(':'.join(perl_snap_inc))) - - # cpanm install modules to `/usr/local` by default - # unfortunatelly no best solution was found - shutil.copytree('/usr/local', - os.path.join(self.installdir, 'usr', 'local')) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index e3932c9..7cf0c21 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -10,23 +10,48 @@ confinement: strict parts: latexml: - plugin: cpanm - cpanm-packages: ['XML::LibXSLT@1.96', LaTeXML@$SNAPCRAFT_PROJECT_VERSION] - build-packages: [libxml2-dev, libxslt1-dev, libicu-dev, zlib1g-dev] - stage-packages: [libxml2, libxslt1.1, zlib1g] - override-stage: | - snapcraftctl stage - chmod 0755 ./usr/local/share/sgml - chmod 0755 ./usr/local/share/sgml/declaration - chmod 0755 ./usr/local/share/sgml/dtd - chmod 0755 ./usr/local/share/sgml/entities - chmod 0755 ./usr/local/share/sgml/misc - chmod 0755 ./usr/local/share/sgml/stylesheet - chmod 0755 ./usr/local/share/xml - chmod 0755 ./usr/local/share/xml/declaration - chmod 0755 ./usr/local/share/xml/entities - chmod 0755 ./usr/local/share/xml/misc - chmod 0755 ./usr/local/share/xml/schema + plugin: nil + source: . + override-pull: | + apt update + apt install -y curl perl build-essential + curl -o cpanminus.pl http://cpanmin.us + perl -- cpanminus.pl App::cpanminus + + override-build: | + apt update + apt install -y libxml2-dev libxslt1-dev libicu-dev zlib1g-dev + + # Install cpanm packages + cpanm_packages=("XML::LibXSLT@1.96" "LaTeXML@$SNAPCRAFT_PROJECT_VERSION") + for pkg in "${cpanm_packages[@]}"; do + cpanm --notest "$pkg" + done + + # Modify perl5lib.sh + perl_inc=$(perl -e 'print "@INC"') + perl_snap_inc=() + + for incpath in $(perl -e 'print "@INC"'); do + if [ "$incpath" != "." ]; then + perl_snap_inc+=("$SNAP$incpath") + fi + done + + perl5lib_sh="/usr/bin/perl5lib.sh" + echo "env PERL5LIB=$(IFS=:; echo "${perl_snap_inc[*]}") env PATH=$SNAP/usr/local/bin:$PATH \$@" > "$perl5lib_sh" + chmod +x "$perl5lib_sh" + + organize: + /usr/bin/perl5lib.sh: /usr/bin/perl5lib.sh + /usr/local: /usr/local + + stage-packages: + - libicu66 + - libxml2 + - libxslt1.1 + - zlib1g + apps: latexml: environment: