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

preConfigureScript autogen.sh error: 'configure.ac' is required #669

Open
sysescool opened this issue Nov 5, 2024 · 13 comments
Open

preConfigureScript autogen.sh error: 'configure.ac' is required #669

sysescool opened this issue Nov 5, 2024 · 13 comments
Labels
bug Something isn't working Feature: Pre/Post Configure Script Related to the pre/post-configure scripts and arguments features more upvotes needed More upvotes from the community are needed for us to prioritize this.
Milestone

Comments

@sysescool
Copy link

I get a project, and this is my settings.json:

{
    "makefile.preConfigureScript": "${workspaceFolder}/autogen.sh",
    // I also tried the below, but the same error.
    // "makefile.preConfigureScript": "./autogen.sh",
}

Then, I click Makefile: Pre-Configure, but thes is error:

Pre-configuring...
Script: "/home/xxx/xf86-video-dummy/autogen.sh"
/home/xxx/xf86-video-dummy
/bin/bash
/bin
autoreconf: export WARNINGS=
autoreconf: error: 'configure.ac' is required
The pre-configure script failed. This project may not configure successfully.

If I run cd /home/xxx/xf86-video-dummy && ./autogen.sh, it indeed works.

there is autogen.sh, for test I modify it:

#! /bin/sh
   # run in terminal: /home/xxx/xf86-video-dummy
   # run in vscode: /home/xxx/xf86-video-dummy
   pwd
   # run in terminal: ./autogen.sh
   # run in vscode: /bin/bash
   echo $0

srcdir=`dirname "$0"`
   # run in terminal: .
   # run in vscode: /bin
   echo ${srcdir}

test -z "$srcdir" && srcdir=.

ORIGDIR=`pwd`
cd "$srcdir"

autoreconf -v --install || exit 1     # error in this line.
cd "$ORIGDIR" || exit $?

git config --local --get format.subjectPrefix >/dev/null 2>&1 ||
    git config --local format.subjectPrefix "PATCH xf86-video-dummy"

if test -z "$NOCONFIGURE"; then
    exec "$srcdir"/configure "$@"
fi

I think this about work path or something about path, but I search a lot, still do not fix it.

@github-actions github-actions bot added the triage label Nov 5, 2024
@gcampbell-msft
Copy link
Collaborator

@sysescool Could you give some more context on how your project is setup? Where is the configure.ac located?

Any information about how we could most easily reproduce this would be great. Thanks!

@Yingzi1234 FYI.

@sysescool
Copy link
Author

sysescool commented Nov 7, 2024

@gcampbell-msft @Yingzi1234

Yes, I will give you more context:

cd $HOME/Music
git clone https://gitlab.freedesktop.org/xorg/driver/xf86-video-dummy.git
cd xf86-video-dummy
tree

and the tree show below:

.
├── autogen.sh
├── configure.ac
├── COPYING
├── Makefile.am
├── README.md
└── src
    ├── dummy_cursor.c
    ├── dummy_driver.c
    ├── dummy.h
    └── Makefile.am

still in xf86-video-dumy folder:

mkdir .vscode
vim .vscode/settings.json

and the settings.json:

{
    "makefile.preConfigureScript": "${workspaceFolder}/autogen.sh",
}

still in xf86-video-dumy foler:

code .

Then Click Makefile in Sidebar -> Click Icon "..." -> Click "Makefile: Pre-Configure".
and the Output:

No current configuration is defined in the workspace state. Assuming 'Default'.
No target defined in the workspace state. Assuming 'Default'.
Dropping various extension output files at /home/qch/.config/Code/User/workspaceStorage/e2cd92175954da71ad97920d7e19011e/ms-vscode.makefile-tools
Logging level: Normal
Configurations cached at /home/qch/.config/Code/User/workspaceStorage/e2cd92175954da71ad97920d7e19011e/ms-vscode.makefile-tools/configurationCache.log
No path to the makefile is defined in the settings file.
No folder path to the makefile is defined in the settings file.
Expanding from '${workspaceFolder}/autogen.sh' to '/home/qch/Music/xf86-video-dummy/autogen.sh' for setting 'preConfigureScript'.
Found pre-configure script defined as /home/qch/Music/xf86-video-dummy/autogen.sh
Always pre-configure: false
Always post-configure: false
Dry-run switches: '--always-make', '--keep-going', '--print-directory'
No current launch configuration is set in the workspace state.
Default launch configuration: MIMode = undefined,
                miDebuggerPath = undefined,
                stopAtEntry = undefined,
                symbolSearchPath = undefined
Configure on open: null
Configure on edit: true
Configure after command: true
Only .PHONY targets: false
Save before build or configure: true
Build before launch: true
Clear output before build: true
Ignore directory commands: true
compile_commands.json path: null
Deduced command 'make ' for configuration "Default"
The makefile entry point was not found. Make sure it exists at the location defined by makefile.makefilePath, makefile.configurations[].makefilePath, makefile makefile.makeDirectory, makefile.configurations[].makeDirectory or in the root of the workspace.
Pre-configuring...
Script: "/home/qch/Music/xf86-video-dummy/autogen.sh"
autoreconf: export WARNINGS=
autoreconf: error: 'configure.ac' is required
The pre-configure script failed. This project may not configure successfully.

