Skip to content

Commit fd9c40f

Browse files
committed
fix: Omit hash to make shebangs stable
1 parent bead3d6 commit fd9c40f

File tree

9 files changed

+25
-20
lines changed

9 files changed

+25
-20
lines changed

embed_util/embedded_files.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ type EmbeddedFiles struct {
1818

1919
func NewEmbeddedFiles(embedFs fs.FS, name string) (*EmbeddedFiles, error) {
2020
tmpDir := filepath.Join(os.TempDir(), fmt.Sprintf("go-embedded-%s", name))
21-
return NewEmbeddedFilesWithTmpDir(embedFs, tmpDir)
21+
return NewEmbeddedFilesWithTmpDir(embedFs, tmpDir, true)
2222
}
2323

24-
func NewEmbeddedFilesWithTmpDir(embedFs fs.FS, tmpDir string) (*EmbeddedFiles, error) {
24+
func NewEmbeddedFilesWithTmpDir(embedFs fs.FS, tmpDir string, withHashInDir bool) (*EmbeddedFiles, error) {
2525
e := &EmbeddedFiles{
2626
tmpDir: tmpDir,
2727
}
28-
err := e.extract(embedFs)
28+
err := e.extract(embedFs, withHashInDir)
2929
if err != nil {
3030
return nil, err
3131
}
@@ -45,16 +45,19 @@ func (e *EmbeddedFiles) GetExtractedPath() string {
4545
return e.extractedPath
4646
}
4747

48-
func (e *EmbeddedFiles) extract(embedFs fs.FS) error {
48+
func (e *EmbeddedFiles) extract(embedFs fs.FS, withHashInDir bool) error {
4949
fl, err := e.readOrBuildFileList(embedFs)
5050
if err != nil {
5151
return err
5252
}
5353

5454
flHash := fl.Hash()
5555

56-
e.extractedPath = fmt.Sprintf("%s-%s", e.tmpDir, flHash[:16])
57-
56+
if withHashInDir {
57+
e.extractedPath = fmt.Sprintf("%s-%s", e.tmpDir, flHash[:16])
58+
} else {
59+
e.extractedPath = e.tmpDir
60+
}
5861
err = os.MkdirAll(filepath.Dir(e.extractedPath), 0o755)
5962
if err != nil {
6063
return err

pip/embed_pip_packages.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ func CreateEmbeddedPipPackagesForKnownPlatforms(requirementsFile string, targetD
3838
func CreateEmbeddedPipPackages(requirementsFile string, goOs string, goArch string, pipPlatform string, targetDir string) error {
3939
name := fmt.Sprintf("pip-%d", rand.Uint32())
4040

41+
// ensure we have a stable extract path for the python distribution (otherwise shebangs won't be stable)
4142
tmpDir := filepath.Join("/tmp", fmt.Sprintf("python-pip-%s-%s-%s", goOs, goArch, pipPlatform))
42-
ep, err := python.NewEmbeddedPythonWithTmpDir(tmpDir)
43+
ep, err := python.NewEmbeddedPythonWithTmpDir(tmpDir, false)
4344
if err != nil {
4445
return err
4546
}

pip/internal/data/bin/pip

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/tmp/python-pip-bootstrap-5c6cf816674ccbfc/bin/python3
1+
#!/tmp/python-pip-bootstrap/bin/python3
22
# -*- coding: utf-8 -*-
33
import re
44
import sys

pip/internal/data/bin/pip3

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/tmp/python-pip-bootstrap-5c6cf816674ccbfc/bin/python3
1+
#!/tmp/python-pip-bootstrap/bin/python3
22
# -*- coding: utf-8 -*-
33
import re
44
import sys

pip/internal/data/bin/pip3.10

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/tmp/python-pip-bootstrap-5c6cf816674ccbfc/bin/python3
1+
#!/tmp/python-pip-bootstrap/bin/python3
22
# -*- coding: utf-8 -*-
33
import re
44
import sys

pip/internal/data/files.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"contentHash": "ddb6050d1e62d6a81c9438bd4118e8055173643010027a560d90f18677aaef72",
2+
"contentHash": "3f6de938b00ecbf872b793f2706363826bd3dafbfcd6aff02416fcf8a0aa37f4",
33
"files": [
44
{
55
"name": "bin",
@@ -8,17 +8,17 @@
88
},
99
{
1010
"name": "bin/pip",
11-
"size": 259,
11+
"size": 242,
1212
"perm": 493
1313
},
1414
{
1515
"name": "bin/pip3",
16-
"size": 259,
16+
"size": 242,
1717
"perm": 493
1818
},
1919
{
2020
"name": "bin/pip3.10",
21-
"size": 259,
21+
"size": 242,
2222
"perm": 493
2323
},
2424
{

pip/internal/data/pip-22.2.2.dist-info/RECORD

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
../../bin/pip,sha256=jCQZi6-1GMDo6yUEXEUko3I_Pft-OiueRN9OXP5n3rw,259
2-
../../bin/pip3,sha256=jCQZi6-1GMDo6yUEXEUko3I_Pft-OiueRN9OXP5n3rw,259
3-
../../bin/pip3.10,sha256=jCQZi6-1GMDo6yUEXEUko3I_Pft-OiueRN9OXP5n3rw,259
1+
../../bin/pip,sha256=wRjnmyTponr89E3KA0MjgmNQrPS4Gl3I0nHz5H9xb2s,242
2+
../../bin/pip3,sha256=wRjnmyTponr89E3KA0MjgmNQrPS4Gl3I0nHz5H9xb2s,242
3+
../../bin/pip3.10,sha256=wRjnmyTponr89E3KA0MjgmNQrPS4Gl3I0nHz5H9xb2s,242
44
pip-22.2.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
55
pip-22.2.2.dist-info/LICENSE.txt,sha256=Y0MApmnUmurmWxLGxIySTFGkzfPR_whtw0VtyLyqIQQ,1093
66
pip-22.2.2.dist-info/METADATA,sha256=1THNkoBHocZtVQ8SixJH12wuSXHJIQb4Vu7RzzEjfKQ,4197

pip/internal/generate/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import (
1313
func main() {
1414
targetDir := "./pip/internal/data"
1515

16+
// ensure we have a stable extract path for the python distribution (otherwise shebangs won't be stable)
1617
tmpDir := filepath.Join("/tmp", fmt.Sprintf("python-pip-bootstrap"))
17-
ep, err := python.NewEmbeddedPythonWithTmpDir(tmpDir)
18+
ep, err := python.NewEmbeddedPythonWithTmpDir(tmpDir, false)
1819
if err != nil {
1920
panic(err)
2021
}

python/embedded_python.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ func NewEmbeddedPython(name string) (*EmbeddedPython, error) {
3030
}, nil
3131
}
3232

33-
func NewEmbeddedPythonWithTmpDir(tmpDir string) (*EmbeddedPython, error) {
34-
e, err := embed_util.NewEmbeddedFilesWithTmpDir(data.Data, tmpDir)
33+
func NewEmbeddedPythonWithTmpDir(tmpDir string, withHashInDir bool) (*EmbeddedPython, error) {
34+
e, err := embed_util.NewEmbeddedFilesWithTmpDir(data.Data, tmpDir, withHashInDir)
3535
if err != nil {
3636
return nil, err
3737
}

0 commit comments

Comments
 (0)