Skip to content

Commit

Permalink
[SPARK-41377][BUILD] Fix spark-version-info.properties not found on W…
Browse files Browse the repository at this point in the history
…indows

### What changes were proposed in this pull request?

This PR enhances the Maven build configuration to automatically detect and switch between using Powershell for Windows and Bash for non-Windows OS to generate `spark-version-info.properties` file.

### Why are the changes needed?

While building Spark, the `spark-version-info.properties` file [is generated using bash](https://github.com/apache/spark/blob/d62c18b7497997188ec587e1eb62e75c979c1c93/core/pom.xml#L560-L564). In Windows environment, if Windows Subsystem for Linux (WSL) is installed, it somehow overrides the other bash executables in the PATH, as noted in SPARK-40739. The bash in WSL has a different mounting configuration and thus, [the target location specified for spark-version-info.properties](https://github.com/apache/spark/blob/d62c18b7497997188ec587e1eb62e75c979c1c93/core/pom.xml#L561-L562) won't be the expected location. Ultimately, this leads to `spark-version-info.properties` to get excluded from the spark-core jar, thus causing the SparkContext initialization to fail with the above depicted error message.

This PR fixes the issue by directing the build system to use the right shell according to the platform.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

I tested this by building on a Windows 10 PC.

```psh
mvn -Pyarn '-Dhadoop.version=3.3.0' -DskipTests clean package
```

Once the build finished, I verified that `spark-version-info.properties` file was included in the spark-core jar.

![image](https://user-images.githubusercontent.com/10280768/205497898-80e53617-c991-460e-b04a-a3bdd4f298ae.png)

I also ran the SparkPi application and verified that it ran successfully without any errors.

![image](https://user-images.githubusercontent.com/10280768/205499567-f6e8e10a-dcbb-45fb-b282-fc29ba58adee.png)

Closes apache#38903 from GauthamBanasandra/spark-version-info-ps.

Authored-by: Gautham Banasandra <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
  • Loading branch information
GauthamBanasandra authored and dongjoon-hyun committed Dec 9, 2022
1 parent 3212fa9 commit bd37b10
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ only_commits:
files:
- appveyor.yml
- dev/appveyor-install-dependencies.ps1
- build/spark-build-info.ps1
- R/
- sql/core/src/main/scala/org/apache/spark/sql/api/r/
- core/src/main/scala/org/apache/spark/api/r/
Expand Down
46 changes: 46 additions & 0 deletions build/spark-build-info.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This script generates the build info for spark and places it into the spark-version-info.properties file.
# Arguments:
# ResourceDir - The target directory where properties file would be created. [./core/target/extra-resources]
# SparkVersion - The current version of spark

param(
# The resource directory.
[Parameter(Position = 0)]
[String]
$ResourceDir,

# The Spark version.
[Parameter(Position = 1)]
[String]
$SparkVersion
)

$null = New-Item -Type Directory -Force $ResourceDir
$SparkBuildInfoPath = $ResourceDir.TrimEnd('\').TrimEnd('/') + '\spark-version-info.properties'

$SparkBuildInfoContent =
"version=$SparkVersion
user=$($Env:USERNAME)
revision=$(git rev-parse HEAD)
branch=$(git rev-parse --abbrev-ref HEAD)
date=$([DateTime]::UtcNow | Get-Date -UFormat +%Y-%m-%dT%H:%M:%SZ)
url=$(git config --get remote.origin.url)"

Set-Content -Path $SparkBuildInfoPath -Value $SparkBuildInfoContent
34 changes: 32 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,42 @@
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>choose-shell-and-script</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<exportAntProperties>true</exportAntProperties>
<target>
<condition property="shell" value="powershell.exe" else="bash">
<and>
<os family="windows"/>
</and>
</condition>
<condition property="spark-build-info-script" value="spark-build-info.ps1"
else="spark-build-info">
<and>
<os family="windows"/>
</and>
</condition>
<echo>Shell to use for generating spark-version-info.properties file =
${shell}
</echo>
<echo>Script to use for generating spark-version-info.properties file =
${spark-build-info-script}
</echo>
</target>
</configuration>
</execution>
<execution>
<id>generate-spark-build-info</id>
<phase>generate-resources</phase>
<configuration>
<!-- Execute the shell script to generate the spark build information. -->
<target>
<exec executable="bash">
<arg value="${project.basedir}/../build/spark-build-info"/>
<exec executable="${shell}">
<arg value="${project.basedir}/../build/${spark-build-info-script}"/>
<arg value="${project.build.directory}/extra-resources"/>
<arg value="${project.version}"/>
</exec>
Expand Down

0 comments on commit bd37b10

Please sign in to comment.