However, If you cd $HOME/Music/xf86-video-dummy && ./autogen.sh, it works.

I try to debug it in autogen.sh, then I modify it as above.

Notice that: the path is different. But I don't know how to fix it.

The problem is: when autogen.sh is running, the $0 is different from vscode plugin run and terminal run.

autogen.sh:

#! /bin/sh
   # run in terminal: /home/xxx/xf86-video-dummy
   # run in vscode: /home/xxx/xf86-video-dummy
   pwd

   # run in terminal: ./autogen.sh
   # run in vscode: /bin/bash
   echo $0

srcdir=`dirname "$0"`
   # run in terminal: .
   # run in vscode: /bin
   echo ${srcdir}

test -z "$srcdir" && srcdir=.

ORIGDIR=`pwd`
cd "$srcdir"

autoreconf -v --install || exit 1     # error in this line.
cd "$ORIGDIR" || exit $?

@Yingzi1234
Copy link
Collaborator

Yingzi1234 commented Nov 8, 2024

@sysescool I apologize for taking so long to respond to your question. Could you try following the steps below and then check if it solves your problem?

  1. Modify the autogen.sh script to ensure it runs from the correct directory
    You need to ensure that the autogen.sh script can always find the configure.ac file, whether running in VSCode or the terminal. Modify the script to always execute from the directory where the script is located:
#!/bin/sh

# Change to the script's directory
cd "$(dirname "$0")" || exit 1  # Go to the script's directory
pwd  # Print the current directory for debugging

# Run autoreconf
autoreconf -v --install || exit 1

# Go back to the original directory
cd "$ORIGDIR" || exit $?
cd "$(dirname "$0")" ensures the script runs from the correct directory, independent of the $0 value.
  1. Ensure VSCode is using the correct working directory
    In your settings.json, configure VSCode to set the terminal's working directory correctly when running autogen.sh:
{
    "makefile.preConfigureScript": "${workspaceFolder}/autogen.sh",
    "terminal.integrated.cwd": "${workspaceFolder}"
}
  1. Debug the autogen.sh script's path issues
    Add debug output to autogen.sh to check the current directory and the script path:
#!/bin/sh

echo "Current directory before cd: $(pwd)"
echo "Script location: $(dirname "$0")"
cd "$(dirname "$0")" || exit 1
echo "Current directory after cd: $(pwd)"

autoreconf -v --install || exit 1
  1. Manually run autogen.sh to confirm terminal behavior
    Run the script manually to verify it works in the terminal:
cd /home/qch/Music/xf86-video-dummy
./autogen.sh
  1. Check Makefile configuration
    Ensure that your Makefile is properly set up and that VSCode has a valid build target. If there's no build target defined, VSCode might show some warnings.

Make sure your Makefile has at least a basic target:

all:
    echo "Hello, world!"

@Yingzi1234 Yingzi1234 added more info needed More info is needed from the community for us to properly triage and investigate and removed triage labels Nov 8, 2024
@sysescool
Copy link
Author

Thank your response.

  1. I won't try to modify autogen.sh. because it's from upstream, modify the source repo more, more conflicts will be met. Lots of GNU Project with that format autogen.sh, so If we compromise, then any autogen.sh of GNU library will need to be changed during configuration. This doesn't make sense.
  2. I have tried this: "terminal.integrated.cwd": "${workspaceFolder}". According to https://code.visualstudio.com/docs/terminal/basics#_working-directory. But seems like makefile.preConfigureScript doesn't follow it.
  3. I have given the answer to this before. Whether or not to add "terminal.integrated.cwd": "${workspaceFolder}", the result is the same as below:
#! /bin/sh
   # run in terminal: /home/xxx/xf86-video-dummy
   # run in vscode: /home/xxx/xf86-video-dummy
   pwd
   # run in terminal: ./autogen.sh
   # run in vscode: /bin/bash
   echo $0

srcdir=`dirname "$0"`
   # run in terminal: .
   # run in vscode: /bin
   echo ${srcdir}
  1. Yes, It works as I answer before.
  2. This has nothing to do with make. If you know autotools,the correct order is: ./autogen.sh -> automake -> ./configure -> make or make install.

Forgive my frankness. Do not copy from ChatGPT or Other AI, Your answer is very similar to the answer the AI ​​gave me.

You can see that:

  1. the pwd in autogen.sh is the same
  2. the $0 is not.

At the reminder of a colleague: cat autogen.sh | /bin/bash, this will output: /bin/bash.
So I think it's the bug of vscode-makefile-tools. Plugin run autogen.sh maybe just like: cat autogen.sh | /bin/bash

@sysescool
Copy link
Author

https://github.com/microsoft/vscode-makefile-tools/blob/46aff6cc72977fd626f6135f2b11c0acdf95002f/src/make.ts#L1213C1-L1248C2

