Skip to content

Commit 030bb3c

Browse files
cleanup after tests
1 parent 5167319 commit 030bb3c

File tree

7 files changed

+9
-536
lines changed

7 files changed

+9
-536
lines changed

build/build.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,6 @@ func (s *Session) BuildProject(pkg *PackageData) (*compiler.Archive, error) {
937937
// ensure that runtime for gopherjs is imported
938938
pkg.Imports = append(pkg.Imports, `runtime`)
939939

940-
//start := time.Now() // TODO(grantnelson-wf): REMOVE
941-
942940
// Load the project to get the sources for the parsed packages.
943941
var rootSrcs *sources.Sources
944942
var err error
@@ -951,13 +949,8 @@ func (s *Session) BuildProject(pkg *PackageData) (*compiler.Archive, error) {
951949
return nil, err
952950
}
953951

954-
//fmt.Println(`load Packages:`, time.Since(start)) // TODO(grantnelson-wf): REMOVE
955-
956952
// Compile the project into Archives containing the generated JS.
957-
a, err := s.PrepareAndCompilePackages(rootSrcs)
958-
959-
//fmt.Println(`build project:`, time.Since(start)) // TODO(grantnelson-wf): REMOVE
960-
return a, err
953+
return s.PrepareAndCompilePackages(rootSrcs)
961954
}
962955

963956
// GetSortedSources returns the sources sorted by import path.
@@ -1183,28 +1176,20 @@ func (s *Session) PrepareAndCompilePackages(rootSrcs *sources.Sources) (*compile
11831176
tContext := types.NewContext()
11841177
allSources := s.GetSortedSources()
11851178

1186-
//start := time.Now() // TODO(grantnelson-wf): REMOVE
1187-
11881179
// Prepare and analyze the source code.
11891180
// This will be performed recursively for all dependencies.
11901181
if err := compiler.PrepareAllSources(allSources, s.SourcesForImport, tContext); err != nil {
11911182
return nil, err
11921183
}
11931184

1194-
//fmt.Println(`prepared sources:`, time.Since(start)) // TODO(grantnelson-wf): REMOVE
1195-
//start = time.Now()
1196-
11971185
// Compile all the sources into archives.
11981186
for _, srcs := range allSources {
11991187
if _, err := s.CompilePackage(srcs, tContext); err != nil {
12001188
return nil, err
12011189
}
12021190
}
12031191

1204-
//fmt.Println(`compile packages:`, time.Since(start)) // TODO(grantnelson-wf): REMOVE
1205-
1206-
log.Infof(`DeclCache stats: %s`, compiler.GlobalDeclCacheStats()) // TODO(grantnelson-wf): Uncomment
1207-
//fmt.Println(`DeclCache stats:`, compiler.GlobalDeclCacheStats())// TODO(grantnelson-wf): REMOVE
1192+
log.Infof(`DeclCache stats: %s`, compiler.GlobalDeclCacheStats())
12081193

12091194
rootArchive, ok := s.UpToDateArchives[rootSrcs.ImportPath]
12101195
if !ok {

build/cache/cache.go

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"path/filepath"
1616
"time"
1717

18-
"github.com/gopherjs/gopherjs/build/cache/pack"
1918
log "github.com/sirupsen/logrus"
2019
)
2120

@@ -28,8 +27,6 @@ import (
2827
type Cacheable interface {
2928
Write(encode func(any) error) error
3029
Read(decode func(any) error) error
31-
pack.Packable
32-
pack.Unpackable
3330
}
3431

3532
// Cache defines methods to store and load cacheable objects.
@@ -219,22 +216,21 @@ func (bc *BuildCache) Load(c Cacheable, importPath string, srcModTime time.Time)
219216
return true
220217
}
221218

222-
var encoding = `pack`
219+
// encoding is the encoding to use when serializing and deserializing the cache.
220+
// Possible values are seen in `getSerializer` and `getDeserializer`.
221+
// Using zip provides a CRC check for the data and reduces the file size but it is slightly slower.
222+
var encoding = `json`
223223

224224
type serializeHandle func(c Cacheable, buildTime time.Time, w io.Writer) (err error)
225225
type deserializeHandle func(c Cacheable, srcModTime time.Time, r io.Reader) (buildTime time.Time, old bool, err error)
226226

227227
func (bc *BuildCache) getSerializer() serializeHandle {
228228
switch encoding {
229-
case `pack`:
230-
return bc.packSerialize
231229
case `json`:
232230
return bc.jsonSerialize
233231
case `gob`:
234232
return bc.gobSerialize
235-
case `zipPack`:
236-
return zipGobSerialize(bc.packSerialize)
237-
case `zipJaon`:
233+
case `zipJson`:
238234
return zipGobSerialize(bc.jsonSerialize)
239235
case `zipGob`:
240236
return zipGobSerialize(bc.gobSerialize)
@@ -245,14 +241,10 @@ func (bc *BuildCache) getSerializer() serializeHandle {
245241

246242
func (bc *BuildCache) getDeserializer() deserializeHandle {
247243
switch encoding {
248-
case `pack`:
249-
return bc.packDeserialize
250244
case `json`:
251245
return bc.jsonDeserialize
252246
case `gob`:
253247
return bc.gobDeserialize
254-
case `zipPack`:
255-
return zipGobDeserialize(bc.packDeserialize)
256248
case `zipJson`:
257249
return zipGobDeserialize(bc.jsonDeserialize)
258250
case `zipGob`:
@@ -329,25 +321,6 @@ func (bc *BuildCache) jsonDeserialize(c Cacheable, srcModTime time.Time, r io.Re
329321
return buildTime, false, c.Read(decode)
330322
}
331323

332-
func (bc *BuildCache) packSerialize(c Cacheable, buildTime time.Time, w io.Writer) (err error) {
333-
e := pack.NewEncoder(w)
334-
if err = e.EncodeTime(buildTime); err != nil {
335-
return err
336-
}
337-
return c.PackEncode(e)
338-
}
339-
340-
func (bc *BuildCache) packDeserialize(c Cacheable, srcModTime time.Time, r io.Reader) (buildTime time.Time, old bool, err error) {
341-
d := pack.NewDecoder(r)
342-
if err := d.DecodeTime(&buildTime); err != nil {
343-
return buildTime, false, err
344-
}
345-
if srcModTime.After(buildTime) {
346-
return buildTime, true, nil // Package is out-of-date, cache miss.
347-
}
348-
return buildTime, false, c.PackDecode(d)
349-
}
350-
351324
// commonKey returns a part of the cache key common for all artifacts generated
352325
// under a given BuildCache configuration.
353326
func (bc *BuildCache) commonKey() string {

build/cache/cache_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ import (
55
"time"
66

77
"github.com/google/go-cmp/cmp"
8-
"github.com/gopherjs/gopherjs/build/cache/pack"
98
)
109

1110
type CacheableMock struct{ Data string }
1211

1312
func (m *CacheableMock) Write(encode func(any) error) error { return encode(m.Data) }
1413
func (m *CacheableMock) Read(decode func(any) error) error { return decode(&m.Data) }
15-
func (m *CacheableMock) PackEncode(e *pack.Encoder) error { return e.EncodeString(m.Data) }
16-
func (m *CacheableMock) PackDecode(d *pack.Decoder) error { return d.DecodeString(&m.Data) }
1714

1815
func TestStore(t *testing.T) {
1916
cacheForTest(t)

0 commit comments

Comments
 (0)