rattler-build icon indicating copy to clipboard operation
rattler-build copied to clipboard

`cmd.exe` stops execution prematurely

Open moritzwilksch opened this issue 1 year ago • 5 comments

Problem

I have a recipe using pnpm (wip over here) with a build script that calls a pnpm command. For the windows builds (on a local windows machine), the execution during the build process always stops after the first invocation of pnpm. For some reason, the issue can be circumvented by &&-ing all commands. I already tried messing with different end-of-line sequences but to no avail. The equivalent script on works on linux.

MRE

recipe/
  recipe.yaml
  build.bat
# build.bat 
pnpm --help

echo "Hello" > %PREFIX%\test.txt
# recipe.yaml
build:
  number: 0

package:
  name: mypackage
  version: 1.0.0

requirements:
  build:
    - pnpm
  host:
    - nodejs

tests:
  - package_contents:
      files:
        - test.txt

results in this (broken?) conda_build.bat:


@chcp 65001 > nul
@echo on
IF "%CONDA_BUILD%" == "" (
    @rem special behavior from conda-build for Windows
    call C:\Users\Administrator\mre\output\bld\rattler-build_mypackage_1730911077\work\build_env.bat
)
@rem re-enable echo because the activation scripts might have messed with it
@echo on

pnpm --help

echo "Hello" > %PREFIX%\test.txt

Fix?

# build.bat 
pnpm --help && echo "Hello" > %PREFIX%\test.txt

Results in this conda_bulid.bat:


@chcp 65001 > nul
@echo on
IF "%CONDA_BUILD%" == "" (
    @rem special behavior from conda-build for Windows
    call C:\Users\Administrator\mre\output\bld\rattler-build_mypackage_1730911013\work\build_env.bat
)
@rem re-enable echo because the activation scripts might have messed with it
@echo on

pnpm --help && echo "Hello" > %PREFIX%\test.txt

moritzwilksch avatar Nov 06 '24 16:11 moritzwilksch

Thanks, excellent bug report. No idea what's going on though! Is it possible for you to check the value of %error_level% or what that special variable is? And can you execute the bat file manually?

wolfv avatar Nov 06 '24 16:11 wolfv

We executed the bat file manually with the same result, i.e. the echo doesn't get called

pavelzw avatar Nov 06 '24 16:11 pavelzw

manually executed
C:\Users\Administrator\mre>c:\Users\Administrator\mre\output\bld\rattler-build_mypackage_1730911077\work\build_env.bat   

C:\Users\Administrator\mre>c:\Users\Administrator\mre\output\bld\rattler-build_mypackage_1730911077\work\conda_build.bat

C:\Users\Administrator\mre>pnpm --help
Version 9.12.2 (compiled to binary; bundled Node.js v22.9.0)
Usage: pnpm [command] [flags]
       pnpm [ -h | --help | -v | --version ]

Manage your dependencies:
      add                  Installs a package and any packages that it depends on. By default, any new package is installed as a prod dependency
      import               Generates a pnpm-lock.yaml from an npm package-lock.json (or npm-shrinkwrap.json) file
   i, install              Install all dependencies for a project
  it, install-test         Runs a pnpm install followed immediately by a pnpm test
  ln, link                 Connect the local project to another one
      prune                Removes extraneous packages
  rb, rebuild              Rebuild a package
  rm, remove               Removes packages from node_modules and from the project's package.json
      unlink               Unlinks a package. Like yarn unlink but pnpm re-installs the dependency after removing the external link
  up, update               Updates packages to their latest version based on the specified range

Review your dependencies:
      audit                Checks for known security issues with the installed packages
      licenses             Check licenses in consumed packages
  ls, list                 Print all the versions of packages that are installed, as well as their dependencies, in a tree-structure
      outdated             Check for outdated packages

Run your scripts:
      exec                 Executes a shell command in scope of a project
      run                  Runs a defined package script
      start                Runs an arbitrary command specified in the package's "start" property of its "scripts" object
   t, test                 Runs a package's "test" script, if one was provided

Other:
      cat-file             Prints the contents of a file based on the hash value stored in the index file
      cat-index            Prints the index file of a specific package from the store
      find-hash            Experimental! Lists the packages that include the file with the specified hash.
      pack                 Create a tarball from a package
      publish              Publishes a package to the registry
      root                 Prints the effective modules directory

Manage your store:
      store add            Adds new packages to the pnpm store directly. Does not modify any projects or files outside the store
      store path           Prints the path to the active store directory
      store prune          Removes unreferenced (extraneous, orphan) packages from the store
      store status         Checks for modified packages in the store

Options:
  -r, --recursive          Run the command for each project in the workspace.

C:\Users\Administrator\mre> echo %errorlevel%
0

C:\Users\Administrator\mre>

moritzwilksch avatar Nov 06 '24 17:11 moritzwilksch

Did we now decide that this is a user error and one should use CALL? :)

wolfv avatar Jan 31 '25 14:01 wolfv

This is actually standard windows behavior, i don't think this could be classified as a bug. Batch processing in windows supposed to work like this, thus why && works. You could also do something like:

`call pnpm --help

echo "Hello" > %PREFIX%\test.txt`

so adding call before pnpm for every pnpm command

zelosleone avatar Apr 05 '25 21:04 zelosleone