Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Conflict with escript #113

@sheepduke

Description

@sheepduke

When bakeware and escript are used at the same time, the generated application will invoke main function twice.

How to reproduce

Taking the simple_script as an example.

Modify mix.exs by adding escript settings, as follows:

defmodule SimpleScript.MixProject do
  use Mix.Project

  @app :simple_script

  def project do
    [
      app: @app,
      version: "0.1.0",
      elixir: "~> 1.10",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      releases: [{@app, release()}],
      escript: escript(), # <-- !! newly added
      preferred_cli_env: [release: :prod]
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger],
      mod: {SimpleScript, []}
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:bakeware, path: "../..", runtime: false}
    ]
  end

  defp release do
    [
      overwrite: true,
      cookie: "#{@app}_cookie",
      quiet: true,
      steps: [:assemble, &Bakeware.assemble/1],
      strip_beams: Mix.env() == :prod
    ]
  end

  # !! newly added
  defp escript do
    [main_module: SimpleScript]
  end
end

After running mix escript.build, you can get the following result:

~/workspace/bakeware/examples/simple_script $ ./simple_script
Pass me some arguments and I will upcase them if you specify --upcase
Pass me some arguments and I will upcase them if you specify --upcase

Questions

My understanding is that when the program starts, module specified by mod is executed, then escript invokes the main function second time.

Now my questions are:

  1. Is it unexpected behavior?
  2. Is there any workaround to bypass it? (Maybe using another option instead of mod?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions