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

file.write doesn't exist in 2.2.5 contrary to the documentation #4044

Closed
cdhowie opened this issue Jul 19, 2024 · 6 comments
Closed

file.write doesn't exist in 2.2.5 contrary to the documentation #4044

cdhowie opened this issue Jul 19, 2024 · 6 comments
Labels

Comments

@cdhowie
Copy link

cdhowie commented Jul 19, 2024

Description

file.write is mentioned in the documentation, but after upgrading from 2.0.0 to 2.2.5, our script that uses file.write gives an error indicating that this function no longer exists:

At /etc/liquidsoap/script.liq, line 4, char 2-6:
  file.write(append=false, data="#{metadata.json.stringify(m)}\n", "/tmp/metadata.json")

Error 5: this value has no method `write`

Steps to reproduce

Use file.write in a script.

Expected behavior

The function call should succeed, or the function should not be listed in the documentation.

Liquidsoap version

Liquidsoap 2.2.5+dev
Copyright (c) 2003-2024 Savonet team
Liquidsoap is open-source software, released under GNU General Public License.
See <http://liquidsoap.info> for more information.

Liquidsoap build config

* Liquidsoap version  : 2.2.5+dev

 * Compilation options
   - Release build       : false
   - Git SHA             : (none)
   - OCaml version       : 5.2.0
   - OS type             : Unix
   - Libs versions       : angstrom=0.16.0 bigstringaf=0.9.1 bytes=[distributed with OCaml 4.02 or above] camlp-streams camomile.lib=2.0 cry=1.0.3 curl=0.9.2 dtools=0.4.5 dune-build-info=3.16.0 dune-private-libs.dune-section=3.16.0 dune-site=3.16.0 dune-site.private=3.16.0 duppy=0.9.4 ffmpeg-av=1.1.11 ffmpeg-avcodec=1.1.11 ffmpeg-avdevice=1.1.11 ffmpeg-avfilter=1.1.11 ffmpeg-avutil=1.1.11 ffmpeg-swresample=1.1.11 ffmpeg-swscale=1.1.11 fileutils=0.6.4 gen=1.1 lame=0.3.7 liquidsoap-lang=2.2.5 liquidsoap-lang.console=2.2.5 liquidsoap_builtins liquidsoap_core liquidsoap_ffmpeg liquidsoap_lame liquidsoap_mad liquidsoap_ogg liquidsoap_optionals liquidsoap_oss liquidsoap_runtime liquidsoap_samplerate liquidsoap_ssl liquidsoap_taglib liquidsoap_vorbis mad=0.5.3 magic-mime=1.3.1 menhirLib=20240715 metadata=0.3.0 mm=0.8.5 mm.audio=0.8.5 mm.base=0.8.5 mm.image=0.8.5 mm.midi=0.8.5 mm.video=0.8.5 ogg=0.7.4 ogg.decoder=0.7.4 pcre=7.5.0 ppx_string.runtime=v0.17.0 re=1.11.0 samplerate=0.1.6 sedlex=3.2 seq=[distributed with OCaml 4.07 or above] ssl=0.7.0 stdlib-shims=0.3.0 str=5.2.0 stringext=1.6.0 taglib=0.3.10 threads=5.2.0 unix=5.2.0 uri=4.4.0 vorbis=0.8.0 vorbis.decoder=0.8.0   
   - architecture        : amd64
   - host                : x86_64-pc-linux-gnu
   - target              : x86_64-pc-linux-gnu
   - system              : linux
   - ocamlopt_cflags     : -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -pthread
   - native_c_compiler   : gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -pthread -D_FILE_OFFSET_BITS=64
   - native_c_libraries  : -lm -lpthread

 * Configured paths
   - mode              : default
   - standard library  : (set by dune-site)
   - scripted binaries : (set by dune-site)
   - rundir            : (set by dune-site)
   - logdir            : (set by dune-site)
   - camomile files    : (set by dune-site)

 * Supported input formats
   - MP3               : yes
   - AAC               : no (requires faad)
   - Ffmpeg            : yes
   - Flac (native)     : no (requires flac)
   - Flac (ogg)        : no (requires ogg)
   - Opus              : no (requires opus)
   - Speex             : no (requires speex)
   - Theora            : no (requires theora)
   - Vorbis            : yes

 * Supported output formats
   - FDK-AAC           : no (requires fdkaac)
   - Ffmpeg            : yes
   - MP3               : yes
   - MP3 (fixed-point) : no (requires shine)
   - Flac (native)     : no (requires flac)
   - Flac (ogg)        : no (requires ogg)
   - Opus              : no (requires opus)
   - Speex             : no (requires speex)
   - Theora            : no (requires theora)
   - Vorbis            : yes

 * Tags
   - Taglib (ID3 tags) : yes
   - Vorbis            : yes

 * Input / output
   - ALSA              : no (requires alsa)
   - AO                : no (requires ao)
   - FFmpeg            : yes
   - GStreamer         : no (requires gstreamer)
   - JACK              : no (requires bjack)
   - OSS               : yes
   - Portaudio         : no (requires portaudio)
   - Pulseaudio        : no (requires pulseaudio)
   - SRT               : no (requires srt)

 * Audio manipulation
   - FFmpeg            : yes
   - LADSPA            : no (requires ladspa)
   - Lilv              : no (requires lilv)
   - Samplerate        : yes
   - SoundTouch        : no (requires soundtouch)
   - StereoTool        : no (requires ctypes-foreign)

 * Video manipulation
   - camlimages        : no (requires camlimages)
   - FFmpeg            : yes
   - frei0r            : no (requires frei0r)
   - ImageLib          : no (requires imagelib)
   - SDL               : no (requires tsdl-image & tsdl-ttf)

 * MIDI manipulation
   - DSSI              : no (requires dssi)

 * Visualization
   - GD                : no (requires gd)
   - Graphics          : no (requires graphics)
   - SDL               : no (requires tsdl-image & tsdl-ttf)

 * Additional libraries
   - FFmpeg filters    : yes
   - FFmpeg devices    : yes
   - inotify           : no (requires inotify)
   - irc               : no (requires irc-client-unix)
   - jemalloc          : no (requires jemalloc)
   - lastfm            : no (requires lastfm)
   - lo                : no (requires lo)
   - memtrace          : no (requires memtrace)
   - mem_usage         : no (requires mem_usage)
   - osc               : no (requires osc-unix)
   - ssl               : yes
   - tls               : no (requires tls-liquidsoap)
   - posix-time2       : no (requires posix)
   - windows service   : no (requires winsvc)
   - YAML support      : no (requires yaml)
   - XML playlists     : no (requires xmlplaylist)

 * Monitoring
   - Prometheus        : no (requires prometheus)