seems like there, call the script. But I know typescript and vscode plugin api nothing.

@Yingzi1234
Copy link
Collaborator

@sysescool Based on the above steps you provided, we can reproduce your problem, we noticed that you fail after running the Makefile:pre-configure command, the reason for the failure may be that there is no preConfigureScript.sh file in the project, if you follow the steps below to add its path to the setup and then run the command "Makefile: pre-configure", it will succeed.
@gcampbell-msft FYI

  1. Create a preConfigureScript.sh file and paste the below code to this file
    echo "PRECONFIGURE" ${1}

  2. Copy the path and paste it to the Makefile: pre configure script Setting

Image

@Yingzi1234
Copy link
Collaborator

@gcampbell-msft After opening the project we realize that we can't select the values for Build target and Launch target because the Makefile option shows (not found) but there are actually no values in the setup, is this a issue?
Image

@sysescool
Copy link
Author

sysescool commented Nov 15, 2024

@Yingzi1234

Hi, what you need to test is ${0} not ${1}.

echo "PRECONFIGURE" ${0}

run ./preConfigureScript.sh or /bin/bash ./preConfigureScript.sh in terminal, have result:

PRECONFIGURE ./preConfigureScript.sh

run by plugin, have result:

PRECONFIGURE /bin/bash

@gcampbell-msft

@Yingzi1234
Copy link
Collaborator

Yingzi1234 commented Nov 15, 2024

Hi @sysescool If change {1} to {0}, also can get the following successful result. Has your problem been solved by the above steps?
Image

@sysescool
Copy link
Author

sysescool commented Nov 16, 2024

@Yingzi1234

Please scroll up, find the output:
PRECONFIGURE $0
and find out what is $0 print.

Then please
run ./preConfigureScript.sh or /bin/bash ./preConfigureScript.sh in the terminal
and find out what is $0 print.

@sysescool
Copy link
Author

Let me explain below picture.
The left in the picture shows the output of running preConfigureScript.sh in the vscode plugin.
The right in the picture shows the output of running preConfigureScript.sh in the terminal.

Image

I hope you understand, they are different !!!!

The value of $0 run in terminal and run in plugin is different !!!!
The value of $0 run in terminal and run in plugin is different !!!!
The value of $0 run in terminal and run in plugin is different !!!!

You should not focus on the "Configure succeeded." All the things preConfigureScript.sh done is just print, or output. No matter how it's always success! Always!

Please focus on the value of $0.


Why the autogen.sh in the project xf86-video-dummy failed?
It's because the autogen.sh use the value of $0, but: The value of $0 run in terminal and run in plugin is different !!!!

If you don't understand $0, please read that https://unix.stackexchange.com/questions/280454/what-is-the-meaning-of-0-in-the-bash-shell.

We write program in script, and the program in script depends on the $0 as an input.
If the input is different, the script depends on the $0 will not work well and will produce the different output.


Let the $0 output run in vscode as same as run it in terminal.

I hope you could fix this.

I Enjoy using your plugin and hope it gets better.

@Yingzi1234
Copy link
Collaborator

Yingzi1234 commented Nov 20, 2024

@gcampbell-msft We can reproduce this issue on latest Makefile tools version v0.12.10(pre-release), you can get the details below. Thank you!

Issue: The output of the preConfigureScript.sh file is not the same in vscode as it is in terminal.

Platform: Linux

Repro steps:

  1. Clone this repo https://gitlab.freedesktop.org/xorg/driver/xf86-video-dummy.git
  2. Open it with VSCode
  3. Create a file named "preConfigureScript.sh" and paste the below code
echo "PRECONFIGURE" $0
SRCDIR=`DIRNAME "$0"`
echo $srcdir
  1. Run command: Makefile: pre-configure
  2. Repeat steps 1-5 above, with terminal

Actual result:
Image

@Yingzi1234 Yingzi1234 added bug Something isn't working and removed more info needed More info is needed from the community for us to properly triage and investigate labels Nov 20, 2024
@gcampbell-msft
Copy link
Collaborator

@sysescool @Yingzi1234 Thank you both for the in-depth investigation! This is expected, as this is by design in the source code.

We create a wrapper around the script so that we can add some scripting that gets the environment after the execution of the users script, and then apply it to the environment so that the preConfigureScript actions actually take effect.

However, this seems to be breaking something in this case. Is there a way that you can modify your scripting in order to make this work? Otherwise, we would have to brainstorm how else to get the environment after execution in order to update the Makefile Tools environment.

You can see the code starting here:

// Create a temporary wrapper for the user pre-configure script so that we collect

@gcampbell-msft gcampbell-msft added this to the Backlog milestone Dec 4, 2024
@gcampbell-msft gcampbell-msft added Feature: Pre/Post Configure Script Related to the pre/post-configure scripts and arguments features more upvotes needed More upvotes from the community are needed for us to prioritize this. labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Feature: Pre/Post Configure Script Related to the pre/post-configure scripts and arguments features more upvotes needed More upvotes from the community are needed for us to prioritize this.
Projects
None yet
Development

No branches or pull requests

3 participants