Installation method

From OPAM

Additional Info

No response

@cdhowie cdhowie added the bug label Jul 19, 2024
@toots
Copy link
Member

toots commented Jul 19, 2024

Hi!

Most likely, you have a variable named file in your script that overrides the top-level file module.

This is an issue we're seeing more and more. I plan on looking at adding a warning when encountering such situation.

@cdhowie
Copy link
Author

cdhowie commented Jul 19, 2024

We don't have any variable named file. The error message also dumps the type of file which includes many other functions listed in the documentation:

Error 5: this value has no method `write`
  Its type is {
  copy : (?recursive : bool, ?force : bool, ?preserve : bool, string, string) ->
         unit,
  digest : (string) -> string,
  exists : (string) -> bool,
  extension : (?dir_sep : string, ?leading_dot : bool, string) -> string,
  is_directory : (string) -> bool,
  ls : (?absolute : bool, ?recursive : bool, ?pattern : string?,
        ?sorted : bool, string) -> [string],
  metadata : ((string, ?exclude : [string]) -> [string * string])
  .{
    ffmpeg : (string) -> [string * string],
    flac_native : (string) -> [string * string],
    id3 : (string) -> [string * string],
    id3v1 : (string) -> [string * string],
    id3v2 : (string) -> [string * string],
    image : (string) -> [string * string],
    native : (string) -> [string * string],
    ogg : (string) -> [string * string],
    ogg_native : (string) -> [string * string],
    taglib : (string) -> [string * string],
    video-metadata : (string) -> [string * string]
  },
  mime :
  {magic : (string) -> string
  },
  mkdir : (?perms : int, string) -> unit,
  move : (?force : bool, string, string) -> unit,
  mtime : (string) -> float,
  open : (?write : bool, ?create : bool?, ?append : bool,
          ?non_blocking : bool, ?perms : int, string) -> socket
         .{
           close : () -> unit,
           non_blocking : (bool) -> unit,
           read : ((?timeout : float?) -> string)
           .{wait : (?timeout : float?, (() -> unit)) -> unit
           },
           type : string,   
           write : ((?timeout : float?, string) -> unit)
           .{wait : (?timeout : float?, (() -> unit)) -> unit
           }},
  remove : (string) -> unit,
  rmdir : (string) -> unit, 
  size : (string) -> int,   
  temp : (string, string) -> string,
  temp_dir : (string, ?string) -> string,
  umask : (() -> int)
  .{set : (int) -> unit
  },
  watch : (string, (() -> unit)) -> {unwatch : () -> unit},
  which : (string) -> string?
}.

write is just absent, and so is read. There may be other missing functions but I haven't done a thorough check against the documentation. These are just the two I noticed.

@vitoyucepi
Copy link
Collaborator

Hi @cdhowie,
Something is wrong with stdlib.
Could you please share the results of

  1. find . -name file.liq.
    To find the source code of file functions.
    I'm located in the home directory. For me, it looks like:
    ./.opam/5.2.0/.opam-switch/sources/liquidsoap-libs-extra.2.2.5/tests/language/file.liq
    ./.opam/5.2.0/.opam-switch/sources/liquidsoap-libs-extra.2.2.5/src/libs/extra/file.liq
    ./.opam/5.2.0/.opam-switch/sources/liquidsoap-libs-extra.2.2.5/src/libs/file.liq
    ./.opam/5.2.0/.opam-switch/sources/liquidsoap-lang.2.2.5/tests/language/file.liq
    ./.opam/5.2.0/.opam-switch/sources/liquidsoap-lang.2.2.5/src/libs/extra/file.liq
    ./.opam/5.2.0/.opam-switch/sources/liquidsoap-lang.2.2.5/src/libs/file.liq
    ./.opam/5.2.0/.opam-switch/sources/liquidsoap-libs.2.2.5/tests/language/file.liq
    ./.opam/5.2.0/.opam-switch/sources/liquidsoap-libs.2.2.5/src/libs/extra/file.liq
    ./.opam/5.2.0/.opam-switch/sources/liquidsoap-libs.2.2.5/src/libs/file.liq
    ./.opam/5.2.0/share/liquidsoap-lang/libs/extra/file.liq
    ./.opam/5.2.0/share/liquidsoap-lang/libs/file.liq
    
  2. lsb_release -a.

@cdhowie
Copy link
Author

cdhowie commented Jul 20, 2024

Ah, I did not realize that these files didn't get bundled with the final executable, so that was a wrong assumption on my part. I will close the issue.

If I was looking to remove all of the development dependencies after building, is there a single directory that I would be able to keep somewhere on the filesystem and toss everything else? I am attempting to optimize the size of the docker image (pltnk/docker-liquidsoap#20) as the dev dependencies leave GBs of cruft laying around. (If you do know the answer and would prefer to continue discussion on that pull request instead of here, that would be totally understandable.)

Sorry for the noise!

@toots
Copy link
Member

toots commented Jul 20, 2024

Ha that makes sense. We were discussing working out a more detailed build guide actually!

@vitoyucepi wrote a detailed one here: #3609

We currently support 3 types of directory locations:

  • as provided by dune, the default
  • the posix layout (/usr/bin and etc)
  • standalone

LIQUIDSOAP_BUILD_TARGET can be used to set this mode during build for instance, for standalone:

% LIQUIDSOAP_BUILD_TARGET=standalone dune build
...
 * Configured paths
   - mode              : standalone
   - standard library  : ./libs
   - scripted binaries : ./bin
   - rundir            : ./run
   - logdir            : ./log
   - user cache        : ./cache (override with $LIQ_CACHE_USER_DIR)
   - system cache      : ./cache (override with $LIQ_CACHE_SYSTEM_DIR)
   - camomile files    : ./camomile
 ...

This is the build mode for windows so you can follow the build script for what to do next:

cp -rf "${BASE_DIR}/_build/default/src/bin/liquidsoap.exe "liquidsoap-$BUILD/liquidsoap"
cp -rf "${BASE_DIR}/src/libs" "liquidsoap-$BUILD"
cp -rf "$(ocamlfind -toolchain windows ocamlc -where)/../../share/camomile" "liquidsoap-$BUILD"

Of course you will also need the shared libraries unless you are able to build a static binary (which is the case on windows)

Here's the posix mode:

% LIQUIDSOAP_BUILD_TARGET=posix dune build
...
 * Configured paths
   - mode              : posix
   - standard library  : /usr/share/liquidsoap/libs
   - scripted binaries : /usr/share/liquidsoap/bin
   - rundir            : /var/run/liquidsoap
   - logdir            : /var/log/liquidsoap
   - user cache        : $HOME/.cache/liquidsoap (override with $LIQ_CACHE_USER_DIR)
   - system cache      : /var/cache/liquidsoap (override with $LIQ_CACHE_SYSTEM_DIR)
   - camomile files    : /usr/share/liquidsoap/camomile
   ...

I'm not sure if we still have scripted binaries.. We used to but I think nowadays its mostly all internal.

@cdhowie
Copy link
Author

cdhowie commented Jul 20, 2024

Very useful info, thanks!

Of course you will also need the shared libraries unless you are able to build a static binary

Right, the two-stage build I did installed the necessary runtime dependencies in the second stage, so that was sorted. I just didn't realize there was other stuff on the filesystem that liquidsoap needed to function.

I'll give this another read tomorrow or next week when I'm ready to resume work on it and will see if I can't get the two-stage build working correctly then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants